diff options
author | John Stebbins <[email protected]> | 2019-01-07 15:30:05 -0700 |
---|---|---|
committer | John Stebbins <[email protected]> | 2019-01-07 15:31:47 -0700 |
commit | 76f14dad963db46961ce3d425a102ac3d898ce10 (patch) | |
tree | 8011a0dbe6e248f4df595ba34427952919aa658d | |
parent | 58ed6c8a448ab61f55fcba4df03718346bfb81d4 (diff) |
fix missing frames when transcoding m2ts files
Fixes https://github.com/HandBrake/HandBrake/issues/1611
-rw-r--r-- | libhb/decavcodec.c | 66 | ||||
-rw-r--r-- | libhb/stream.c | 3 |
2 files changed, 68 insertions, 1 deletions
diff --git a/libhb/decavcodec.c b/libhb/decavcodec.c index 2294f8e8b..1c3f51070 100644 --- a/libhb/decavcodec.c +++ b/libhb/decavcodec.c @@ -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; diff --git a/libhb/stream.c b/libhb/stream.c index adc9a3eed..427e10209 100644 --- a/libhb/stream.c +++ b/libhb/stream.c @@ -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 ); |