Opened 10 years ago

Closed 8 years ago

Last modified 8 years ago

#3859 closed defect (worksforme)

mp4: start_time never zero

Reported by: Christian Ebert Owned by:
Priority: normal Component: undetermined
Version: git-master Keywords:
Cc: blacktrash@gmx.net Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

Summary of the bug:
How to reproduce:

$ ffprobe -show_entries format=start_time BigBuckBunny_640x360.m4v
ffprobe version N-65628-g6c36b3a Copyright (c) 2007-2014 the FFmpeg developers
  built on Aug 14 2014 15:21:41 with Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
  configuration: --enable-gpl --enable-version3 --enable-nonfree --disable-ffserver --enable-shared --enable-libfdk-aac --enable-libx265 --enable-libx264 --enable-libxvid --enable-libfaac --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libvidstab --extra-cflags=-I/sw/include --extra-libs=-L/sw/lib
  libavutil      54.  3.100 / 54.  3.100
  libavcodec     56.  0.100 / 56.  0.100
  libavformat    56.  1.100 / 56.  1.100
  libavdevice    56.  0.100 / 56.  0.100
  libavfilter     5.  0.100 /  5.  0.100
  libswscale      3.  0.100 /  3.  0.100
  libswresample   1.  0.100 /  1.  0.100
  libpostproc    53.  0.100 / 53.  0.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'BigBuckBunny_640x360.m4v':
  Metadata:
    major_brand     : M4V
    minor_version   : 1
    compatible_brands: M4V M4A mp42isom
    creation_time   : 2008-06-03 05:23:28
    copyright       : © 2008 Blender Foundation | www.bigbuckbunny.org
    title           : Big Buck Bunny
    artist          : Peach Open Movie Team
    composer        : Sacha Goedegebure / Ton Roosendaal
    date            : 2008
  Duration: 00:09:56.46, start: 0.000000, bitrate: 1626 kb/s
    Stream #0:0(eng): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 127 kb/s (default)
    Metadata:
      creation_time   : 2008-06-03 05:23:28
      handler_name    : Apple Sound Media Handler
    Stream #0:1(eng): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p(tv, smpte170m), 640x360, 1495 kb/s, 24 fps, 24 tbr, 2400 tbn, 4800 tbc (default)
    Metadata:
      creation_time   : 2008-06-03 05:23:28
      handler_name    : Apple Video Media Handler
[FORMAT]
start_time=0.000000
[/FORMAT]
$ ffmpeg -i BigBuckBunny_640x360.m4v test.mp4
ffmpeg version N-65628-g6c36b3a Copyright (c) 2000-2014 the FFmpeg developers
  built on Aug 14 2014 15:21:41 with Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
  configuration: --enable-gpl --enable-version3 --enable-nonfree --disable-ffserver --enable-shared --enable-libfdk-aac --enable-libx265 --enable-libx264 --enable-libxvid --enable-libfaac --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libvidstab --extra-cflags=-I/sw/include --extra-libs=-L/sw/lib
  libavutil      54.  3.100 / 54.  3.100
  libavcodec     56.  0.100 / 56.  0.100
  libavformat    56.  1.100 / 56.  1.100
  libavdevice    56.  0.100 / 56.  0.100
  libavfilter     5.  0.100 /  5.  0.100
  libswscale      3.  0.100 /  3.  0.100
  libswresample   1.  0.100 /  1.  0.100
  libpostproc    53.  0.100 / 53.  0.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'BigBuckBunny_640x360.m4v':
  Metadata:
    major_brand     : M4V
    minor_version   : 1
    compatible_brands: M4V M4A mp42isom
    creation_time   : 2008-06-03 05:23:28
    copyright       : © 2008 Blender Foundation | www.bigbuckbunny.org
    title           : Big Buck Bunny
    artist          : Peach Open Movie Team
    composer        : Sacha Goedegebure / Ton Roosendaal
    date            : 2008
  Duration: 00:09:56.46, start: 0.000000, bitrate: 1626 kb/s
    Stream #0:0(eng): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 127 kb/s (default)
    Metadata:
      creation_time   : 2008-06-03 05:23:28
      handler_name    : Apple Sound Media Handler
    Stream #0:1(eng): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p(tv, smpte170m), 640x360, 1495 kb/s, 24 fps, 24 tbr, 2400 tbn, 4800 tbc (default)
    Metadata:
      creation_time   : 2008-06-03 05:23:28
      handler_name    : Apple Video Media Handler
