[FFmpeg-user] H264 + AAC MPEG-TS to MP4 Audio Sync

Ross (MikiPro Services) ross.b at mikipro.nz
Thu Feb 12 09:09:02 CET 2015


Hello all,

I have been driven insane by audio sync issues going from a transport
stream to a MP4 container. I have concatenated a HLS stream and can play
the .ts file perfectly in VLC without any audio sync issues however when I
stream copy to MP4 the audio drifts out of sync when playing in Firefox and
Chrome but not in VLC.

Can you guys please help me?

The technical details is as follows:

ffmpeg
ffmpeg version N-69027-g843d93d Copyright (c) 2000-2015 the FFmpeg
developers
  built on Jan 12 2015 14:52:51 with gcc 4.8 (Ubuntu 4.8.2-19ubuntu1)
  configuration: --enable-gpl --enable-libx264 --enable-libmp3lame
--enable-nonfree --enable-libfdk_aac --enable-pthreads
  libavutil      54. 16.100 / 54. 16.100
  libavcodec     56. 20.100 / 56. 20.100
  libavformat    56. 18.101 / 56. 18.101
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5.  7.100 /  5.  7.100
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  3.100 / 53.  3.100
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options]
outfile}...

Use -h to get full help or, even better, run 'man ffmpeg'

Source file: http://210.48.78.12:9999/capture2.ts

MP4 file: http://210.48.78.12:9999/capture2.mp4

First I concat HLS TS segemenst by:

ffmpeg -y -async 1 -f concat -safe 0 -i concat2.txt -codec copy
-mpegts_copyts 1 -f mpegts /mnt/ramdisk/capture2.ts

No error messages are displayed at all

Then I try to convert to MP4:

ffmpeg -y -i capture2.ts -copyinkf -c:v copy -copyts -c:a copy
-avoid_negative_ts 1 -mpegts_copyts 1 -bsf:a aac_adtstoasc -movflags
+faststart -f mp4 /mnt/ramdisk/capture2.mp4

ffmpeg version N-69027-g843d93d Copyright (c) 2000-2015 the FFmpeg
developers
  built on Jan 12 2015 14:52:51 with gcc 4.8 (Ubuntu 4.8.2-19ubuntu1)
  configuration: --enable-gpl --enable-libx264 --enable-libmp3lame
--enable-nonfree --enable-libfdk_aac --enable-pthreads
  libavutil      54. 16.100 / 54. 16.100
  libavcodec     56. 20.100 / 56. 20.100
  libavformat    56. 18.101 / 56. 18.101
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5.  7.100 /  5.  7.100
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  3.100 / 53.  3.100
Input #0, mpegts, from 'capture2.ts':
  Duration: 01:00:25.69, start: 0.018667, bitrate: 1028 kb/s
  Program 1
    Metadata:
      service_name    : Service01
      service_provider: FFmpeg
    Stream #0:0[0x100]: Video: h264 (High) ([27][0][0][0] / 0x001B),
yuv420p, 960x540 [SAR 1:1 DAR 16:9], 25 fps, 25 tbr, 90k tbn, 50 tbc
    Stream #0:1[0x101]: Audio: aac (LC) ([15][0][0][0] / 0x000F), 48000 Hz,
stereo, fltp, 120 kb/s
Output #0, mp4, to '/mnt/ramdisk/capture2.mp4':
  Metadata:
    encoder         : Lavf56.18.101
    Stream #0:0: Video: h264 ([33][0][0][0] / 0x0021), yuv420p, 960x540
[SAR 1:1 DAR 16:9], q=2-31, 25 fps, 25 tbr, 90k tbn, 90k tbc
    Stream #0:1: Audio: aac ([64][0][0][0] / 0x0040), 48000 Hz, stereo, 120
kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
[mp4 @ 0x1b1cfa0] Starting second pass: moving the moov atom to the
beginning of the file
frame=90007 fps=24171 q=-1.0 Lsize=  411591kB time=01:00:25.64 bitrate=
930.0kbits/s
video:353819kB audio:55101kB subtitle:0kB other streams:0kB global
headers:0kB muxing overhead: 0.653165%

I have done ffmpeg -v error -i capture2.mp4 -f null - 2>errorcheck
and ffmpeg -v error -i capture2.ts4 -f null - 2>errorcheck and there are no
errors.

Thanks for reading this far, hopefully its something easy. Thanks FFMPEG
and all the contributors for great transcoding software I have used over
the years. If any of you end up in Auckland, New Zealand I will buy you a
beer!


More information about the ffmpeg-user mailing list