使用ffmpeg逐帧编写视频 [英] Writing a video frame by frame using ffmpeg
本文介绍了使用ffmpeg逐帧编写视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
I am trying to write a video frame by frame using ffmpeg as explained here: 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.这是代码:
However, I am always getting an OSError: [Errno 22] Invalid argument. I am on Windows 7 and using Python 3.4. Here is the code:
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()
非常感谢您的帮助.
根据此处的要求,该程序的详细输出
As requested here the detailed output of the program
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)),则错误消息会稍有变化,但循环仍然只运行两次.错误输出如下:
Interestingly, if I comment line number 26 (i.e. time.sleep(1/24)) the error message changes slightly but the loop still only runs twice. Here is the error output:
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
推荐答案
将字符串"mpeg"
更改为"mpeg4"
这篇关于使用ffmpeg逐帧编写视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文