[libx264 @ 0x7fe2e8826200] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
[libx264 @ 0x7fe2e8826200] profile High, level 3.0
[libx264 @ 0x7fe2e8826200] 264 - core 142 r2453 ea0ca51 - H.264/MPEG-4 AVC codec - Copyleft 2003-2014 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=12 lookahead_threads=2 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=24 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'test.mp4':
  Metadata:
    major_brand     : M4V
    minor_version   : 1
    compatible_brands: M4V M4A mp42isom
    date            : 2008
    copyright       : © 2008 Blender Foundation | www.bigbuckbunny.org
    title           : Big Buck Bunny
    artist          : Peach Open Movie Team
    composer        : Sacha Goedegebure / Ton Roosendaal
    encoder         : Lavf56.1.100
    Stream #0:0(eng): Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p, 640x360, q=-1--1, 24 fps, 12288 tbn, 24 tbc (default)
    Metadata:
      creation_time   : 2008-06-03 05:23:28
      handler_name    : Apple Video Media Handler
      encoder         : Lavc56.0.100 libx264
    Stream #0:1(eng): Audio: aac (libfaac) ([64][0][0][0] / 0x0040), 44100 Hz, stereo, s16, 128 kb/s (default)
    Metadata:
      creation_time   : 2008-06-03 05:23:28
      handler_name    : Apple Sound Media Handler
      encoder         : Lavc56.0.100 libfaac
Stream mapping:
  Stream #0:1 -> #0:0 (h264 (native) -> h264 (libx264))
  Stream #0:0 -> #0:1 (aac (native) -> aac (libfaac))
