FFmpeg音频和视频不同步

FFmpeg音频和视频不同步

我知道这里有很多关于使用 ffmpeg 时视频和音频不同步的问题,但是我找不到一个可以解决我的问题的问题,所以我希望大家能够提供帮助。

我将 3 个视频连接在一起,每个视频都有自己的音轨。

  • 视频 1:介绍视频(MP4 文件)
  • 视频 2:主视频(MP4 文件)
  • 视频 3:结尾视频(MP4 文件)

我正在使用以下代码进行连接:

ffmpeg -i '.$input.' -c copy -bsf:v h264_mp4toannexb -f mpegts '.$intermediate1.'
ffmpeg -i '.$input_second.' -c copy -bsf:v h264_mp4toannexb -f mpegts '.$intermediate2.'
ffmpeg -i '.$input_third.' -c copy -bsf:v h264_mp4toannexb -f mpegts '.$intermediate3.'
ffmpeg -i "concat:'.$intermediate1.'|'.$intermediate2.'|'.$intermediate3.'" -c copy -        bsf:a aac_adtstoasc '.$output.' 2>&1

问题是主视频上的音频和视频不同步。

以下是 ffmpeg 返回的输出:

ffmpeg version N-59597-g4ced5d7-syslint 
Copyright (c) 2000-2014 the FFmpeg developers
built on Jan 6 2014 06:11:39 with gcc 4.4.7 (GCC) 20120313 (Red Hat 4.4.7-4)
configuration: --prefix=/usr/local/cpffmpeg --enable-shared --enable-nonfree --enable-gpl --enable-pthreads --enable-libopencore-amrnb --enable-decoder=liba52 --enable-libopencore-amrwb --enable-libfaac --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libx264 --enable-libxvid --extra-cflags=-I/usr/local/cpffmpeg/include/ --extra-ldflags=-L/usr/local/cpffmpeg/lib --enable-version3 --extra-version=syslint 
libavutil 52. 62.100 / 52. 62.100
libavcodec 55. 47.100 / 55. 47.100
libavformat 55. 22.102 / 55. 22.102
libavdevice 55. 5.102 / 55. 5.102
libavfilter 4. 0.103 / 4. 0.103
libswscale 2. 5.101 / 2. 5.101
libswresample 0. 17.104 / 0. 17.104
libpostproc 52. 3.100 / 52. 3.100
Input #0, mpegts, from 'concat:videos/finals/i1_w22861fd697894f2fc6aeb55462f29ff.ts|videos/finals/i2_T22861fd697894f2fc6aeb55462f29ff.ts':
Duration: 00:04:05.08, start: 1.466733, bitrate: 1535 kb/s
Program 1
Metadata: service_name : Service01
service_provider: FFmpeg
Stream #0:0[0x100]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p, 768x432 [SAR 1:1 DAR 16:9], 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc
Stream #0:1[0x101](und): Audio: aac ([15][0][0][0] / 0x000F), 48000 Hz, stereo, fltp, 234 kb/s
Output #0, mp4, to 'videos/finals/s22861fd697894f2fc6aeb55462f29ff.mp4':
Metadata: encoder : Lavf55.22.102
Stream #0:0: Video: h264 ([33][0][0][0] / 0x0021), yuv420p, 768x432 [SAR 1:1 DAR 16:9], q=2-31, 29.97 fps, 90k tbn, 90k tbc
Stream #0:1(und): Audio: aac ([64][0][0][0] / 0x0040), 48000 Hz, stereo, 234 kb/s
Stream mapping: Stream #0:0 -> #0:0 (copy)
Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
[mp4 @ 0x184b640] Non-monotonous DTS in output stream 0:1; previous: 651264, current: 650250; changing to 651265. This may result in incorrect timestamps in the output file. 
[mp4 @ 0x184b640] Non-monotonous DTS in output stream 0:0; previous: 2444442, current: 2444442; changing to 2444443. This may result in incorrect timestamps in the output file.
[mp4 @ 0x184b640] Non-monotonous DTS in output stream 0:0; previous: 2447445, current: 2447445; changing to 2447446. This may result in incorrect timestamps in the output file.
frame= 7756 fps=0.0 q=-1.0 Lsize= 41685kB time=00:04:18.72 bitrate=1319.9kbits/s" [32]=> string(82) "video:35379kB audio:6137kB subtitle:0 global headers:0kB muxing overhead 0.405115%"

有人能帮我解决这个问题或指出正确的方向吗?如果您需要更多信息,请告诉我。

相关内容