summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2022-07-12 11:25:09 +0200
committerAnton Khirnov <anton@khirnov.net>2022-08-23 16:50:32 +0200
commit2bf6c1c8e81e82c371d3eaad2503f1d00f7ffcee (patch)
tree8d38259b6e5c5083d560582aea32323e3788aae7
parent68413d4ee19d716205f950e3bd81ea511e2051cb (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.
-rw-r--r--libavcodec/avcodec.h3
-rw-r--r--libavcodec/encode.c14
-rw-r--r--libavcodec/version.h2
3 files changed, 15 insertions, 4 deletions
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 9c246c455c..96ee88c4fa 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -2647,7 +2647,8 @@ int avcodec_receive_frame(AVCodecContext *avctx, AVFrame *frame);
*
* frame->time_base should be set to the same value as
* avctx->time_base. This is not required yet, but may be in
- * the future.
+ * the future. frame->duration will be ignored unless time_base
+ * is set.
*
* For audio:
* If AV_CODEC_CAP_VARIABLE_FRAME_SIZE is set, then each frame
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;
}
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 12421666b9..d7d5fca6b2 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -30,7 +30,7 @@
#include "version_major.h"
#define LIBAVCODEC_VERSION_MINOR 42
-#define LIBAVCODEC_VERSION_MICRO 102
+#define LIBAVCODEC_VERSION_MICRO 103
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
LIBAVCODEC_VERSION_MINOR, \