Press [q] to stop, [?] for help
frame=14316 fps=292 q=-1.0 Lsize=   48159kB time=00:09:56.47 bitrate= 661.4kbits/s
video:38397kB audio:9320kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.926535%
[libx264 @ 0x7fe2e8826200] frame I:154   Avg QP:17.40  size: 37708
[libx264 @ 0x7fe2e8826200] frame P:5550  Avg QP:22.44  size:  4792
[libx264 @ 0x7fe2e8826200] frame B:8612  Avg QP:27.20  size:   803
[libx264 @ 0x7fe2e8826200] consecutive B-frames: 12.4% 17.7% 13.4% 56.4%
[libx264 @ 0x7fe2e8826200] mb I  I16..4: 35.4% 26.7% 37.9%
[libx264 @ 0x7fe2e8826200] mb P  I16..4:  3.2%  4.2%  1.7%  P16..4: 33.3%  7.3%  4.9%  0.0%  0.0%    skip:45.3%
[libx264 @ 0x7fe2e8826200] mb B  I16..4:  0.2%  0.5%  0.2%  B16..8: 24.6%  1.7%  0.5%  direct: 0.8%  skip:71.6%  L0:49.5% L1:44.9% BI: 5.6%
[libx264 @ 0x7fe2e8826200] 8x8 transform intra:42.7% inter:49.6%
[libx264 @ 0x7fe2e8826200] coded y,uvDC,uvAC intra: 61.4% 65.7% 32.2% inter: 9.7% 10.2% 2.1%
[libx264 @ 0x7fe2e8826200] i16 v,h,dc,p: 22% 27% 23% 28%
[libx264 @ 0x7fe2e8826200] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 22% 19% 26%  4%  5%  7%  5%  6%  6%
[libx264 @ 0x7fe2e8826200] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 26% 23% 19%  4%  6%  6%  6%  5%  5%
[libx264 @ 0x7fe2e8826200] i8c dc,h,v,p: 48% 23% 18% 11%
[libx264 @ 0x7fe2e8826200] Weighted P-Frames: Y:3.7% UV:2.4%
[libx264 @ 0x7fe2e8826200] ref P L0: 70.7% 13.5% 11.6%  4.2%  0.1%
[libx264 @ 0x7fe2e8826200] ref B L0: 91.2%  7.6%  1.2%
[libx264 @ 0x7fe2e8826200] ref B L1: 94.8%  5.2%
[libx264 @ 0x7fe2e8826200] kb/s:527.31
$ ffprobe -show_entries format=start_time test.mp4
ffprobe version N-65628-g6c36b3a Copyright (c) 2007-2014 the FFmpeg developers
  built on Aug 14 2014 15:21:41 with Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
  configuration: --enable-gpl --enable-version3 --enable-nonfree --disable-ffserver --enable-shared --enable-libfdk-aac --enable-libx265 --enable-libx264 --enable-libxvid --enable-libfaac --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libvidstab --extra-cflags=-I/sw/include --extra-libs=-L/sw/lib
  libavutil      54.  3.100 / 54.  3.100
  libavcodec     56.  0.100 / 56.  0.100
  libavformat    56.  1.100 / 56.  1.100
  libavdevice    56.  0.100 / 56.  0.100
  libavfilter     5.  0.100 /  5.  0.100
  libswscale      3.  0.100 /  3.  0.100
  libswresample   1.  0.100 /  1.  0.100
  libpostproc    53.  0.100 / 53.  0.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'test.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    title           : Big Buck Bunny
    artist          : Peach Open Movie Team
    composer        : Sacha Goedegebure / Ton Roosendaal
    date            : 2008
    encoder         : Lavf56.1.100
    copyright       : © 2008 Blender Foundation | www.bigbuckbunny.org
  Duration: 00:09:56.50, start: 0.023220, bitrate: 661 kb/s
    Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 640x360, 527 kb/s, 24 fps, 24 tbr, 12288 tbn, 48 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 127 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
[FORMAT]
start_time=-0.023220
[/FORMAT]

Even using -filter_complex [v]setpts=PTS-STARTPTS;[a]asetpts=PTS-STARTPTS does not make a difference. I haven't found any input where this does not happen.

Just remuxing with -c copy is ok.

This can result in other apps warning about failing lipsync.

Change History (17)

comment:1 by Carl Eugen Hoyos, 10 years ago

Are external libraries like libx264 and libfaac necessary to reproduce this?

Which applications warn about failing lipsync? Do you really see A/V desync with any media player?

in reply to:  1 comment:2 by Christian Ebert, 10 years ago

Replying to cehoyos:

Are external libraries like libx264 and libfaac necessary to reproduce this?

$ ffmpeg -i BigBuckBunny_640x360.m4v test.ts
ffmpeg version N-65628-g6c36b3a Copyright (c) 2000-2014 the FFmpeg developers
  built on Aug 14 2014 15:21:41 with Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
  configuration: --enable-gpl --enable-version3 --enable-nonfree --disable-ffserver --enable-shared --enable-libfdk-aac --enable-libx265 --enable-libx264 --enable-libxvid --enable-libfaac --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libvidstab --extra-cflags=-I/sw/include --extra-libs=-L/sw/lib
  libavutil      54.  3.100 / 54.  3.100
  libavcodec     56.  0.100 / 56.  0.100
  libavformat    56.  1.100 / 56.  1.100
  libavdevice    56.  0.100 / 56.  0.100
  libavfilter     5.  0.100 /  5.  0.100
  libswscale      3.  0.100 /  3.  0.100
  libswresample   1.  0.100 /  1.  0.100
  libpostproc    53.  0.100 / 53.  0.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'BigBuckBunny_640x360.m4v':
  Metadata:
    major_brand     : M4V
    minor_version   : 1
    compatible_brands: M4V M4A mp42isom
    creation_time   : 2008-06-03 05:23:28
    copyright       : © 2008 Blender Foundation | www.bigbuckbunny.org
    title           : Big Buck Bunny
    artist          : Peach Open Movie Team
    composer        : Sacha Goedegebure / Ton Roosendaal
    date            : 2008
  Duration: 00:09:56.46, start: 0.000000, bitrate: 1626 kb/s
    Stream #0:0(eng): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 127 kb/s (default)
    Metadata:
      creation_time   : 2008-06-03 05:23:28
      handler_name    : Apple Sound Media Handler
    Stream #0:1(eng): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p(tv, smpte170m), 640x360, 1495 kb/s, 24 fps, 24 tbr, 2400 tbn, 4800 tbc (default)
    Metadata:
      creation_time   : 2008-06-03 05:23:28
      handler_name    : Apple Video Media Handler
