This will allow parsers to export the duration of the current frame being
output, if known, instead of using AVCodecContext.frame_size.
| ... | ... |
@@ -3994,6 +3994,13 @@ typedef struct AVCodecParserContext {
|
| 3994 | 3994 |
* Previous frame byte position. |
| 3995 | 3995 |
*/ |
| 3996 | 3996 |
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; |
|
| 3997 | 4004 |
} AVCodecParserContext; |
| 3998 | 4005 |
|
| 3999 | 4006 |
typedef struct AVCodecParser {
|
| ... | ... |
@@ -1039,6 +1039,20 @@ static int read_frame_internal(AVFormatContext *s, AVPacket *pkt) |
| 1039 | 1039 |
if (pkt->size) {
|
| 1040 | 1040 |
got_packet: |
| 1041 | 1041 |
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 |
+ } |
|
| 1042 | 1056 |
pkt->stream_index = st->index; |
| 1043 | 1057 |
pkt->pts = st->parser->pts; |
| 1044 | 1058 |
pkt->dts = st->parser->dts; |