Skip to content

Commit

Permalink
fix missing frames when transcoding m2ts files
Browse files Browse the repository at this point in the history
  • Loading branch information
jstebbins committed Jan 7, 2019
1 parent 58ed6c8 commit 76f14da
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 1 deletion.
66 changes: 66 additions & 0 deletions libhb/decavcodec.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
***********************************************************************
Expand All @@ -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;
Expand Down Expand Up @@ -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 )
{
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion libhb/stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down

0 comments on commit 76f14da

Please sign in to comment.