Output #0, mpegts, to 'test.ts':
  Metadata:
    major_brand     : M4V
    minor_version   : 1
    compatible_brands: M4V M4A mp42isom
    date            : 2008
    copyright       : © 2008 Blender Foundation | www.bigbuckbunny.org
    title           : Big Buck Bunny
    artist          : Peach Open Movie Team
    composer        : Sacha Goedegebure / Ton Roosendaal
    encoder         : Lavf56.1.100
    Stream #0:0(eng): Video: mpeg2video, yuv420p, 640x360, q=2-31, 200 kb/s, 24 fps, 90k tbn, 24 tbc (default)
    Metadata:
      creation_time   : 2008-06-03 05:23:28
      handler_name    : Apple Video Media Handler
      encoder         : Lavc56.0.100 mpeg2video
    Stream #0:1(eng): Audio: mp2, 44100 Hz, stereo, s16, 384 kb/s (default)
    Metadata:
      creation_time   : 2008-06-03 05:23:28
      handler_name    : Apple Sound Media Handler
      encoder         : Lavc56.0.100 mp2
Stream mapping:
  Stream #0:1 -> #0:0 (h264 (native) -> mpeg2video (native))
  Stream #0:0 -> #0:1 (aac (native) -> mp2 (native))
Press [q] to stop, [?] for help
frame=14316 fps=1316 q=31.0 Lsize=   55390kB time=00:09:56.46 bitrate= 760.7kbits/s
video:20870kB audio:27960kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 13.433609%
$ ffprobe -show_entries format=start_time test.ts
ffprobe version N-65628-g6c36b3a Copyright (c) 2007-2014 the FFmpeg developers
  built on Aug 14 2014 15:21:41 with Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
  configuration: --enable-gpl --enable-version3 --enable-nonfree --disable-ffserver --enable-shared --enable-libfdk-aac --enable-libx265 --enable-libx264 --enable-libxvid --enable-libfaac --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libvidstab --extra-cflags=-I/sw/include --extra-libs=-L/sw/lib
  libavutil      54.  3.100 / 54.  3.100
  libavcodec     56.  0.100 / 56.  0.100
  libavformat    56.  1.100 / 56.  1.100
  libavdevice    56.  0.100 / 56.  0.100
  libavfilter     5.  0.100 /  5.  0.100
  libswscale      3.  0.100 /  3.  0.100
  libswresample   1.  0.100 /  1.  0.100
  libpostproc    53.  0.100 / 53.  0.100
Input #0, mpegts, from 'test.ts':
  Duration: 00:09:56.51, start: 1.430756, bitrate: 760 kb/s
  Program 1
    Metadata:
      service_name    : Big Buck Bunny
      service_provider: FFmpeg
    Stream #0:0[0x100]: Video: mpeg2video (Main) ([2][0][0][0] / 0x0002), yuv420p(tv), 640x360 [SAR 1:1 DAR 16:9], max. 104857 kb/s, 24 fps, 24 tbr, 90k tbn, 48 tbc
    Stream #0:1[0x101](eng): Audio: mp2 ([3][0][0][0] / 0x0003), 44100 Hz, stereo, s16p, 371 kb/s
