ffmpeg选择最短的电影,但保留全长音频 [英] ffmpeg selects shortest movie but leaves full length audio

查看:90
本文介绍了ffmpeg选择最短的电影,但保留全长音频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个工具来创建电影网格,就像在Brady Bunch开幕式中一样.这是一个很酷,有趣的效果.

I've created a tool to create a grid of movies, like in the Brady Bunch opening. It's a cool, funny effect.

这是显示网格的示例电影.

问题在于ffmpeg正在选择最短电影来确定重叠视频的最大长度,但仍使用第一个音轨的 full 长度来确定总输出电影长度.

The problem is that ffmpeg is choosing the shortest movie to determine the maximum length of overlaid videos, but still using the full length of the first audio track to determine the overall output movie length.

因此,我的所有视频在最短的视频结束时都停止移动,但音频会播放第一部电影的全长.

So all my videos stop moving when the shortest one ends, but the audio plays on for full length of the first movie.

我该如何(1)将输出电影的长度设置为最长输入电影,或者(2)将音频长度与最短的电影长度匹配?

How can I either (1) set the length of the output movie to the longest input movie or (2) match the audio length to the shortest movie length as well?

我的脚本要旨.

基于此ffmpeg示例用法出现相同的音频问题:

Based on this ffmpeg example usage which exhibits the same audio problem:

ffmpeg
    -i 1.avi -i 2.avi -i 3.avi -i 4.avi
    -filter_complex "
        nullsrc=size=640x480 [base];
        [0:v] setpts=PTS-STARTPTS, scale=320x240 [upperleft];
        [1:v] setpts=PTS-STARTPTS, scale=320x240 [upperright];
        [2:v] setpts=PTS-STARTPTS, scale=320x240 [lowerleft];
        [3:v] setpts=PTS-STARTPTS, scale=320x240 [lowerright];
        [base][upperleft] overlay=shortest=1 [tmp1];
        [tmp1][upperright] overlay=shortest=1:x=320 [tmp2];
        [tmp2][lowerleft] overlay=shortest=1:y=240 [tmp3];
        [tmp3][lowerright] overlay=shortest=1:x=320:y=240
    "
    -c:v libx264 output.mkv

推荐答案

如何将输出电影的长度设置为最长输入电影?

How can I set the length of the output movie to the longest input movie?

从每个覆盖图中删除shortest=1.默认情况下,叠加层的最短输入将简单地停止,而较长的输入将继续,最后一帧将被重复.可以使用eof_action overlay选项更改此行为.请参见重叠过滤器文档.

Remove the shortest=1 from each overlay. By default the shortest input for the overlay will simply stop and the last frame will be repeated while the longer input continues. This behavior can be changed with the eof_action overlay option. See overlay filter docs.

如何将音频长度与最短的电影长度相匹配?

How can I match the audio length to the shortest movie length as well?

添加-shortest输出选项.这与overlay shortest选项不同.将其放置在过滤器之外作为输出选项(在输出文件之前).现在,最终的输出文件的持续时间与最短的流的持续时间相同:来自滤镜的视频或来自其中一个输入的音频(这完全取决于

Add the -shortest output option. This is a different option that the overlay shortest option; place it outside the filtergraph as an output option (before the output file). Now the final output file will be the same duration as the shortest stream: either the video from the filtergraph, or the audio from one of your inputs (which one exactly depends on the default stream selection behavior because I don't see you doing anything with the audio in the command).

IIRC,可能存在一个涉及过滤的现有错误,并且-shortest没有按照预期进行操作,但是我暂时无法回忆起这些细节,而且太懒了.只是要注意的事情.

IIRC, there may be an existing bug involving filtering and -shortest not doing what is expected, but I can't recall the details at the moment and am too lazy to look. Just something to be aware of.

这篇关于ffmpeg选择最短的电影,但保留全长音频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