aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec/encode.c
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2022-07-12 11:25:09 +0200
committerAnton Khirnov <anton@khirnov.net>2023-01-29 09:23:15 +0100
commita1a80f2e64f31755be74d8cc7afb1aafe000c29a (patch)
treed870fa655bc8c6787f5c3915224574fb8a9d055a /libavcodec/encode.c
parent8d73f3ce56fc90d840c83e8ab3463474d2d38046 (diff)
downloadffmpeg-a1a80f2e64f31755be74d8cc7afb1aafe000c29a.tar.gz
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.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/libavcodec/encode.c b/libavcodec/encode.c
index 555bd3ff96..c92beaf8e1 100644
--- a/libavcodec/encode.c
+++ b/libavcodec/encode.c
@@ -231,10 +231,13 @@ int ff_encode_encode_cb(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);
+ }
}
ret = ff_encode_reordered_opaque(avctx, avpkt, frame);
@@ -463,6 +466,13 @@ FF_ENABLE_DEPRECATION_WARNINGS
return ret;
}
+ // unset frame duration unless AV_CODEC_FLAG_FRAME_DURATION is set,
+ // since 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 (!(avctx->flags & AV_CODEC_FLAG_FRAME_DURATION))
+ dst->duration = 0;
+
return 0;
}