# HG changeset patch # User benoit # Date 1176450604 0 # Node ID d0d39f124c6b99486a8f7c4d95545412bd6bf5f1 # Parent e046ab4f6571eff8e1649e3efb2103c9734d0592 timestamps generation improvement when parsing avi patch by Joakim \ elupus chez ecce dot se / original thread: date: 03/19/2007 01:47 AM subject: [Ffmpeg-devel] [RFC] Improvement for the odd timestamp generation when parser is in use. diff -r e046ab4f6571 -r d0d39f124c6b avformat.h --- a/avformat.h Thu Apr 12 11:28:34 2007 +0000 +++ b/avformat.h Fri Apr 13 07:50:04 2007 +0000 @@ -25,8 +25,8 @@ extern "C" { #endif -#define LIBAVFORMAT_VERSION_INT ((51<<16)+(12<<8)+0) -#define LIBAVFORMAT_VERSION 51.12.0 +#define LIBAVFORMAT_VERSION_INT ((51<<16)+(12<<8)+1) +#define LIBAVFORMAT_VERSION 51.12.1 #define LIBAVFORMAT_BUILD LIBAVFORMAT_VERSION_INT #define LIBAVFORMAT_IDENT "Lavf" AV_STRINGIFY(LIBAVFORMAT_VERSION) @@ -309,7 +309,8 @@ char language[4]; /** ISO 639 3-letter language code (empty string if undefined) */ /* av_read_frame() support */ - int need_parsing; ///< 1->full parsing needed, 2->only parse headers dont repack +#define AVSTREAM_PARSE_TIMESTAMPS 3 /**< full parsing and interpolation of timestamps for frames not starting on packet boundary */ + int need_parsing; ///< 1->full parsing needed, 2->only parse headers dont repack, 3->full parsing and interpolate timestamps struct AVCodecParserContext *parser; int64_t cur_dts; diff -r e046ab4f6571 -r d0d39f124c6b avidec.c --- a/avidec.c Thu Apr 12 11:28:34 2007 +0000 +++ b/avidec.c Fri Apr 13 07:50:04 2007 +0000 @@ -452,8 +452,8 @@ if (size%2) /* 2-aligned (fix for Stargate SG-1 - 3x18 - Shades of Grey.avi) */ url_fskip(pb, 1); /* Force parsing as several audio frames can be in - * one packet. */ - st->need_parsing = 1; + * one packet and timestamps refer to packet start*/ + st->need_parsing = AVSTREAM_PARSE_TIMESTAMPS; /* ADTS header is in extradata, AAC without header must be stored as exact frames, parser not needed and it will fail */ if (st->codec->codec_id == CODEC_ID_AAC && st->codec->extradata_size) st->need_parsing = 0; diff -r e046ab4f6571 -r d0d39f124c6b utils.c --- a/utils.c Thu Apr 12 11:28:34 2007 +0000 +++ b/utils.c Fri Apr 13 07:50:04 2007 +0000 @@ -584,6 +584,7 @@ AVCodecParserContext *pc, AVPacket *pkt) { int num, den, presentation_delayed, delay, i; + int64_t offset; /* handle wrapping */ if(st->cur_dts != AV_NOPTS_VALUE){ if(pkt->pts != AV_NOPTS_VALUE) @@ -599,6 +600,16 @@ } } + /* correct timestamps with byte offset if demuxers only have timestamps on packet boundaries */ + if(pc && st->need_parsing == AVSTREAM_PARSE_TIMESTAMPS && pkt->size){ + /* this will estimate bitrate based on this frame's duration and size */ + offset = av_rescale(pc->offset, pkt->duration, pkt->size); + if(pkt->pts != AV_NOPTS_VALUE) + pkt->pts += offset; + if(pkt->dts != AV_NOPTS_VALUE) + pkt->dts += offset; + } + if(is_intra_only(st->codec)) pkt->flags |= PKT_FLAG_KEY;