使用ffmpeg逐帧编写视频

Chr*_*ris 7 python video ffmpeg

我正在尝试使用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()
Run Code Online (Sandbox Code Playgroud)

任何帮助是极大的赞赏.

编辑:这里要求详细的程序输出

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
Run Code Online (Sandbox Code Playgroud)

有趣的是,如果我对第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
Run Code Online (Sandbox Code Playgroud)

Too*_*one 0

将字符串更改"mpeg""mpeg4"