簡體   English   中英

使用ffmpeg逐幀編寫視頻

[英]Writing a video frame by frame using ffmpeg

我正在嘗試使用 ffmpeg 逐幀編寫視頻,如下所述:http: //zulko.github.io/blog/2013/09/27/read-and-write-video-frames-in-python-using- ffmpeg/

但是,我總是收到OSError: [Errno 22] Invalid argument 我在 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

將字符串"mpeg"更改為"mpeg4"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM