diff options
author | Justin Ruggles <justin.ruggles@gmail.com> | 2012-01-12 20:03:17 -0500 |
---|---|---|
committer | Justin Ruggles <justin.ruggles@gmail.com> | 2012-02-20 15:08:40 -0500 |
commit | e9cda853511d7c5a8fa16da4f99cf8ead86bf658 (patch) | |
tree | 1bbd4917b41b24a84c3419aab35c511be508233c /libavformat/utils.c | |
parent | 0b42a9388c98c8669811d4e7e5da7240e6707a41 (diff) | |
download | ffmpeg-e9cda853511d7c5a8fa16da4f99cf8ead86bf658.tar.gz |
avcodec: add duration field to AVCodecParserContext
This will allow parsers to export the duration of the current frame being
output, if known, instead of using AVCodecContext.frame_size.
Diffstat (limited to 'libavformat/utils.c')
-rw-r--r-- | libavformat/utils.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/libavformat/utils.c b/libavformat/utils.c index 33775b9a2b..24175228ab 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -1039,6 +1039,20 @@ static int read_frame_internal(AVFormatContext *s, AVPacket *pkt) if (pkt->size) { got_packet: pkt->duration = 0; + if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { + if (st->codec->sample_rate > 0) { + pkt->duration = av_rescale_q_rnd(st->parser->duration, + (AVRational){ 1, st->codec->sample_rate }, + st->time_base, + AV_ROUND_DOWN); + } + } else if (st->codec->time_base.num != 0 && + st->codec->time_base.den != 0) { + pkt->duration = av_rescale_q_rnd(st->parser->duration, + st->codec->time_base, + st->time_base, + AV_ROUND_DOWN); + } pkt->stream_index = st->index; pkt->pts = st->parser->pts; pkt->dts = st->parser->dts; |