对于我的应用程序,我正在为tensorflow修改来自ffmpeg-python的代码。
它基本上是对输入的每一个帧进行解码,让您用python处理它,然后再对它进行编码。
为了优化目标,我在输入端添加了一个fps过滤器,以得到一半的fps,所以我只能处理一半的帧,然后在编码器中用minterpolate插值帧以得到原始的fps。
我的解码器是这样的:
def decoder(in_filename):
args = (
ffmpeg
.input(in_filename)
.filter('fps', fps=30/2)
(... more filters in between ...)
.output('pipe:', format='rawvideo', pix_fmt='rgb24')
.compile()
)
return subprocess.Popen(args, stdout=subprocess.PIPE)
我的编码器在用python处理帧之后:
def encoder(out_filename, width, height):
args = (
ffmpeg
.input('pipe:', format='rawvideo', pix_fmt='rgb24', s='{}x{}'.format(width, height))
.filter('minterpolate', fps=30)
.filter('fps',fps=30)
.output(out_filename, pix_fmt='rgb24')
.overwrite_output()
.compile()
)
return subprocess.Popen(args, stdin=subprocess.PIPE)
之后,我将原始输入与处理过的视频进行水平叠加。
subprocess.run("ffmpeg -i {} -i {} -filter_complex hstack=inputs=2 -pix_fmt yuv420p -c:v libx264 {}".format(in_filename,out_filename,"out.mp4"))
问题是:“处理”视频速度更快,在原始视频之前结束。就像它们遵循相同的时间戳,但实际上从来没有插值过帧。我做错了什么?
发布于 2022-05-08 15:10:36
编码器.input()
必须指定其帧速率以匹配解码器帧(15帧/s)。目前,它正在使用rawvideo
编码器的默认框架。
在FFmpeg中,即使用-r 15
输入选项。不确定它在ffmpeg-python
中是什么,但可能只是r=15
关键字参数。
.filter('fps',fps=30)
是多余的。
https://stackoverflow.com/questions/72162119
复制相似问题