Opened 5 years ago

Closed 5 years ago

#3797 closed defect (fixed)

AVStream.time_base is causing audio/video sync issues and growing videos

Reported by: hackeron Owned by:
Priority: important Component: avformat
Version: git-master Keywords: regression
Cc: michael Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

I'm recording from a D-Link DCS-2230 IP Camera with this command:

ffmpeg -use_wallclock_as_timestamps 1 -rtsp_transport tcp -i 'rtsp://admin:@192.168.1.83/live1.sdp' -dn -map 0 -codec:a libfdk_aac -flags +qscale -global_quality 1 -afterburner 1 -ar 44100 -codec:v copy -f segment -segment_time 60 -segment_wrap 10 -segment_list_flags live -segment_list_size 10 -reset_timestamps 1 -segment_list test.csv -y test_%02d.mkv

With Trunk from 2014/04/09 all works correctly and each output video is exactly 1 minute long. With Trunk from 2014/07/18 the audio duration slowly grows in size and the duration of each video gets 10 seconds longer:

With 2014/04/09 trunk:

deployer@XanBox:~/test$ mediainfo *.mkv | grep -i duration
Duration                                 : 1mn 0s
Duration                                 : 1mn 0s
Duration                                 : 1mn 0s
Duration                                 : 1mn 0s
Duration                                 : 1mn 0s
Duration                                 : 1mn 0s
Duration                                 : 1mn 0s
Duration                                 : 1mn 0s

With 2014/07/18 trunk:

deployer@XanBox:~/test$ mediainfo *.mkv | grep -i duration
Duration                                 : 1mn 1s
Duration                                 : 1mn 1s
Duration                                 : 1mn 1s
Duration                                 : 1mn 1s
Duration                                 : 1mn 1s
Duration                                 : 1mn 11s
Duration                                 : 1mn 11s
Duration                                 : 1mn 21s
Duration                                 : 1mn 21s

Any ideas what could have been changed/broken to cause this to happen?

Attachments (2)

ffmpeg-2.4.1.log (42.5 KB) - added by ricky-ticky 5 years ago.
ffmpeg 2.4.1 buggy console output
ffmpeg-2.2.1.log (3.7 KB) - added by ricky-ticky 5 years ago.
ffmpeg 2.2.1 console output

Download all attachments as: .zip

Change History (29)

comment:1 Changed 5 years ago by cehoyos

If you want to report a regression, please run git bisect to find the change introducing the bug.
To make this a valid ticket please provide the command line that does not work correctly together with the complete uncut console output.

comment:2 Changed 5 years ago by hackeron

I have identified exactly at that commit it breaks and it happens on Wed Jun 18 18:18:25 2014 +0200 - here are the full outputs of the working and non working versions:

Working version, commit: 88514378bac99872265dad28072fb30160b26bfa -

deployer@XanBox:~/test$ rm *.mkv; ffmpeg -use_wallclock_as_timestamps 1 -rtsp_transport tcp -i rtsp://localhost:10103/proxyStream -dn -map 0 -af aresample=async=1000 -codec:a libfdk_aac -flags +qscale -global_quality 1 -afterburner 1 -ar 44100 -codec:v copy -f segment -segment_time 60 -segment_wrap 10 -segment_list_flags live -segment_list_size 10 -reset_timestamps 1 -segment_list test.csv -y test_%02d.mkv
ffmpeg version N-64052-g8851437 Copyright (c) 2000-2014 the FFmpeg developers
  built on Jul 24 2014 12:07:54 with gcc 4.8 (Ubuntu 4.8.2-19ubuntu1)
  configuration: --enable-pic --enable-shared --extra-ldflags=-ldl --enable-gpl --enable-libfdk-aac --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libtheora --enable-libvorbis --enable-libx264 --enable-nonfree --enable-version3 --extra-cflags=-fPIC --extra-ldflags=-fPIC
  libavutil      52. 89.100 / 52. 89.100
  libavcodec     55. 67.100 / 55. 67.100
  libavformat    55. 43.100 / 55. 43.100
  libavdevice    55. 13.101 / 55. 13.101
  libavfilter     4.  8.100 /  4.  8.100
  libswscale      2.  6.100 /  2.  6.100
  libswresample   0. 19.100 /  0. 19.100
  libpostproc    52.  3.100 / 52.  3.100
