]> granicus.if.org Git - handbrake/commitdiff
libhb: fix duration of initial audio frame when decoding with avcodec
authorjstebbins <jstebbins.hb@gmail.com>
Mon, 21 Oct 2013 20:57:38 +0000 (20:57 +0000)
committerjstebbins <jstebbins.hb@gmail.com>
Mon, 21 Oct 2013 20:57:38 +0000 (20:57 +0000)
For some codecs, the samplerate is not known until we decode some data.
So postpone calculation of frame duration till after we have decoded
some data.

The effect of this error is that the first 2 audio frames could have the
same start time.  This causes the "non monotonically increasing dts"
error in libavformat mp4 muxer.

git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@5849 b64f7644-9d1e-0410-96f1-a4d463321fa5

libhb/decavcodec.c

index 84ad5103c41f9a8418d823a06cb019d228fec3b8..15a14dcec35ca1d6d30d4392a4cc45ab41a305b8 100644 (file)
@@ -488,17 +488,6 @@ static int decavcodecaWork( hb_work_object_t * w, hb_buffer_t ** buf_in,
         }
         if (pout)
         {
-            // set the duration on every frame since the stream format can
-            // change (it shouldn't but there's no way to guarantee it).
-            // duration is a scaling factor to go from #bytes in the decoded
-            // frame to frame time (in 90KHz mpeg ticks). 'channels' converts
-            // total samples to per-channel samples. 'sample_rate' converts
-            // per-channel samples to seconds per sample and the 90000
-            // is mpeg ticks per second.
-            if ( pv->context->sample_rate )
-            {
-                pv->duration = 90000. / (double)( pv->context->sample_rate );
-            }
             decodeAudio( w->audio, pv, pout, pout_len, cur );
         }
     }
@@ -1922,6 +1911,21 @@ static void decodeAudio(hb_audio_t *audio, hb_work_private_t *pv, uint8_t *data,
 
         pos += len;
 
+        // set the duration on every frame since the stream format can
+        // change (it shouldn't but there's no way to guarantee it).
+        // duration is a scaling factor to go from #bytes in the decoded
+        // frame to frame time (in 90KHz mpeg ticks). 'channels' converts
+        // total samples to per-channel samples. 'sample_rate' converts
+        // per-channel samples to seconds per sample and the 90000
+        // is mpeg ticks per second.
+        //
+        // Also, sample rate is not available until we have decoded some
+        // audio.
+        if ( pv->context->sample_rate )
+        {
+            pv->duration = 90000. / (double)( pv->context->sample_rate );
+        }
+
         if (got_frame)
         {
             hb_buffer_t *out;