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

问题描述 投票:0回答:1

我正在努力处理一个错误,每当我试图在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上运行得很完美。你会如何处理?

python python-3.x subprocess
1个回答
0
投票

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

hls_stream.output(r'C:/Users/Documents/mashpy/VideoAnalytics_Mediaserver/ffmpeg_exec_test/video_fragments/hl_test.m3u8')
© www.soinside.com 2019 - 2024. All rights reserved.