[tcp @ 0x23f8e40] Connection to tcp://localhost:10103?timeout=0 failed (Connection refused), trying next address
Guessed Channel Layout for  Input Stream #0.1 : mono
Input #0, rtsp, from 'rtsp://localhost:10103/proxyStream':
  Metadata:
    title           : LIVE555 Streaming Media v2014.07.18
    comment         : LIVE555 Streaming Media v2014.07.18
  Duration: N/A, start: 1406200279.476000, bitrate: 64 kb/s
    Stream #0:0: Video: h264 (High), yuvj420p(pc), 1920x1080, 12.50 fps, 12.50 tbr, 90k tbn, 25 tbc
    Stream #0:1: Audio: pcm_mulaw, 8000 Hz, 1 channels, s16, 64 kb/s
[libfdk_aac @ 0x24ab440] Note, the VBR setting is unsupported and only works with some parameter combinations
Output #0, segment, to 'test_%02d.mkv':
  Metadata:
    title           : LIVE555 Streaming Media v2014.07.18
    comment         : LIVE555 Streaming Media v2014.07.18
    encoder         : Lavf55.43.100
    Stream #0:0: Video: h264, yuvj420p, 1920x1080, q=2-31, 12.50 fps, 90k tbn, 12.50 tbc
    Stream #0:1: Audio: aac (libfdk_aac), 44100 Hz, mono, s16
    Metadata:
      encoder         : Lavc55.67.100 libfdk_aac
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (pcm_mulaw (native) -> aac (libfdk_aac))
Press [q] to stop, [?] for help
frame=   94 fps= 14 q=-1.0 Lsize=N/A time=00:00:08.21 bitrate=N/A
video:1957kB audio:48kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
Received signal 2: terminating.
deployer@XanBox:~/test$

Broken version, commit: 194be1f43ea391eb986732707435176e579265aa -

deployer@XanBox:~/test$ rm *.mkv; ffmpeg -use_wallclock_as_timestamps 1 -rtsp_transport tcp -i rtsp://localhost:10103/proxyStream -dn -map 0 -af aresample=async=1000 -codec:a libfdk_aac -flags +qscale -global_quality 1 -afterburner 1 -ar 44100 -codec:v copy -f segment -segment_time 60 -segment_wrap 10 -segment_list_flags live -segment_list_size 10 -reset_timestamps 1 -segment_list test.csv -y test_%02d.mkv
ffmpeg version N-64054-gac293b6 Copyright (c) 2000-2014 the FFmpeg developers
  built on Jul 24 2014 11:49:57 with gcc 4.8 (Ubuntu 4.8.2-19ubuntu1)
  configuration: --enable-pic --enable-shared --extra-ldflags=-ldl --enable-gpl --enable-libfdk-aac --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libtheora --enable-libvorbis --enable-libx264 --enable-nonfree --enable-version3 --extra-cflags=-fPIC --extra-ldflags=-fPIC
  libavutil      52. 89.100 / 52. 89.100
  libavcodec     55. 67.100 / 55. 67.100
  libavformat    55. 44.100 / 55. 44.100
  libavdevice    55. 13.101 / 55. 13.101
  libavfilter     4.  8.100 /  4.  8.100
  libswscale      2.  6.100 /  2.  6.100
  libswresample   0. 19.100 /  0. 19.100
  libpostproc    52.  3.100 / 52.  3.100
[tcp @ 0x9b3e40] Connection to tcp://localhost:10103?timeout=0 failed (Connection refused), trying next address
Guessed Channel Layout for  Input Stream #0.1 : mono
Input #0, rtsp, from 'rtsp://localhost:10103/proxyStream':
  Metadata:
    title           : LIVE555 Streaming Media v2014.07.18
    comment         : LIVE555 Streaming Media v2014.07.18
  Duration: N/A, start: 1406199492.592900, bitrate: 64 kb/s
    Stream #0:0: Video: h264 (High), yuvj420p(pc), 1920x1080, 12.50 fps, 12.50 tbr, 90k tbn, 25 tbc
    Stream #0:1: Audio: pcm_mulaw, 8000 Hz, 1 channels, s16, 64 kb/s
[libfdk_aac @ 0xae96c0] Note, the VBR setting is unsupported and only works with some parameter combinations
[segment @ 0x9d6dc0] Using AVStream.codec.time_base as a timebase hint to the muxer is deprecated. Set AVStream.time_base instead.
    Last message repeated 1 times
[matroska @ 0x9b3540] Using AVStream.codec.time_base as a timebase hint to the muxer is deprecated. Set AVStream.time_base instead.
    Last message repeated 1 times
Output #0, segment, to 'test_%02d.mkv':
  Metadata:
    title           : LIVE555 Streaming Media v2014.07.18
    comment         : LIVE555 Streaming Media v2014.07.18
    encoder         : Lavf55.44.100
    Stream #0:0: Video: h264, yuvj420p, 1920x1080, q=2-31, 12.50 fps, 12.50 tbn, 12.50 tbc
    Stream #0:1: Audio: aac (libfdk_aac), 44100 Hz, mono, s16
    Metadata:
      encoder         : Lavc55.67.100 libfdk_aac
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (pcm_mulaw (native) -> aac (libfdk_aac))
Press [q] to stop, [?] for help
[segment @ 0x9d6dc0] Non-monotonous DTS in output stream 0:0; previous: 22, current: 22; changing to 23. This may result in incorrect timestamps in the output file.
[segment @ 0x9d6dc0] Non-monotonous DTS in output stream 0:0; previous: 23, current: 23; changing to 24. This may result in incorrect timestamps in the output file.
[segment @ 0x9d6dc0] Non-monotonous DTS in output stream 0:0; previous: 24, current: 24; changing to 25. This may result in incorrect timestamps in the output file.
[segment @ 0x9d6dc0] Non-monotonous DTS in output stream 0:0; previous: 25, current: 25; changing to 26. This may result in incorrect timestamps in the output file.
[segment @ 0x9d6dc0] Non-monotonous DTS in output stream 0:0; previous: 26, current: 26; changing to 27. This may result in incorrect timestamps in the output file.
[segment @ 0x9d6dc0] Non-monotonous DTS in output stream 0:0; previous: 27, current: 26; changing to 28. This may result in incorrect timestamps in the output file.
[segment @ 0x9d6dc0] Non-monotonous DTS in output stream 0:0; previous: 28, current: 27; changing to 29. This may result in incorrect timestamps in the output file.
[segment @ 0x9d6dc0] Non-monotonous DTS in output stream 0:0; previous: 29, current: 27; changing to 30. This may result in incorrect timestamps in the output file.
[segment @ 0x9d6dc0] Non-monotonous DTS in output stream 0:0; previous: 30, current: 28; changing to 31. This may result in incorrect timestamps in the output file.
[segment @ 0x9d6dc0] Non-monotonous DTS in output stream 0:0; previous: 31, current: 29; changing to 32. This may result in incorrect timestamps in the output file.
[segment @ 0x9d6dc0] Non-monotonous DTS in output stream 0:0; previous: 32, current: 30; changing to 33. This may result in incorrect timestamps in the output file.
[segment @ 0x9d6dc0] Non-monotonous DTS in output stream 0:0; previous: 33, current: 31; changing to 34. This may result in incorrect timestamps in the output file.
[segment @ 0x9d6dc0] Non-monotonous DTS in output stream 0:0; previous: 34, current: 33; changing to 35. This may result in incorrect timestamps in the output file.
frame=   22 fps= 19 q=-1.0 Lsize=N/A time=00:00:02.88 bitrate=N/A
video:452kB audio:15kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
Received signal 2: terminating.
Last edited 5 years ago by hackeron (previous) (diff)

