#175 Avformat can't stream continuously

feature_request
closed
nobody
5
2014-06-30
2012-10-11
Mariusz Wolek
No

After a several hours of continuously playing (about 10-12h) melted stops and print out "[mpegts @ 0x7f18f4391480] Application provided invalid, non monotonically increasing dts to muxer in stream 1: 4026529920 >= -4026531840"
I use avformat as a consumer and a short avi (2-3min duration) movies. Eof is set to loop.

I also tried to play it using swig/perl script and I got the same result.
My perl consume settings are:
$c = new mlt::FilteredConsumer( $profile, "avformat:udp://192.168.90.102:1234");
$c->set( "real_time", 1 );
$c->set( "terminate_on_pause", 0 );
$c->set( "f", "mpegts" );
$c->set( "vcodec", "mpeg4" );
$c->set( "b", "3000k" );
$c->set( "acodec", "aac" );
$c->set( "ab", "128k" );
$c->set( "samplerate", 48000);
$c->set( "channels",2);

Discussion

  • Mariusz Wolek
    Mariusz Wolek
    2012-10-11

    • summary: Avformat cannot stream continuously --> Avformat can't stream continuously
     
  • Mariusz Wolek
    Mariusz Wolek
    2012-10-11

    also there is
    [mpegts @ 0x7f18f4391480] Encoder did not produce proper pts, making some up.
    [aac @ 0x7f18f43a57e0] Que input is backward in time

     
  • Dan Dennedy
    Dan Dennedy
    2012-10-11

    • assigned_to: ddennedy --> nobody
     
  • pegro
    pegro
    2013-07-04

    We experienced the same bug trying different codecs and formats. After several hours of debugging we think tracked it down to a bug in ffmpeg in a deprecated API.

    Melt uses the avcodec_encode_audio function, which is deprecated since beginning of 2012.
    ffmpegs APIchanges file states:

     2012-01-15 - lavc 53.56.105 / 53.34.0
      New audio encoding API:
       67f5650 / b2c75b6 Add CODEC_CAP_VARIABLE_FRAME_SIZE capability for use by audio encoders.
       67f5650 / 5ee5fa0 Add avcodec_fill_audio_frame() as a convenience function.
       67f5650 / b2c75b6 Add avcodec_encode_audio2() and deprecate avcodec_encode_audio(). Add AVCodec.encode2().
    

    While deprecating the old API they introduced the occurring bug by using a 32bit integer for timestamps instead of 64bit like everywhere else in the code.

    Using plain ffmpeg doesn't trigger this bug, since they don't use the compatibility API.

    The patch to fix this is simple. I filed a bug upstream: https://trac.ffmpeg.org/ticket/2752

    diff -ur ffmpeg-1.2.1/libavcodec/internal.h ffmpeg-1.2.1-64bit-samplecount/libavcodec/internal.h
    --- ffmpeg-1.2.1/libavcodec/internal.h  2013-06-30 16:21:55.448676657 +0200
    +++ ffmpeg-1.2.1-64bit-samplecount/libavcodec/internal.h        2013-06-30 16:24:37.165331386 +0200
    @@ -67,7 +67,7 @@
          * Internal sample count used by avcodec_encode_audio() to fabricate pts.
          * Can be removed along with avcodec_encode_audio().
          */
    -    int sample_count;
    +    int64_t sample_count;
     #endif
    
         /**
    


    API versions

    Melts avformat consumer is somewhat to conservative regarding ffmpeg API versions. The "new" encode API (avcodec_encode_audio2) will only be used, if LIBAVCODECVERSION >= 55 although it's available since ffmpeg 1.0. The current stable ffmpeg contains libavcodec version 54. 92.100. A check whether the API version is greater or equal 54 should be sufficient. At least for me it compiles and works as intended. Maybe that works for all API version checks in the avformat consumer and producer.

     
    Last edit: pegro 2013-07-04
  • Dan Dennedy
    Dan Dennedy
    2013-07-04

    Regarding API version usage, libav and ffmpeg went through a lot of API changes, and I chose to wait a little for things to settle and then make a major update wherein it was more manageable to use old vs. new API rather broadly. There is a lot to balance between versions mlt tries to support. Also, I prefer not to use a new API as soon as it becomes available because it might not be "fully baked." However, in this case, I am testing a change to use encode_audio2() for LIBAVCODEC_VERSION_MAJOR >= 54.

     
  • Dan Dennedy
    Dan Dennedy
    2013-07-04

    • status: open --> pending
    • Group: --> feature_request
     
  • Dan Dennedy
    Dan Dennedy
    2013-07-04

    Git commit eceaa40d6b3bef3866f8f4bf07df6b2cb0a58b3c switches to new avcodec_encode_audio2() API for libavcodec >= 54.

     
    Last edit: Dan Dennedy 2013-07-04
  • Dan Dennedy
    Dan Dennedy
    2014-06-30

    • status: pending --> closed