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

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

问题描述

使用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 em>和编码,视频似乎工作正常。音频保持同步,因为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.

我有一个href =https://ffmpeg.org/ffmpeg.html =noreferrer>尝试了几个标志来整理这个似乎基于时间戳的问题。没有这些似乎可以解决问题。

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 +编码固定问题,但我不想每次重新编码视频和质量下降。

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

从那时起,我试图使用 -to m和 -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

推荐答案

这两步过程应该工作

步骤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 Concat

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

其中 segments.txt 包括填充文件。

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

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