我正在尝试使用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
答案 0 :(得分:0)
将字符串"mpeg"
更改为"mpeg4"