]> granicus.if.org Git - handbrake/commitdiff
encavcodecaudio: work around lame bug
authorJohn Stebbins <jstebbins.hb@gmail.com>
Thu, 11 May 2017 20:17:51 +0000 (13:17 -0700)
committerJohn Stebbins <jstebbins.hb@gmail.com>
Thu, 11 May 2017 20:19:40 +0000 (13:19 -0700)
On windows builds, there is an upstream bug in the lame
encoder that causes an extra output packet that has the same
timestamp as the second to last packet.  This causes an error
during muxing. Drop the packet with the duplicate timestamp.

Fixes https://github.com/HandBrake/HandBrake/issues/726

libhb/encavcodecaudio.c

index b7f2969d922f18ca2dc37074640495e450abddf8..5f95c73832804de0382f3e5ff961cba088bdb171 100644 (file)
@@ -24,6 +24,8 @@ struct hb_work_private_s
     hb_list_t      * list;
 
     AVAudioResampleContext *avresample;
+
+    int64_t          last_pts;
 };
 
 static int  encavcodecaInit( hb_work_object_t *, hb_job_t * );
@@ -49,6 +51,7 @@ static int encavcodecaInit(hb_work_object_t *w, hb_job_t *job)
     w->private_data       = pv;
     pv->job               = job;
     pv->list              = hb_list_init();
+    pv->last_pts          = AV_NOPTS_VALUE;
 
     // channel count, layout and matrix encoding
     int matrix_encoding;
@@ -363,17 +366,26 @@ static void get_packets( hb_work_object_t * w, hb_buffer_list_t * list )
         out = hb_buffer_init(pkt.size);
         memcpy(out->data, pkt.data, out->size);
 
-        // The output pts from libav is in context->time_base. Convert it
-        // back to our timebase.
-        out->s.start = av_rescale_q(pkt.pts, pv->context->time_base,
-                                    (AVRational){1, 90000});
-        out->s.duration  = (double)90000 * pv->samples_per_frame /
-                                           audio->config.out.samplerate;
-        out->s.stop      = out->s.start + out->s.duration;
-        out->s.type      = AUDIO_BUF;
-        out->s.frametype = HB_FRAME_AUDIO;
-
-        hb_buffer_list_append(list, out);
+        // FIXME: On windows builds, there is an upstream bug in the lame
+        // encoder that causes an extra output packet that has the same
+        // timestamp as the second to last packet.  This causes an error
+        // during muxing. Work around it by dropping such packets here.
+        // See: https://github.com/HandBrake/HandBrake/issues/726
+        if (pkt.pts > pv->last_pts)
+        {
+            // The output pts from libav is in context->time_base. Convert it
+            // back to our timebase.
+            out->s.start = av_rescale_q(pkt.pts, pv->context->time_base,
+                                        (AVRational){1, 90000});
+            out->s.duration  = (double)90000 * pv->samples_per_frame /
+                                               audio->config.out.samplerate;
+            out->s.stop      = out->s.start + out->s.duration;
+            out->s.type      = AUDIO_BUF;
+            out->s.frametype = HB_FRAME_AUDIO;
+
+            hb_buffer_list_append(list, out);
+            pv->last_pts = pkt.pts;
+        }
         av_packet_unref(&pkt);
     }
 }