FFmpeg concat 视频和音频不同步 [英] FFmpeg concat video and audio out of sync

查看:221
本文介绍了FFmpeg concat 视频和音频不同步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 ffmpeg concat 加入多个文件似乎会导致时间戳或偏移量不匹配音频.我试过几个视频,发现 h.264/MP4 也有同样的问题.

Joining multiple files using ffmpeg concat seems to result in a mismatch of the timestamps or offsets for the audio. I've tried with several videos and noticed the same problem for h.264 / MP4.

使用 concat 和编码 视频似乎工作正常.音频保持同步,因为 ffmpeg 会进行完整的转换计算,并且似乎一切正常.

Using concat and encoding the video seems to work fine. The audio stays in sync as ffmpeg does the full conversion calculations and seems to get everything right.

但是,在没有任何转换或编码的情况下简单地连接视频会导致同步问题缓慢增加.显然,编码视频而不是简单地加入它们会导致信息/质量的损失,所以我宁愿找到解决这个问题的方法.

However, simply concatenating the videos without any transformation or encoding results in a slowly increasing sync issue. Obviously, encoding the videos rather than simply joining them will result in a loss of information/quality so I would rather find a way around this problem.

尝试了几个标志来解决这个似乎基于时间戳的问题.不过,这些似乎都不能解决问题.

I've tried several flags to sort out this problem that appears to be based on the timestamps. None of these seem to correct the problem though.

ffmpeg -f concat -fflags +genpts -async 1 -i segments.txt test.mov
ffmpeg -auto_convert 1 -f concat -fflags +genpts -async 1 -i segments.txt -c copy test2.mov
ffmpeg -f concat -i segments.txt -c copy -fflags +genpts test3.mp4
ffmpeg -f concat -fflags +genpts -async 1 -i segments.txt -copyts test4.mov
ffmpeg -f concat -i segments.txt -copyts test5.mov
ffmpeg -f concat -i segments.txt -copyts -c copy test6.mov
ffmpeg -f concat -fflags +genpts -i segments.txt -copyts -c copy test7.mov

注意:我能在 SO 上找到的所有其他问题似乎都可以通过简单地重新编码视频来解决"问题.不是一个好的解决方案.

我意识到 concat 不是问题所在.原始剪辑集的时间戳不匹配.以某种方式 concat + encoding 解决了这个问题,但我不想每次都重新编码视频和降低质量.

I realized the concat wasn't the problem. The original set of clips had mis-matched timestamps. Somehow concat + encoding fixed the issue, but I don't want to re-encode the videos and loose quality each time.

ffmpeg -y -ss 00:00:02.750 -i input.MOV -c copy -t 00:00:05.880 output.MOV

结果如下

ffprobe -v quiet -show_entries stream=start_time,duration output.MOV

start_time=-0.247500
duration=6.131125
start_time=-0.257333
duration=6.155333

从那以后我尝试在不同的地方使用 -tom 和 -t 以及 -af apad -c:v copy 并且我仍然无法获得相同的持续时间.

Since then I've tried to use -tom and -t in different places along with -af apad -c:v copy and I've still failed to get the duration to be the same.

我录制了一个示例视频,添加了将其切碎的命令,然后将其连接起来.http://davidpennington.me/share/audio_sync_test_video.zip

I recorded a sample video, added the commands to chop it up, then concat it. http://davidpennington.me/share/audio_sync_test_video.zip

推荐答案

这两个步骤应该可以工作

This two step process should work

第 1 步填充每个片段中的音频

ffmpeg -i segment1.mov -af apad -c:v copy <audio encoding params> -shortest -avoid_negative_ts make_zero -fflags +genpts padded1.mov

使用同步流生成片段

ffmpeg -y -ss 00:00:02.750 -i input.MOV -c copy -t 00:00:05.880 -avoid_negative_ts make_zero -fflags +genpts segment.MOV

步骤 2 连接

ffmpeg -f concat -i segments.txt -c copy test.mov

其中 segments.txt 包含填充文件的名称.

where segments.txt consists of the names of the padded files.

这篇关于FFmpeg concat 视频和音频不同步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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