History

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.

Justin Ruggles committed 14 years ago

Commit e9cda851 parent 0b42a933 files · +24 −0Browse files

Unified · Split

3 files
  1. doc/APIchanges +3 −0
  2. libavcodec/avcodec.h +7 −0
  3. libavformat/utils.c +14 −0
doc/APIchanges+3−0
@@ -13,6 +13,9 @@ libavutil: 2011-04-18 · 12 unmodified lines
1313
1414 API changes, most recent first:
1515
16+2012-xx-xx - xxxxxxx - lavc 54.x.x
17+ Add duration field to AVCodecParserContext
18+
1619 2012-02-xx - xxxxxxx - lavu 51.23.1 - mathematics.h
1720 Add av_rescale_q_rnd()
1821
libavcodec/avcodec.h+7−0
@@ -3994,6 +3994,13 @@ typedef struct AVCodecParserContext { · 3993 unmodified lines
39943994 * Previous frame byte position.
39953995 */
39963996 int64_t last_pos;
3997+
3998+ /**
3999+ * Duration of the current frame.
4000+ * For audio, this is in units of 1 / AVCodecContext.sample_rate.
4001+ * For all other types, this is in units of AVCodecContext.time_base.
4002+ */
4003+ int duration;
39974004 } AVCodecParserContext;
39984005
39994006 typedef struct AVCodecParser {
libavformat/utils.c+14−0
@@ -1039,6 +1039,20 @@ static int read_frame_internal(AVFormatContext *s, AVPacket *pkt) · 1038 unmodified lines
10391039 if (pkt->size) {
10401040 got_packet:
10411041 pkt->duration = 0;
1042+ if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
1043+ if (st->codec->sample_rate > 0) {
1044+ pkt->duration = av_rescale_q_rnd(st->parser->duration,
1045+ (AVRational){ 1, st->codec->sample_rate },
1046+ st->time_base,
1047+ AV_ROUND_DOWN);
1048+ }
1049+ } else if (st->codec->time_base.num != 0 &&
1050+ st->codec->time_base.den != 0) {
1051+ pkt->duration = av_rescale_q_rnd(st->parser->duration,
1052+ st->codec->time_base,
1053+ st->time_base,
1054+ AV_ROUND_DOWN);
1055+ }
10421056 pkt->stream_index = st->index;
10431057 pkt->pts = st->parser->pts;
10441058 pkt->dts = st->parser->dts;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t