summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2022-07-11 11:28:39 +0200
committerAnton Khirnov <anton@khirnov.net>2022-08-23 16:47:48 +0200
commit9f10a3b67696bfc5939d3199ca14aee7f5713902 (patch)
tree8d23ade24c8be97f28f807dcb45f3336bef0f783
parentc75152cb3d35032924455febcbea1117991ea7a6 (diff)
lavc/encode: make sure frame timebase matches encoder, when set
AVFrame.time_base has been added recently, but is currently not used for anything. Prepare for its use in encoders by rejecting frames where time_base is set, but differs from the AVCodecContext one.
-rw-r--r--libavcodec/avcodec.h4
-rw-r--r--libavcodec/encode.c8
-rw-r--r--libavutil/frame.h5
3 files changed, 15 insertions, 2 deletions
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 65c8535359..9c246c455c 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -2645,6 +2645,10 @@ int avcodec_receive_frame(AVCodecContext *avctx, AVFrame *frame);
* packets are ignored, and sending frames will return
* AVERROR_EOF.
*
+ * 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.
+ *
* For audio:
* If AV_CODEC_CAP_VARIABLE_FRAME_SIZE is set, then each frame
* can have any number of samples.
diff --git a/libavcodec/encode.c b/libavcodec/encode.c
index bd66f138a3..a774dc28dc 100644
--- a/libavcodec/encode.c
+++ b/libavcodec/encode.c
@@ -361,6 +361,14 @@ static int encode_send_frame_internal(AVCodecContext *avctx, const AVFrame *src)
AVFrame *dst = avci->buffer_frame;
int ret;
+ /* make sure the frame's timebase (if set) matches the encoder one */
+ if (src->time_base.num &&
+ (src->time_base.num != avctx->time_base.num ||
+ src->time_base.den != avctx->time_base.den)) {
+ av_log(avctx, AV_LOG_ERROR, "Mismatching frame/encoder time base\n");
+ return AVERROR(EINVAL);
+ }
+
if (avctx->codec->type == AVMEDIA_TYPE_AUDIO) {
/* extract audio service type metadata */
AVFrameSideData *sd = av_frame_get_side_data(src, AV_FRAME_DATA_AUDIO_SERVICE_TYPE);
diff --git a/libavutil/frame.h b/libavutil/frame.h
index 6d9563bc5d..c5e2de85b3 100644
--- a/libavutil/frame.h
+++ b/libavutil/frame.h
@@ -441,8 +441,9 @@ typedef struct AVFrame {
/**
* Time base for the timestamps in this frame.
* In the future, this field may be set on frames output by decoders or
- * filters, but its value will be by default ignored on input to encoders
- * or filters.
+ * filters; its value will be by default ignored on input to filters.
+ * For frames sent to encoders, it should be set by the user to the same
+ * value as AVCodecContext.time_base.
*/
AVRational time_base;