我正在尝试使用ffmpeg逐帧写入视频,如此处所示:http://zulko.github.io/blog/2013/09/27/read-and-write-video-frames-in-python-using-ffmpeg/。然而,我一直收到一个 OSError:[Errno 22]无效的参数 。 我在Windows 7上使用Python 3.4。下面是代码:
任何帮助都非常感激。
编辑:按照要求,以下是程序的详细输出。
import subprocess as sp
import numpy as np
import time
ffmpeg_bin = r'C:\path\to\ffmpeg\ffmpeg.exe'
command = [ffmpeg_bin,
'-y', # (optional) overwrite output file if it exists
'-f', 'rawvideo',
'-vcodec','rawvideo',
'-s', '420x360', # size of one frame
'-pix_fmt', 'rgb24',
'-r', '24', # frames per second
'-i', '-', # The imput comes from a pipe
'-an', # Tells FFMPEG not to expect any audio
'-vcodec', 'mpeg',
'my_output_videofile.mp4' ]
proc = sp.Popen(command, stdin=sp.PIPE, stderr=sp.PIPE)
a = np.zeros((360, 420, 3), dtype=np.uint8)
for ii in range(5*24):
print(ii)
proc.stdin.write(a.tostring())
time.sleep(1/24)
proc.stdin.close()
proc.stderr.close()
proc.wait()
任何帮助都非常感激。
编辑:按照要求,以下是程序的详细输出。
0
1
Traceback (most recent call last):
File ".\write_dummy_video.py", line 25, in <module>
proc.stdin.write(a.tostring())
OSError: [Errno 22] Invalid argument
有趣的是,如果我注释掉第26行(即time.sleep(1/24)),错误消息会略有变化,但循环仍然只运行两次。以下是错误输出:
0
1
Traceback (most recent call last):
File ".\write_dummy_video.py", line 25, in <module>
proc.stdin.write(a.tostring())
BrokenPipeError: [Errno 32] Broken pipe