comment:3 Changed 5 years ago by hackeron

I've identified what specific commit caused this issue and it is:

commit ac293b66851f6c4461eab03ca91af59d5ee4e02e
Merge: 8851437 194be1f
Author: Michael Niedermayer <michaelni@gmx.at>
Date:   Wed Jun 18 18:18:25 2014 +0200

    Merge commit '194be1f43ea391eb986732707435176e579265aa'

    * commit '194be1f43ea391eb986732707435176e579265aa':
      lavf: switch to AVStream.time_base as the hint for the muxer timebase

    Conflicts:
        doc/APIchanges
        libavformat/filmstripenc.c
        libavformat/movenc.c
        libavformat/mxfenc.c
        libavformat/oggenc.c
        libavformat/swf.h
        libavformat/version.h
        tests/ref/lavf/mkv

    Merged-by: Michael Niedermayer <michaelni@gmx.at>

This is the diff of what was changed: http://git.videolan.org/?p=ffmpeg.git;a=commitdiff;h=ac293b66851f6c4461eab03ca91af59d5ee4e02e

comment:4 Changed 5 years ago by hackeron

  • Summary changed from Latest trunk is not syncing audio/video from RTSP to AVStream.time_base is causing audio/video sync issues and growing videos

comment:5 Changed 5 years ago by hackeron

  • Component changed from undetermined to avformat

comment:6 Changed 5 years ago by cehoyos

  • Status changed from new to open

comment:7 Changed 5 years ago by cehoyos

  • Keywords regression added

comment:8 Changed 5 years ago by michael

please provide a publically available rtsp url with which this can be reproduced or a local input file if it can be reproduced without rtsp
so we can debug, test and fix this. Ive fixes some related issues but i suspect this is still not working

comment:9 Changed 5 years ago by hackeron

I'm not quite sure how to get a local input file - any example? -- Otherwise I will connect and set up port forwarding tomorrow.

comment:10 Changed 5 years ago by michael

you could try to copy the rtsp stuff into some container and check if its reproduceabel with that.
something like ffmpeg -i rstp... -vcodec copy -acodec copy file.nut / file.mkv

comment:11 Changed 5 years ago by michael

  • Cc michael added

comment:12 Changed 5 years ago by hackeron

I've made the stream publicly available for the time being here: rtsp://admin:@86.146.232.61/live1.sdp -- please let me know when I can take it down :)

Version 0, edited 5 years ago by hackeron (next)

comment:13 Changed 5 years ago by hackeron

Correction, the stream is on: rtsp://86.146.232.61/proxyStream

To reproduce, if you are using homebrew on a Mac, compile ffmpeg with fdk-aac: brew install ffmpeg --with-fdk-aac --HEAD

Then run:

ffmpeg -use_wallclock_as_timestamps 1 -rtsp_transport tcp -i 'rtsp://86.146.232.61/proxyStream' -dn -map 0 -codec:a libfdk_aac -ar 44100 -codec:v copy -f segment -segment_time 60 -segment_wrap 10 -segment_list_flags live -segment_list_size 10 -reset_timestamps 1 -segment_list test.csv -y 'test_%02d.mkv'
Last edited 5 years ago by hackeron (previous) (diff)

comment:14 Changed 5 years ago by cehoyos

Is libfdk required to reproduce the problem or is it also reproducible with the native aac encoder?

comment:15 follow-up: Changed 5 years ago by hackeron

I haven't tried the native one as it says "The encoder 'aac' is experimental but experimental codecs are not enabled".

When using libbfaac, the "Non-monotonous DTS" errors are less frequent and the duration doesn't grow, so it does seem to be related to libfdk, not sure if it relates to others too.

