如何处理Python子进程FileNotFoundError:[WinError 2]?

时间:2020-05-19 19:39:35

标签: python python-3.x subprocess

当我尝试在Windows 10上运行此程序时,我正在努力管理发生的错误:

import ffmpeg_streaming
from ffmpeg_streaming import Formats, Bitrate, Representation, Size
import subprocess
import sys

def monitor(ffmpeg, duration, time_):
    per = round(time_ / duration * 100)
    sys.stdout.write("\rTranscoding...(%s%%) [%s%s]" % (per, '#' * per, '-' * (100 - per)))
    sys.stdout.flush()

video = ffmpeg_streaming.input('http://freja.hiof.no:1935/rtplive/_definst_/hessdalen03.stream/playlist.m3u8')

_360p = Representation(Size(640, 360), Bitrate(276 * 1024, 128 * 1024))
_480p = Representation(Size(854, 480), Bitrate(750 * 1024, 192 * 1024))
_720p = Representation(Size(1280, 720), Bitrate(2048 * 1024, 320 * 1024))

hls_stream = video.hls(Formats.h264(), hls_list_size = 1, hls_time = 60)
hls_stream.representations(_480p)
hls_stream.output('C:/Users/Documents/mashpy/VideoAnalytics_Mediaserver/ffmpeg_exec_test/video_fragments/hl_test.m3u8')

错误消息包含文本:

 Traceback (most recent call last):
  File "C:/Users/Documents/mashpy/VideoAnalytics_Mediaserver/ffmpeg_exec_test/capture.py", line 20, in <module>
    hls_stream.output('C:/Users/Documents/mashpy/VideoAnalytics_Mediaserver/ffmpeg_exec_test/video_fragments/hl_test.m3u8')
  File "C:\Users\AppData\Local\Programs\Python\Python36\lib\site-packages\ffmpeg_streaming\_media.py", line 82, in output
    self._run(ffmpeg_bin, monitor, **options)
  File "C:\Users\AppData\Local\Programs\Python\Python36\lib\site-packages\ffmpeg_streaming\_media.py", line 93, in _run
    with Process(self, command_builder(ffmpeg_bin, self), monitor, **options) as process:
  File "C:\Users\AppData\Local\Programs\Python\Python36\lib\site-packages\ffmpeg_streaming\_process.py", line 57, in __init__
    self.process = _p_open(commands, **options)
  File "C:\Users\AppData\Local\Programs\Python\Python36\lib\site-packages\ffmpeg_streaming\_process.py", line 28, in _p_open
    return subprocess.Popen(shlex.split(commands), **options)
  File "C:\Users\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 709, in __init__
    restore_signals, start_new_session)
  File "C:\Users\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 997, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] Specified file not found

不知道这里错过了什么。最初,我设置了PATH,同一程序在Ubuntu 18.04上完美运行。您将如何处理?

1 个答案:

答案 0 :(得分:0)

在最后一行的路径名称前添加r

hls_stream.output(r'C:/Users/Documents/mashpy/VideoAnalytics_Mediaserver/ffmpeg_exec_test/video_fragments/hl_test.m3u8')
相关问题