diff options
author | Anton Khirnov <anton@khirnov.net> | 2022-07-12 11:25:09 +0200 |
---|---|---|
committer | Anton Khirnov <anton@khirnov.net> | 2022-08-23 16:50:32 +0200 |
commit | 2bf6c1c8e81e82c371d3eaad2503f1d00f7ffcee (patch) | |
tree | 8d38259b6e5c5083d560582aea32323e3788aae7 /libavcodec/encode.c | |
parent | 68413d4ee19d716205f950e3bd81ea511e2051cb (diff) |
lavc/encode: pass through frame durations to encoded packets
The generic code can only handle the no-delay case. Encoders with delay
need to be handled individually, which will be done in the following
commits.
Diffstat (limited to 'libavcodec/encode.c')
-rw-r--r-- | libavcodec/encode.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/libavcodec/encode.c b/libavcodec/encode.c index da910b1b60..76eb69bba8 100644 --- a/libavcodec/encode.c +++ b/libavcodec/encode.c @@ -230,10 +230,13 @@ static int encode_simple_internal(AVCodecContext *avctx, AVPacket *avpkt) if (avpkt->pts == AV_NOPTS_VALUE) avpkt->pts = frame->pts; - if (avctx->codec->type == AVMEDIA_TYPE_AUDIO) { - if (!avpkt->duration) + if (!avpkt->duration) { + if (frame->duration) + avpkt->duration = frame->duration; + else if (avctx->codec->type == AVMEDIA_TYPE_AUDIO) { avpkt->duration = ff_samples_to_time_base(avctx, frame->nb_samples); + } } } @@ -424,6 +427,13 @@ FF_ENABLE_DEPRECATION_WARNINGS return ret; } + // only use the frame duration if the timebase is set; + // otherwise we cannot be sure that whatever value it has is in the right + // timebase, so we would produce an incorrect value, which is worse than + // none at all + if (!dst->time_base.num || !dst->time_base.den) + dst->duration = 0; + return 0; } |