comment:16 in reply to: ↑ 15 Changed 5 years ago by cehoyos

Replying to hackeron:

I haven't tried the native one as it says "The encoder 'aac' is experimental but experimental codecs are not enabled".

Please test with -acodec aac -strict -2.

comment:17 Changed 5 years ago by hackeron

There seem to be a lot more errors like this:

[segment @ 0x19a5e20] Non-monotonous DTS in output stream 0:1; previous: 12466764, current: 12460908; changing to 12466765. This may result in incorrect timestamps in the output file.
[segment @ 0x19a5e20] Non-monotonous DTS in output stream 0:1; previous: 12466765, current: 12462998; changing to 12466766. This may result in incorrect timestamps in the output file.
[aac @ 0x1a45b80] Queue input is backward in time

But the output video time doesn't grow so I guess it is related to libfdk_aac.

This is the full command I'm using:

ffmpeg -use_wallclock_as_timestamps 1 -rtsp_transport tcp -i 'rtsp://86.146.232.61/proxyStream' -dn -map 0 -acodec aac -strict -2 -ar 44100 -codec:v copy -f segment -segment_time 60 -segment_wrap 10 -segment_list_flags live -segment_list_size 10 -reset_timestamps 1 -segment_list test.csv -y 'test_%02d.mkv'

comment:18 Changed 5 years ago by michael

Connection to tcp://86.146.232.61:554?timeout=0 failed: Connection timed out

comment:19 Changed 5 years ago by michael

not reproducable with another rtsp source it seems

comment:20 follow-up: Changed 5 years ago by ricky-ticky

Hello, i got similar problem (alot of "Non-monotonous DTS" and picture
twitching) with input from mumudvb.
The problem are appear only with "-codec:v copy".
There is no such problem with ffmpeg 2.2.1, and there are with ffmpeg 2.3.3 and 2.4.1
If you need, i can share input stream.

Last edited 5 years ago by ricky-ticky (previous) (diff)

comment:21 in reply to: ↑ 20 Changed 5 years ago by cehoyos

Replying to ricky-ticky:

If you need, i can share input stream.

This is only needed if you'd like the issue fixed.

comment:22 Changed 5 years ago by hackeron

The IP address changed, here is the up to date address:

ffmpeg -use_wallclock_as_timestamps 1 -rtsp_transport tcp -i 'rtsp://86.146.233.53/proxyStream' -dn -map 0 -acodec aac -strict -2 -ar 44100 -codec:v copy -f segment -segment_time 60 -segment_wrap 10 -segment_list_flags live -segment_list_size 10 -reset_timestamps 1 -segment_list test.csv -y 'test_%02d.mkv'

comment:23 Changed 5 years ago by ricky-ticky

share my stream too: http://194.85.16.42:9005. IP is static.
use it like this:
/usr/bin/ffmpeg -i http://194.85.16.42:9005 -vcodec copy -threads 4 -strict experimental -acodec libfdk_aac -ar 44100 -ac 2 -ab 96000 -bufsize 1835k -pix_fmt yuv420p -flags -global_header -hls_time 10 -hls_list_size 6 -hls_wrap 10 -start_number 1 /live/stream/hi.m3u8

Changed 5 years ago by ricky-ticky

ffmpeg 2.4.1 buggy console output

Changed 5 years ago by ricky-ticky

ffmpeg 2.2.1 console output

comment:24 Changed 5 years ago by ricky-ticky

added two attachments with ffmpeg 2.2.1 and 2.4.1 console output for same stream.

comment:25 Changed 5 years ago by michael

the rtsp://86.146.233.53/proxyStream stream freezes after a few seconds with every version i tried. The other results in http://194.85.16.42:9005: No such file or directory

comment:26 Changed 5 years ago by michael

The "No such file or directory" was caused by a unicode "zero width space" in there

comment:27 Changed 5 years ago by michael

  • Resolution set to fixed
  • Status changed from open to closed
Note: See TracTickets for help on using tickets.