[FORMAT]
start_time=1.430756
[/FORMAT]

Which applications warn about failing lipsync?

$ mediafilesegmenter -t 10 test.mp4 | head -n 3
Aug 16 2014 12:15:42.587: Using floating point is not backward compatible to iOS 4.1 or earlier devices
Aug 16 2014 12:15:42.588: Processing file /Users/chris/Movies/test.mp4
Aug 16 2014 12:15:42.602: track 1 of /Users/chris/Movies/test.mp4 contains edit list that the media doesn't start at beginning; this may cause problems in lip sync

Do you really see A/V desync with any media player?

I had a user complaining about it. As it's minimal, you'd need input you a) know extremely well and b) is a steady talking head or some such, and I don't havesomething like that available.

Last edited 10 years ago by Christian Ebert (previous) (diff)

in reply to:  1 ; comment:3 by Christian Ebert, 10 years ago

Replying to cehoyos:

Are external libraries like libx264 and libfaac necessary to reproduce this?

  1. The problem does not surface if I omit the audio track by ffmpeg -i input -an test.mp4 with libx264, so it's not an x264 issue per se
  2. With -c:a aac ffmpeg suggests to use an external library like libfaac - btw. the same problem happens with libfdk_aac - or -strict -2; with the latter there's less de-sync, and it's negative; but I don't want to use the native aac encoder anyway

I would argue this is a muxer issue. Basically the result is longer by roughly one video frame. Therefore people well familiar with the original material and a fine ear and eye will notice a slight de-sync.

Last edited 10 years ago by Christian Ebert (previous) (diff)

in reply to:  3 comment:4 by Christian Ebert, 10 years ago

Replying to blacktrash:

  1. The problem does not surface if I omit the audio track by ffmpeg -i input -an test.mp4 with libx264, so it's not an x264 issue per se
  2. With -c:a aac ffmpeg suggests to use an external library like libfaac - btw. the same problem happens with libfdk_aac - or -strict -2; with the latter there's less de-sync, and it's negative; but I don't want to use the native aac encoder anyway

Correction: with libfdk_aac start time is also negative, similar to native aac, but I can't get it to be 0.

comment:5 by Christian Ebert, 10 years ago

With -c:a libfdk_aac -profile:a aac_he -b:a 64k start_time is reliably -0.114694, even for audio only.
So I'm gonna ask there, with the fear to be referred back to here.

in reply to:  5 ; comment:6 by Christian Ebert, 10 years ago

Replying to blacktrash:

With -c:a libfdk_aac -profile:a aac_he -b:a 64k start_time is reliably -0.114694, even for audio only.
So I'm gonna ask there, with the fear to be referred back to here.

Upon further reflection: encoding to raw aac obviously does not know about start time, and muxing audio only e.g. into an m4a container gives the abovementioned negative start time.
So again, it points to some muxing problem - which is done by ffmpeg.

comment:7 by Christian Ebert, 10 years ago

Ugly workaround for libfdk_aac HE:

$ ffmpeg -v quiet -i BigBuckBunny_640x360.m4v -af atrim=start=0.114694 -c:a libfdk_aac -profile:a aac_he -b:a 64
k test.mp4
$ ffprobe -v quiet -show_entries format=start_time,duration test.mp4
[FORMAT]
start_time=0.000000
duration=596.500000
[/FORMAT]
$ ffprobe -v quiet -show_entries stream=start_time,duration test.mp4
[STREAM]
start_time=0.000000
duration=596.500000
[/STREAM]
[STREAM]
start_time=0.000000
duration=596.474195
[/STREAM]
$ ffmpeg -version
ffmpeg version N-66240-g4a203b7 Copyright (c) 2000-2014 the FFmpeg developers
built on Sep 11 2014 17:08:14 with Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
configuration: --enable-gpl --enable-version3 --enable-nonfree --disable-ffserver --enable-shared --enable-libfdk-aac --enable-libx265 --enable-libx264 --enable-libxvid --enable-libfaac --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libvidstab --extra-cflags=-I/sw/include --extra-libs=-L/sw/lib
libavutil      54.  7.100 / 54.  7.100
libavcodec     56.  1.100 / 56.  1.100
libavformat    56.  4.101 / 56.  4.101
libavdevice    56.  0.100 / 56.  0.100
libavfilter     5.  1.100 /  5.  1.100
libswscale      3.  0.100 /  3.  0.100
libswresample   1.  1.100 /  1.  1.100
libpostproc    53.  0.100 / 53.  0.100

