gpt4 book ai didi

Python ffmpeg子进程: Broken pipe

转载 作者:行者123 更新时间:2023-12-01 00:04:49 25 4
gpt4 key购买 nike

以下脚本使用 OpenCV 读取视频,对每个帧应用转换,并尝试使用 ffmpeg 写入它。我的问题是,我无法让 ffmpeg 与 subprocess 一起使用模块。我总是收到错误 BrokenPipeError: [Errno 32] Broken pipe在我尝试写入标准输入的行中。为什么会这样,我做错了什么?

# Open input video with OpenCV
video_in = cv.VideoCapture(src_video_path)
frame_width = int(video_in.get(cv.CAP_PROP_FRAME_WIDTH))
frame_height = int(video_in.get(cv.CAP_PROP_FRAME_HEIGHT))
fps = video_in.get(cv.CAP_PROP_FPS)
frame_count = int(video_in.get(cv.CAP_PROP_FRAME_COUNT))
bitrate = bitrate * 4096 * 2160 / (frame_width * frame_height)

# Process video in ffmpeg pipe
# See http://zulko.github.io/blog/2013/09/27/read-and-write-video-frames-in-python-using-ffmpeg/
command = ['ffmpeg',
'-loglevel', 'error',
'-y',
# Input
'-f', 'rawvideo',
'-vcodec', 'rawvideo'
'-pix_fmt', 'bgr24',
'-s', str(frame_width) + 'x' + str(frame_height),
'-r', str(fps),
# Output
'-i', '-',
'-an',
'-vcodec', 'h264',
'-r', str(fps),
'-b:v', str(bitrate) + 'M',
'-pix_fmt', 'bgr24',
dst_video_path
]
pipe = sp.Popen(command, stdin=sp.PIPE)

for i_frame in range(frame_count):
ret, frame = video_in.read()
if ret:
warped_frame = cv.warpPerspective(frame, homography, (frame_width, frame_height))
pipe.stdin.write(warped_frame.astype(np.uint8).tobytes())
else:
print('Stopped early.')
break
print('Done!')

最佳答案

'-vcodec', 'rawvideo' 之后缺少逗号!!!

我花了大约一个小时才注意到......

您还应该关闭 stdin 并在 print('Done!') 之前等待:

pipe.stdin.close()
pipe.wait()

关于Python ffmpeg子进程: Broken pipe,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60044157/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com