为什么我的 mp4 文件的音频不同步

Why the audio of my mp4 file is going out of async

我在将 wmv 文件转换为 mp4 时遇到问题。我正在使用 x264.exe 这个命令来获取视频流

x264 --output temporal.264 --fps 25 --preset slow --bitrate 2048 --vbv-maxrate 2048 --vbv-bufsize 9600 --min-keyint 48 --keyint 48 --scenecut 0 --no-scenecut --pass 1 --video-filter "resize:width=640,height=480" Original.wmv

然后我使用 ffmpeg.exe 来提取音频流:

ffmpeg -i .wmv -acodec libfdk_aac -b:a 32000 temporal.aac

最后我使用 MP4Box 将每个流与此行合并:

MP4Box -add temporal.264 Final.mp4 MP4Box -add temporal.aac Final.mp4

问题是 final.mp4 音频不同步。开始不错,但随着时间的推移,它与时间不同步。

我运行这个命令:

MP4Box -info 010004470063PE-10022017083824-2_MultiMedia--1.mp4

我发现两个流的估计时间不同:

命令输出

* Movie Info * Timescale 600 - 2 tracks Computed Duration 01:00:03.643 - Indicated Duration 01:00:03.643 Fragmented File: no File suitable for progressive download (moov before mdat) File Brand isom - version 1 Compatible brands: isom avc1 Created: GMT Wed Jun 27 16:31:44 2018 Modified: GMT Wed Jun 27 16:31:44 2018 File has root IOD (9 bytes) Scene PL 0xff - Graphics PL 0xff - OD PL 0xff Visual PL: AVC/H264 Profile (0x7f) Audio PL: AAC Profile @ Level 2 (0x29) No streams included in root OD Track # 1 Info - TrackID 1 - TimeScale 25000 Media Duration 00:59:57.520 - Indicated Duration 00:59:57.520 Track has 1 edit lists: track duration is 00:59:57.320 Media Info: Language "Undetermined (und)" - Type "vide:avc1" - 89938 samples Visual Track layout: x=0 y=0 width=640 height=480 MPEG-4 Config: Visual Stream - ObjectTypeIndication 0x21 AVC/H264 Video - Visual Size 640 x 480 AVC Info: 1 SPS - 1 PPS - Profile Main @ Level 3 NAL Unit length bits: 32 Chroma format YUV 4:2:0 - Luma bit depth 8 - chroma bit depth 8 SPS#1 hash: 41EE779BEF2AA71A7131EAFD3C77C7E3BC95FD8E PPS#1 hash: 086E1D72A40A0E8CF35D102F34A9DF6CD44D6CEF Self-synchronized RFC6381 Codec Parameters: avc1.4D401E Average GOP length: 250 samples Track # 2 Info - TrackID 2 - TimeScale 44100 Media Duration 01:00:03.644 - Indicated Duration 01:00:03.644 Media Info: Language "Undetermined (und)" - Type "soun:mp4a" - 155196 samples MPEG-4 Config: Audio Stream - ObjectTypeIndication 0x40 MPEG-4 Audio AAC LC - 2 Channel(s) - SampleRate 44100 Synchronized on stream 1 RFC6381 Codec Parameters: mp4a.40.2 All samples are sync

我不明白为什么会这样,因为原始的 wmv 是完全同步的。有帮助吗?

.aac是没有时间戳的原始容器,如果源音频中有PTS间隙,它们将丢失。

您有两个解决方法:

a) 提取到定时样本容器

ffmpeg -i .wmv -acodec libfdk_aac -b:a 32000 -vn temporal.m4a

b) 填空并摘录

ffmpeg -i .wmv -af aresample=async=1 -acodec libfdk_aac -b:a 32000 temporal.aac

根据 Gyan 的回复,我使用 ffmpeg 将 wmv 文件转码为 mp4,分离​​音频和视频序列是个坏主意。最后我使用以下命令进行转码:

ffmpeg -i <input>.wmv -c:v libx264 -preset slow -crf 23 -c:a aac -r 25 -b:a 48k -strict -2 -max_muxing_queue_size 4000 <output>.mp4