But that feels wrong and risky.

in reply to:  6 comment:8 by Christian Ebert, 10 years ago

Last edited 10 years ago by Christian Ebert (previous) (diff)

comment:9 by Christian Ebert, 10 years ago

ffmpeg -i input -af asetpts=PTS+SR/TB -c:a libfdk_aac -profile:a aac_he -b:a 64 out.mp4

looks like a reliable workaround for fdk-aac, dealing with different sample rates etc.

But I'd still say it works around a bug.

comment:10 by Carl Eugen Hoyos, 10 years ago

I still don't understand how I can reproduce the problem: Is there an input sample and command line for which I can reproduce A/V desync or is this ticket only about a warning that a third-party tool shows?

in reply to:  9 comment:11 by Christian Ebert, 10 years ago

Replying to blacktrash:

ffmpeg -i input -af asetpts=PTS+SR/TB -c:a libfdk_aac -profile:a aac_he -b:a 64 out.mp4

looks like a reliable workaround for fdk-aac, dealing with different sample rates etc.

But I'd still say it works around a bug.

Nah, that's more a measure of despair ;-)

in reply to:  10 comment:12 by Christian Ebert, 10 years ago

Replying to cehoyos:

I still don't understand how I can reproduce the problem: Is there an input sample and command line for which I can reproduce A/V desync or is this ticket only about a warning that a third-party tool shows?

  1. You get a negative start_time with ffprobe for format and audio stream
  2. With the segment muxer the first segment always exceeds segment duration (in spite of forced key frames etc.)
  3. asetpts=PTS-STARTPTS does not make the audio start at 0 as it's supposed to do

comment:13 by Christian Ebert, 10 years ago

It's a problem with mp4 audio or aac, the duration is too long - I guess ffmpeg tries to accomodate that by setting a negative start_time when transcoding and muxing. If I encode the audio separately and mux it in with -c:a copy start_time is 0, but that only shifts the issue because it is still longer than the video (or the orginal audio track for that matter). The values vary depending on the aac library (or native) used, and sample rate.

