diff --git a/libavcodec/mpeg12.c b/libavcodec/mpeg12.c index fc43a53701..153e4aa300 100644 --- a/libavcodec/mpeg12.c +++ b/libavcodec/mpeg12.c @@ -234,7 +234,7 @@ int ff_mpeg1_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size, } } if (pc->frame_start_found == 0 && s && state == PICTURE_START_CODE) { - ff_fetch_timestamp(s, i - 3, 1); + ff_fetch_timestamp(s, i - 3, 1, 0); } } } diff --git a/libavcodec/parser.c b/libavcodec/parser.c index d1e1574a65..8a3be295aa 100644 --- a/libavcodec/parser.c +++ b/libavcodec/parser.c @@ -93,14 +93,16 @@ err_out: return NULL; } -void ff_fetch_timestamp(AVCodecParserContext *s, int off, int remove) +void ff_fetch_timestamp(AVCodecParserContext *s, int off, int remove, int fuzzy) { int i; - s->dts = - s->pts = AV_NOPTS_VALUE; - s->pos = -1; - s->offset = 0; + if (!fuzzy) { + s->dts = + s->pts = AV_NOPTS_VALUE; + s->pos = -1; + s->offset = 0; + } for (i = 0; i < AV_PARSER_PTS_NB; i++) { if (s->cur_offset + off >= s->cur_frame_offset[i] && (s->frame_offset < s->cur_frame_offset[i] || @@ -108,10 +110,12 @@ void ff_fetch_timestamp(AVCodecParserContext *s, int off, int remove) // check disabled since MPEG-TS does not send complete PES packets /*s->next_frame_offset + off <*/ s->cur_frame_end[i]){ - s->dts = s->cur_frame_dts[i]; - s->pts = s->cur_frame_pts[i]; - s->pos = s->cur_frame_pos[i]; - s->offset = s->next_frame_offset - s->cur_frame_offset[i]; + if (!fuzzy || s->cur_frame_dts[i] != AV_NOPTS_VALUE) { + s->dts = s->cur_frame_dts[i]; + s->pts = s->cur_frame_pts[i]; + s->pos = s->cur_frame_pos[i]; + s->offset = s->next_frame_offset - s->cur_frame_offset[i]; + } if (remove) s->cur_frame_offset[i] = INT64_MAX; if (s->cur_offset + off < s->cur_frame_end[i]) @@ -154,7 +158,7 @@ int av_parser_parse2(AVCodecParserContext *s, AVCodecContext *avctx, s->last_pts = s->pts; s->last_dts = s->dts; s->last_pos = s->pos; - ff_fetch_timestamp(s, 0, 0); + ff_fetch_timestamp(s, 0, 0, 0); } /* WARNING: the returned index can be negative */ index = s->parser->parser_parse(s, avctx, (const uint8_t **) poutbuf, diff --git a/libavcodec/parser.h b/libavcodec/parser.h index 7fe0e115b1..ef35547e9b 100644 --- a/libavcodec/parser.h +++ b/libavcodec/parser.h @@ -53,7 +53,8 @@ void ff_parse_close(AVCodecParserContext *s); * Fetch timestamps for a specific byte within the current access unit. * @param off byte position within the access unit * @param remove Found timestamps will be removed if set to 1, kept if set to 0. + * @param fuzzy Only use found value if it is more informative than what we already have */ -void ff_fetch_timestamp(AVCodecParserContext *s, int off, int remove); +void ff_fetch_timestamp(AVCodecParserContext *s, int off, int remove, int fuzzy); #endif /* AVCODEC_PARSER_H */