]> granicus.if.org Git - handbrake/commitdiff
fix missing frames when transcoding m2ts files
authorJohn Stebbins <jstebbins.hb@gmail.com>
Mon, 7 Jan 2019 22:30:05 +0000 (15:30 -0700)
committerJohn Stebbins <jstebbins.hb@gmail.com>
Mon, 7 Jan 2019 22:43:59 +0000 (15:43 -0700)
Fixes https://github.com/HandBrake/HandBrake/issues/1611

(cherry picked from commit 76f14dad963db46961ce3d425a102ac3d898ce10)

libhb/decavcodec.c
libhb/stream.c

index 2294f8e8b5283bbf1561520c97ff0b14c76f3b13..1c3f51070af4bb37556d66d341744e33ee99822c 100644 (file)
@@ -424,6 +424,34 @@ static void decavcodecClose( hb_work_object_t * w )
     }
 }
 
+static void audioParserFlush(hb_work_object_t * w)
+{
+    hb_work_private_t * pv = w->private_data;
+    uint8_t * pout;
+    int       pout_len;
+    int64_t   parser_pts;
+
+    do
+    {
+        if (pv->parser)
+        {
+            av_parser_parse2(pv->parser, pv->context, &pout, &pout_len,
+                                   NULL, 0,
+                                   AV_NOPTS_VALUE, AV_NOPTS_VALUE, 0 );
+            parser_pts = pv->parser->pts;
+        }
+
+        if (pout != NULL && pout_len > 0)
+        {
+            pv->packet_info.data         = pout;
+            pv->packet_info.size         = pout_len;
+            pv->packet_info.pts          = parser_pts;
+
+            decodeAudio(pv, &pv->packet_info);
+        }
+    } while (pout != NULL && pout_len > 0);
+}
+
 /***********************************************************************
  * Work
  ***********************************************************************
@@ -446,6 +474,7 @@ static int decavcodecaWork( hb_work_object_t * w, hb_buffer_t ** buf_in,
     if (in->s.flags & HB_BUF_FLAG_EOF)
     {
         /* EOF on input stream - send it downstream & say that we're done */
+        audioParserFlush(w);
         decodeAudio(pv, NULL);
         hb_buffer_list_append(&pv->list, in);
         *buf_in = NULL;
@@ -1690,6 +1719,42 @@ static int decodePacket( hb_work_object_t * w )
     return HB_WORK_OK;
 }
 
+static void videoParserFlush(hb_work_object_t * w)
+{
+    hb_work_private_t * pv = w->private_data;
+    int       result;
+    uint8_t * pout;
+    int       pout_len;
+    int64_t   parser_pts, parser_dts;
+
+    do
+    {
+        if (pv->parser)
+        {
+            av_parser_parse2(pv->parser, pv->context, &pout, &pout_len,
+                                   NULL, 0,
+                                   AV_NOPTS_VALUE, AV_NOPTS_VALUE, 0 );
+            parser_pts = pv->parser->pts;
+            parser_dts = pv->parser->dts;
+        }
+
+        if (pout != NULL && pout_len > 0)
+        {
+            pv->packet_info.data         = pout;
+            pv->packet_info.size         = pout_len;
+            pv->packet_info.pts          = parser_pts;
+            pv->packet_info.dts          = parser_dts;
+
+            result = decodePacket(w);
+            if (result != HB_WORK_OK)
+            {
+                break;
+            }
+            w->frame_count++;
+        }
+    } while (pout != NULL && pout_len > 0);
+}
+
 static int decavcodecvWork( hb_work_object_t * w, hb_buffer_t ** buf_in,
                             hb_buffer_t ** buf_out )
 {
@@ -1717,6 +1782,7 @@ static int decavcodecvWork( hb_work_object_t * w, hb_buffer_t ** buf_in,
     {
         if (pv->context != NULL && pv->context->codec != NULL)
         {
+            videoParserFlush(w);
             while (decodeFrame(pv, NULL))
             {
                 continue;
index adc9a3eed560bb3810be03045233550c0ad765a6..427e102094bbc59a6ba922b0d7f6635e2e3c4807 100644 (file)
@@ -4942,7 +4942,8 @@ static hb_buffer_t * hb_ts_stream_decode( hb_stream_t *stream )
             // end of file - we didn't finish filling our ps write buffer
             // so just discard the remainder (the partial buffer is useless)
             hb_log("hb_ts_stream_decode - eof");
-            return NULL;
+            b = flush_ts_streams(stream);
+            return b;
         }
 
         b = hb_ts_decode_pkt( stream, buf, 0, 0 );