$ ffmpeg -v quiet -i BigBuckBunny_640x360.m4v -vn -c:a copy copy.m4a
$ ffmpeg -v quiet -i BigBuckBunny_640x360.m4v -vn -strict -2 -c:a aac -b:a 64k native.m4a
$ ffmpeg -v quiet -i BigBuckBunny_640x360.m4v -vn -c:a libfdk_aac -profile:a aac_he -b:a 64k fdk.m4a
$ ffmpeg -v quiet -i BigBuckBunny_640x360.m4v -vn -c:a libfaac -b:a 64k faac.m4a
$ ffprobe -v quiet -show_entries stream=start_time,duration copy.m4a
[STREAM]
start_time=0.000000
duration=596.474195
[/STREAM]
$ ffprobe -v quiet -show_entries stream=start_time,duration native.m4a
[STREAM]
start_time=-0.023220
duration=596.497415
[/STREAM]
$ ffprobe -v quiet -show_entries stream=start_time,duration faac.m4a
[STREAM]
start_time=-0.023220
duration=596.497415
[/STREAM]
$ ffprobe -v quiet -show_entries stream=start_time,duration fdk.m4a
[STREAM]
start_time=-0.114694
duration=596.588889
[/STREAM]
$ ffprobe -show_entries stream=start_time,duration BigBuckBunny_640x360.m4v
ffprobe version N-66357-g28dce3c Copyright (c) 2007-2014 the FFmpeg developers
  built on Sep 21 2014 11:24:50 with Apple LLVM version 6.0 (clang-600.0.51) (based on LLVM 3.5svn)
  configuration: --enable-gpl --enable-version3 --enable-nonfree --disable-ffserver --enable-shared --enable-libfdk-aac --enable-libx265 --enable-libx264 --enable-libxvid --enable-libfaac --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libvidstab --extra-cflags=-I/sw/include --extra-libs=-L/sw/lib
  libavutil      54.  7.100 / 54.  7.100
  libavcodec     56.  1.101 / 56.  1.101
  libavformat    56.  4.102 / 56.  4.102
  libavdevice    56.  0.100 / 56.  0.100
  libavfilter     5.  1.101 /  5.  1.101
  libswscale      3.  0.100 /  3.  0.100
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  0.100 / 53.  0.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'BigBuckBunny_640x360.m4v':
  Metadata:
    major_brand     : M4V
    minor_version   : 1
    compatible_brands: M4V M4A mp42isom
    creation_time   : 2008-06-03 05:23:28
    copyright       : © 2008 Blender Foundation | www.bigbuckbunny.org
    title           : Big Buck Bunny
    artist          : Peach Open Movie Team
    composer        : Sacha Goedegebure / Ton Roosendaal
    date            : 2008
  Duration: 00:09:56.46, start: 0.000000, bitrate: 1626 kb/s
    Stream #0:0(eng): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 127 kb/s (default)
    Metadata:
      creation_time   : 2008-06-03 05:23:28
      handler_name    : Apple Sound Media Handler
    Stream #0:1(eng): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p(tv, smpte170m), 640x360, 1495 kb/s, 24 fps, 24 tbr, 2400 tbn, 4800 tbc (default)
    Metadata:
      creation_time   : 2008-06-03 05:23:28
      handler_name    : Apple Video Media Handler
[STREAM]
start_time=0.000000
duration=596.474195
[/STREAM]
[STREAM]
start_time=0.000000
duration=596.491667
[/STREAM]

comment:14 by Christian Ebert, 10 years ago

Trying to follow this up for fdk-aac: http://sourceforge.net/p/opencore-amr/mailman/message/32912437/

It definitely has practical consequences in "real life", the end of video of a HLS "vod" stream in a HTML5 video tag becomes reliable on legacy devices if I -filter:a atrim to the exact duration of the video.

fdk-aac maybe external, but is recommended quite strongly in the Wiki and such, so it really would be nice to find a solution for this; also the native encoder has the same problem, just not as pronounced.

comment:15 by Carl Eugen Hoyos, 10 years ago

Do I understand correctly that the issue is not reproducible with the native aac encoder?

in reply to:  15 comment:16 by Christian Ebert, 10 years ago

Replying to cehoyos:

Do I understand correctly that the issue is not reproducible with the native aac encoder?

No, as I've shown in https://trac.ffmpeg.org/ticket/3859#comment:13 the problem is present with all aac encoders. It just varies how pronounced it is. According to Martin it has to be that way: http://sourceforge.net/p/opencore-amr/mailman/message/32912765/

From a practical POV the results are almost random, see: http://sourceforge.net/p/opencore-amr/mailman/message/32912560/ resulting in over 2 seconds extra duration ...

So I guess I have to butcher around with atrim in practice to get sort of well behaved HLS streams. Trying to get clarity that I am able to understand is a bit like being sent from Pontius to Pilates and back ;-)

iTunes gives best result regarding start_time and duration: http://sourceforge.net/p/opencore-amr/mailman/message/32913564/ (start time 0, duration + ~0.1) but maybe this will result in more actual async, I don't know.

comment:17 by Christian Ebert, 8 years ago

Resolution: worksforme
Status: newclosed

In principle this can be solved by monitoring the delay in ffmpeg verbose output, and applying aresample=start_pts=0,asetpts=PTS+{delay}.

Last edited 8 years ago by Christian Ebert (previous) (diff)
Note: See TracTickets for help on using tickets.