* [FFmpeg-devel] [PATCH 01/13] lavu/frame: extend AVFrame.repeat_pict documentation
@ 2023-05-07 13:32 Anton Khirnov
2023-05-07 13:32 ` [FFmpeg-devel] [PATCH 02/13] fftools/ffmpeg: fix computing video frame duration from repeat_pict Anton Khirnov
` (12 more replies)
0 siblings, 13 replies; 35+ messages in thread
From: Anton Khirnov @ 2023-05-07 13:32 UTC (permalink / raw)
To: ffmpeg-devel
---
libavutil/frame.h | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)
diff --git a/libavutil/frame.h b/libavutil/frame.h
index f2b56beebb..ed3f199ce1 100644
--- a/libavutil/frame.h
+++ b/libavutil/frame.h
@@ -491,8 +491,22 @@ typedef struct AVFrame {
void *opaque;
/**
- * When decoding, this signals how much the picture must be delayed.
- * extra_delay = repeat_pict / (2*fps)
+ * Number of fields in this frame which should be repeated, i.e. the total
+ * duration of this frame should be repeat_pict + 2 normal field durations.
+ *
+ * For interlaced frames this field may be set to 1, which signals that this
+ * frame should be presented as 3 fields: beginning with the first field (as
+ * determined by AV_FRAME_FLAG_TOP_FIELD_FIRST being set or not), followed
+ * by the second field, and then the first field again.
+ *
+ * For progressive frames this field may be set to a multiple of 2, which
+ * signals that this frame's duration should be (repeat_pict + 2) / 2
+ * normal frame durations.
+ *
+ * @note This field is computed from MPEG2 repeat_first_field flag and its
+ * associated flags, H.264 pic_struct from picture timing SEI, and
+ * their analogues in other codecs. Typically it should only be used when
+ * higher-layer timing information is not available.
*/
int repeat_pict;
--
2.39.2
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 35+ messages in thread
* [FFmpeg-devel] [PATCH 02/13] fftools/ffmpeg: fix computing video frame duration from repeat_pict
2023-05-07 13:32 [FFmpeg-devel] [PATCH 01/13] lavu/frame: extend AVFrame.repeat_pict documentation Anton Khirnov
@ 2023-05-07 13:32 ` Anton Khirnov
2023-05-07 13:32 ` [FFmpeg-devel] [PATCH 03/13] lavc/codec_desc: add a property for codecs that support field coding Anton Khirnov
` (11 subsequent siblings)
12 siblings, 0 replies; 35+ messages in thread
From: Anton Khirnov @ 2023-05-07 13:32 UTC (permalink / raw)
To: ffmpeg-devel
This field contains the number of _field_ durations by which the
standard frame duration should be extended.
---
fftools/ffmpeg.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 8323c32ffd..4e45ab74b9 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1008,10 +1008,10 @@ static int64_t video_duration_estimate(const InputStream *ist, const AVFrame *fr
return frame->duration;
if (ist->dec_ctx->framerate.den && ist->dec_ctx->framerate.num) {
- int ticks = frame->repeat_pict >= 0 ?
- frame->repeat_pict + 1 :
- ist->dec_ctx->ticks_per_frame;
- codec_duration = av_rescale_q(ticks, av_inv_q(ist->dec_ctx->framerate),
+ int fields = frame->repeat_pict + 2;
+ AVRational field_rate = av_mul_q(ist->dec_ctx->framerate,
+ (AVRational){ 2, 1 });
+ codec_duration = av_rescale_q(fields, av_inv_q(field_rate),
ist->st->time_base);
}
--
2.39.2
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 35+ messages in thread
* [FFmpeg-devel] [PATCH 03/13] lavc/codec_desc: add a property for codecs that support field coding
2023-05-07 13:32 [FFmpeg-devel] [PATCH 01/13] lavu/frame: extend AVFrame.repeat_pict documentation Anton Khirnov
2023-05-07 13:32 ` [FFmpeg-devel] [PATCH 02/13] fftools/ffmpeg: fix computing video frame duration from repeat_pict Anton Khirnov
@ 2023-05-07 13:32 ` Anton Khirnov
2023-05-07 13:32 ` [FFmpeg-devel] [PATCH 04/13] lavf: use AV_CODEC_PROP_FIELDS where appropriate Anton Khirnov
` (10 subsequent siblings)
12 siblings, 0 replies; 35+ messages in thread
From: Anton Khirnov @ 2023-05-07 13:32 UTC (permalink / raw)
To: ffmpeg-devel
Multiple places currently use AVCodecContext.ticks_per_frame > 1 to
identify such codecs, which
* requires a codec context
* requires it to be open
---
doc/APIchanges | 3 +++
libavcodec/codec_desc.c | 16 ++++++++++++----
libavcodec/codec_desc.h | 6 ++++++
libavcodec/version.h | 2 +-
4 files changed, 22 insertions(+), 5 deletions(-)
diff --git a/doc/APIchanges b/doc/APIchanges
index fd01def1b2..777485ce86 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -2,6 +2,9 @@ The last version increases of all libraries were on 2023-02-09
API changes, most recent first:
+2023-05-xx - xxxxxxxxxx - lavc 60.11.100 - codec_desc.h
+ Add AV_CODEC_PROP_FIELDS.
+
2023-05-04 - xxxxxxxxxx - lavu 58.7.100 - frame.h
Deprecate AVFrame.interlaced_frame, AVFrame.top_field_first, and
AVFrame.key_frame.
diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c
index d40977d6b3..49dddd1a49 100644
--- a/libavcodec/codec_desc.c
+++ b/libavcodec/codec_desc.c
@@ -38,14 +38,20 @@ static const AVCodecDescriptor codec_descriptors[] = {
.type = AVMEDIA_TYPE_VIDEO,
.name = "mpeg1video",
.long_name = NULL_IF_CONFIG_SMALL("MPEG-1 video"),
- .props = AV_CODEC_PROP_LOSSY | AV_CODEC_PROP_REORDER,
+ .props = AV_CODEC_PROP_LOSSY | AV_CODEC_PROP_REORDER |
+ // FIXME this is strigly speaking not true, as MPEG-1 does
+ // not allow field coding, but our mpeg12 code (decoder and
+ // parser) can sometimes change codec id at runtime, so
+ // this is safer
+ AV_CODEC_PROP_FIELDS,
},
{
.id = AV_CODEC_ID_MPEG2VIDEO,
.type = AVMEDIA_TYPE_VIDEO,
.name = "mpeg2video",
.long_name = NULL_IF_CONFIG_SMALL("MPEG-2 video"),
- .props = AV_CODEC_PROP_LOSSY | AV_CODEC_PROP_REORDER,
+ .props = AV_CODEC_PROP_LOSSY | AV_CODEC_PROP_REORDER |
+ AV_CODEC_PROP_FIELDS,
.profiles = NULL_IF_CONFIG_SMALL(ff_mpeg2_video_profiles),
},
{
@@ -225,7 +231,8 @@ static const AVCodecDescriptor codec_descriptors[] = {
.type = AVMEDIA_TYPE_VIDEO,
.name = "h264",
.long_name = NULL_IF_CONFIG_SMALL("H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10"),
- .props = AV_CODEC_PROP_LOSSY | AV_CODEC_PROP_LOSSLESS | AV_CODEC_PROP_REORDER,
+ .props = AV_CODEC_PROP_LOSSY | AV_CODEC_PROP_LOSSLESS |
+ AV_CODEC_PROP_REORDER | AV_CODEC_PROP_FIELDS,
.profiles = NULL_IF_CONFIG_SMALL(ff_h264_profiles),
},
{
@@ -529,7 +536,8 @@ static const AVCodecDescriptor codec_descriptors[] = {
.type = AVMEDIA_TYPE_VIDEO,
.name = "vc1",
.long_name = NULL_IF_CONFIG_SMALL("SMPTE VC-1"),
- .props = AV_CODEC_PROP_LOSSY | AV_CODEC_PROP_REORDER,
+ .props = AV_CODEC_PROP_LOSSY | AV_CODEC_PROP_REORDER |
+ AV_CODEC_PROP_FIELDS,
.profiles = NULL_IF_CONFIG_SMALL(ff_vc1_profiles),
},
{
diff --git a/libavcodec/codec_desc.h b/libavcodec/codec_desc.h
index 126b52df47..dd4491112b 100644
--- a/libavcodec/codec_desc.h
+++ b/libavcodec/codec_desc.h
@@ -90,6 +90,12 @@ typedef struct AVCodecDescriptor {
* equal.
*/
#define AV_CODEC_PROP_REORDER (1 << 3)
+
+/**
+ * Video codec supports separate coding of fields in interlaced frames.
+ */
+#define AV_CODEC_PROP_FIELDS (1 << 4)
+
/**
* Subtitle codec is bitmap based
* Decoded AVSubtitle data can be read from the AVSubtitleRect->pict field.
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 80e2ae630d..8b53586be1 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -29,7 +29,7 @@
#include "version_major.h"
-#define LIBAVCODEC_VERSION_MINOR 10
+#define LIBAVCODEC_VERSION_MINOR 11
#define LIBAVCODEC_VERSION_MICRO 100
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
--
2.39.2
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 35+ messages in thread
* [FFmpeg-devel] [PATCH 04/13] lavf: use AV_CODEC_PROP_FIELDS where appropriate
2023-05-07 13:32 [FFmpeg-devel] [PATCH 01/13] lavu/frame: extend AVFrame.repeat_pict documentation Anton Khirnov
2023-05-07 13:32 ` [FFmpeg-devel] [PATCH 02/13] fftools/ffmpeg: fix computing video frame duration from repeat_pict Anton Khirnov
2023-05-07 13:32 ` [FFmpeg-devel] [PATCH 03/13] lavc/codec_desc: add a property for codecs that support field coding Anton Khirnov
@ 2023-05-07 13:32 ` Anton Khirnov
2023-05-08 14:12 ` Michael Niedermayer
2023-05-08 14:15 ` [FFmpeg-devel] [PATCH " Michael Niedermayer
2023-05-07 13:32 ` [FFmpeg-devel] [PATCH 05/13] lavc/av1*: fix exporting framerate Anton Khirnov
` (9 subsequent siblings)
12 siblings, 2 replies; 35+ messages in thread
From: Anton Khirnov @ 2023-05-07 13:32 UTC (permalink / raw)
To: ffmpeg-devel
H.264 and mpeg12 parsers need to be adjusted at the same time to stop
using the value of AVCodecContext.ticks_per_frame, because it is not set
correctly unless the codec has been opened. Previously this would result
in both the parser and lavf seeing the same incorrect value, which would
cancel out.
Updating lavf and not the parsers would result in correct value in lavf,
but the wrong one in parsers, which would break some tests.
---
libavcodec/h264_parser.c | 4 ++--
libavcodec/mpegvideo_parser.c | 2 +-
libavformat/avformat.c | 9 ++++++---
libavformat/demux.c | 29 +++++++++++++++++++----------
libavformat/internal.h | 3 +++
5 files changed, 31 insertions(+), 16 deletions(-)
diff --git a/libavcodec/h264_parser.c b/libavcodec/h264_parser.c
index 46134a1c48..43abc45f9c 100644
--- a/libavcodec/h264_parser.c
+++ b/libavcodec/h264_parser.c
@@ -568,7 +568,7 @@ static inline int parse_nal_units(AVCodecParserContext *s,
if (p->sei.common.unregistered.x264_build < 44U)
den *= 2;
av_reduce(&avctx->framerate.den, &avctx->framerate.num,
- sps->num_units_in_tick * avctx->ticks_per_frame, den, 1 << 30);
+ sps->num_units_in_tick * 2, den, 1 << 30);
}
av_freep(&rbsp.rbsp_buffer);
@@ -625,7 +625,7 @@ static int h264_parse(AVCodecParserContext *s,
parse_nal_units(s, avctx, buf, buf_size);
if (avctx->framerate.num)
- time_base = av_inv_q(av_mul_q(avctx->framerate, (AVRational){avctx->ticks_per_frame, 1}));
+ time_base = av_inv_q(av_mul_q(avctx->framerate, (AVRational){2, 1}));
if (p->sei.picture_timing.cpb_removal_delay >= 0) {
s->dts_sync_point = p->sei.buffering_period.present;
s->dts_ref_dts_delta = p->sei.picture_timing.cpb_removal_delay;
diff --git a/libavcodec/mpegvideo_parser.c b/libavcodec/mpegvideo_parser.c
index 8e7e88ff25..08e5316960 100644
--- a/libavcodec/mpegvideo_parser.c
+++ b/libavcodec/mpegvideo_parser.c
@@ -129,6 +129,7 @@ static void mpegvideo_extract_headers(AVCodecParserContext *s,
s->pict_type = (buf[1] >> 3) & 7;
if (bytes_left >= 4)
vbv_delay = ((buf[1] & 0x07) << 13) | (buf[2] << 5) | (buf[3] >> 3);
+ s->repeat_pict = 1;
}
break;
case SEQ_START_CODE:
@@ -186,7 +187,6 @@ static void mpegvideo_extract_headers(AVCodecParserContext *s,
progressive_frame = buf[4] & (1 << 7);
/* check if we must repeat the frame */
- s->repeat_pict = 1;
if (repeat_first_field) {
if (pc->progressive_sequence) {
if (top_field_first)
diff --git a/libavformat/avformat.c b/libavformat/avformat.c
index 708d90b38c..fea905693d 100644
--- a/libavformat/avformat.c
+++ b/libavformat/avformat.c
@@ -679,6 +679,7 @@ AVRational av_guess_sample_aspect_ratio(AVFormatContext *format, AVStream *strea
AVRational av_guess_frame_rate(AVFormatContext *format, AVStream *st, AVFrame *frame)
{
AVRational fr = st->r_frame_rate;
+ const AVCodecDescriptor *desc = cffstream(st)->codec_desc;
AVCodecContext *const avctx = ffstream(st)->avctx;
AVRational codec_fr = avctx->framerate;
AVRational avg_fr = st->avg_frame_rate;
@@ -688,7 +689,7 @@ AVRational av_guess_frame_rate(AVFormatContext *format, AVStream *st, AVFrame *f
fr = avg_fr;
}
- if (avctx->ticks_per_frame > 1) {
+ if (desc && (desc->props & AV_CODEC_PROP_FIELDS)) {
if ( codec_fr.num > 0 && codec_fr.den > 0 &&
(fr.num == 0 || av_q2d(codec_fr) < av_q2d(fr)*0.7 && fabs(1.0 - av_q2d(av_div_q(avg_fr, fr))) > 0.1))
fr = codec_fr;
@@ -701,10 +702,12 @@ int avformat_transfer_internal_stream_timing_info(const AVOutputFormat *ofmt,
AVStream *ost, const AVStream *ist,
enum AVTimebaseSource copy_tb)
{
+ const AVCodecDescriptor *desc = cffstream(ist)->codec_desc;
const AVCodecContext *const dec_ctx = cffstream(ist)->avctx;
AVCodecContext *const enc_ctx = ffstream(ost)->avctx;
- AVRational dec_ctx_tb = dec_ctx->framerate.num ? av_inv_q(av_mul_q(dec_ctx->framerate,
- (AVRational){dec_ctx->ticks_per_frame, 1}))
+
+ AVRational mul = (AVRational){ desc && (desc->props & AV_CODEC_PROP_FIELDS) ? 2 : 1, 1 };
+ AVRational dec_ctx_tb = dec_ctx->framerate.num ? av_inv_q(av_mul_q(dec_ctx->framerate, mul))
: (ist->codecpar->codec_type == AVMEDIA_TYPE_AUDIO ? (AVRational){0, 1}
: ist->time_base);
diff --git a/libavformat/demux.c b/libavformat/demux.c
index 45e5f5c4c2..1e47cd2bba 100644
--- a/libavformat/demux.c
+++ b/libavformat/demux.c
@@ -213,6 +213,8 @@ FF_ENABLE_DEPRECATION_WARNINGS
if (ret < 0)
return ret;
+ sti->codec_desc = avcodec_descriptor_get(sti->avctx->codec_id);
+
sti->need_context_update = 0;
}
return 0;
@@ -677,10 +679,11 @@ static void compute_frame_duration(AVFormatContext *s, int *pnum, int *pden,
*pnum = st->time_base.num;
*pden = st->time_base.den;
} else if (codec_framerate.den * 1000LL > codec_framerate.num) {
- av_assert0(sti->avctx->ticks_per_frame);
+ int ticks_per_frame = (sti->codec_desc &&
+ (sti->codec_desc->props & AV_CODEC_PROP_FIELDS)) ? 2 : 1;
av_reduce(pnum, pden,
codec_framerate.den,
- codec_framerate.num * (int64_t)sti->avctx->ticks_per_frame,
+ codec_framerate.num * (int64_t)ticks_per_frame,
INT_MAX);
if (pc && pc->repeat_pict) {
@@ -692,7 +695,8 @@ static void compute_frame_duration(AVFormatContext *s, int *pnum, int *pden,
/* If this codec can be interlaced or progressive then we need
* a parser to compute duration of a packet. Thus if we have
* no parser in such case leave duration undefined. */
- if (sti->avctx->ticks_per_frame > 1 && !pc)
+ if (sti->codec_desc &&
+ (sti->codec_desc->props & AV_CODEC_PROP_FIELDS) && !pc)
*pnum = *pden = 0;
}
break;
@@ -1288,6 +1292,8 @@ static int read_frame_internal(AVFormatContext *s, AVPacket *pkt)
return ret;
}
+ sti->codec_desc = avcodec_descriptor_get(sti->avctx->codec_id);
+
sti->need_context_update = 0;
}
@@ -2164,9 +2170,10 @@ static int get_std_framerate(int i)
static int tb_unreliable(AVFormatContext *ic, AVStream *st)
{
FFStream *const sti = ffstream(st);
+ const AVCodecDescriptor *desc = sti->codec_desc;
AVCodecContext *c = sti->avctx;
- AVRational time_base = c->framerate.num ? av_inv_q(av_mul_q(c->framerate,
- (AVRational){c->ticks_per_frame, 1}))
+ AVRational mul = (AVRational){ desc && (desc->props & AV_CODEC_PROP_FIELDS) ? 2 : 1, 1 };
+ AVRational time_base = c->framerate.num ? av_inv_q(av_mul_q(c->framerate, mul))
/* NOHEADER check added to not break existing behavior */
: (((ic->ctx_flags & AVFMTCTX_NOHEADER) ||
st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) ? (AVRational){0, 1}
@@ -2718,13 +2725,14 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
break;
}
if (pkt->duration > 0) {
+ const int fields = sti->codec_desc && (sti->codec_desc->props & AV_CODEC_PROP_FIELDS);
if (avctx->codec_type == AVMEDIA_TYPE_SUBTITLE && pkt->pts != AV_NOPTS_VALUE && st->start_time != AV_NOPTS_VALUE && pkt->pts >= st->start_time
&& (uint64_t)pkt->pts - st->start_time < INT64_MAX
) {
sti->info->codec_info_duration = FFMIN(pkt->pts - st->start_time, sti->info->codec_info_duration + pkt->duration);
} else
sti->info->codec_info_duration += pkt->duration;
- sti->info->codec_info_duration_fields += sti->parser && sti->need_parsing && avctx->ticks_per_frame == 2
+ sti->info->codec_info_duration_fields += sti->parser && sti->need_parsing && fields
? sti->parser->repeat_pict + 1 : 2;
}
}
@@ -2864,15 +2872,16 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
best_fps, 12 * 1001, INT_MAX);
}
if (!st->r_frame_rate.num) {
- AVRational time_base = avctx->framerate.num ? av_inv_q(av_mul_q(avctx->framerate,
- (AVRational){avctx->ticks_per_frame, 1}))
+ const AVCodecDescriptor *desc = sti->codec_desc;
+ AVRational mul = (AVRational){ desc && (desc->props & AV_CODEC_PROP_FIELDS) ? 2 : 1, 1 };
+ AVRational time_base = avctx->framerate.num ? av_inv_q(av_mul_q(avctx->framerate, mul))
/* NOHEADER check added to not break existing behavior */
: ((ic->ctx_flags & AVFMTCTX_NOHEADER) ? (AVRational){0, 1}
: st->time_base);
if ( time_base.den * (int64_t) st->time_base.num
- <= time_base.num * (uint64_t)avctx->ticks_per_frame * st->time_base.den) {
+ <= time_base.num * (uint64_t)mul.num * st->time_base.den) {
av_reduce(&st->r_frame_rate.num, &st->r_frame_rate.den,
- time_base.den, (int64_t)time_base.num * avctx->ticks_per_frame, INT_MAX);
+ time_base.den, (int64_t)time_base.num * mul.num, INT_MAX);
} else {
st->r_frame_rate.num = st->time_base.den;
st->r_frame_rate.den = st->time_base.num;
diff --git a/libavformat/internal.h b/libavformat/internal.h
index f575064e8f..40c46311c8 100644
--- a/libavformat/internal.h
+++ b/libavformat/internal.h
@@ -23,6 +23,7 @@
#include <stdint.h>
+#include "libavcodec/codec_desc.h"
#include "libavcodec/packet_internal.h"
#include "avformat.h"
@@ -408,6 +409,8 @@ typedef struct FFStream {
*/
int64_t first_dts;
int64_t cur_dts;
+
+ const AVCodecDescriptor *codec_desc;
} FFStream;
static av_always_inline FFStream *ffstream(AVStream *st)
--
2.39.2
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 35+ messages in thread
* [FFmpeg-devel] [PATCH 05/13] lavc/av1*: fix exporting framerate
2023-05-07 13:32 [FFmpeg-devel] [PATCH 01/13] lavu/frame: extend AVFrame.repeat_pict documentation Anton Khirnov
` (2 preceding siblings ...)
2023-05-07 13:32 ` [FFmpeg-devel] [PATCH 04/13] lavf: use AV_CODEC_PROP_FIELDS where appropriate Anton Khirnov
@ 2023-05-07 13:32 ` Anton Khirnov
2023-05-10 11:52 ` James Almer
2023-05-07 13:32 ` [FFmpeg-devel] [PATCH 06/13] lavc/libdav1d: " Anton Khirnov
` (8 subsequent siblings)
12 siblings, 1 reply; 35+ messages in thread
From: Anton Khirnov @ 2023-05-07 13:32 UTC (permalink / raw)
To: ffmpeg-devel
* take num_ticks_per_picture_minus_1 into account, since that is a part
of the framerate computation
* stop exporting num_ticks_per_picture_minus_1 into
AVCodecContext.ticks_per_frame, as that field is used for other
purposes (in conjunction with repeat_pict, which is not used at all by
av1)
---
libavcodec/Makefile | 2 +-
libavcodec/av1_parse.c | 15 +++++++++++++++
libavcodec/av1_parse.h | 4 ++++
libavcodec/av1_parser.c | 9 ++++-----
libavcodec/av1dec.c | 12 +++---------
5 files changed, 27 insertions(+), 15 deletions(-)
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index b0971ce833..8162bcf4fa 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1143,7 +1143,7 @@ OBJS-$(CONFIG_AC3_PARSER) += aac_ac3_parser.o ac3tab.o \
ac3_channel_layout_tab.o
OBJS-$(CONFIG_ADX_PARSER) += adx_parser.o
OBJS-$(CONFIG_AMR_PARSER) += amr_parser.o
-OBJS-$(CONFIG_AV1_PARSER) += av1_parser.o
+OBJS-$(CONFIG_AV1_PARSER) += av1_parser.o av1_parse.o
OBJS-$(CONFIG_AVS2_PARSER) += avs2.o avs2_parser.o
OBJS-$(CONFIG_AVS3_PARSER) += avs3_parser.o
OBJS-$(CONFIG_BMP_PARSER) += bmp_parser.o
diff --git a/libavcodec/av1_parse.c b/libavcodec/av1_parse.c
index 59ea0bc6e7..cf325e09b9 100644
--- a/libavcodec/av1_parse.c
+++ b/libavcodec/av1_parse.c
@@ -24,6 +24,7 @@
#include "av1.h"
#include "av1_parse.h"
+#include "cbs_av1.h"
#include "bytestream.h"
int ff_av1_extract_obu(AV1OBU *obu, const uint8_t *buf, int length, void *logctx)
@@ -108,3 +109,17 @@ void ff_av1_packet_uninit(AV1Packet *pkt)
av_freep(&pkt->obus);
pkt->obus_allocated = pkt->obus_allocated_size = 0;
}
+
+AVRational ff_av1_framerate(const AV1RawTimingInfo *ti)
+{
+ const int ticks = ti->num_ticks_per_picture_minus_1 + 1;
+ AVRational fr = (AVRational){ 0, 1 };
+
+ if (ti->num_units_in_display_tick && ti->time_scale &&
+ ticks < INT_MAX / ti->num_units_in_display_tick) {
+ av_reduce(&fr.den, &fr.num, ti->num_units_in_display_tick * ticks,
+ ti->time_scale, INT_MAX);
+ }
+
+ return fr;
+}
diff --git a/libavcodec/av1_parse.h b/libavcodec/av1_parse.h
index f4a5d2830e..60a6fd0ba2 100644
--- a/libavcodec/av1_parse.h
+++ b/libavcodec/av1_parse.h
@@ -181,4 +181,8 @@ static inline int get_obu_bit_length(const uint8_t *buf, int size, int type)
return size;
}
+struct AV1RawTimingInfo;
+
+AVRational ff_av1_framerate(const struct AV1RawTimingInfo *ti);
+
#endif /* AVCODEC_AV1_PARSE_H */
diff --git a/libavcodec/av1_parser.c b/libavcodec/av1_parser.c
index 14dae92fe9..978bbebe30 100644
--- a/libavcodec/av1_parser.c
+++ b/libavcodec/av1_parser.c
@@ -21,6 +21,8 @@
*/
#include "libavutil/avassert.h"
+
+#include "av1_parse.h"
#include "cbs.h"
#include "cbs_av1.h"
#include "parser.h"
@@ -162,11 +164,8 @@ static int av1_parser_parse(AVCodecParserContext *ctx,
avctx->color_trc = (enum AVColorTransferCharacteristic) color->transfer_characteristics;
avctx->color_range = color->color_range ? AVCOL_RANGE_JPEG : AVCOL_RANGE_MPEG;
- if (seq->timing_info_present_flag) {
- const AV1RawTimingInfo *timing = &seq->timing_info;
- av_reduce(&avctx->framerate.den, &avctx->framerate.num,
- timing->num_units_in_display_tick, timing->time_scale, INT_MAX);
- }
+ if (seq->timing_info_present_flag)
+ avctx->framerate = ff_av1_framerate(&seq->timing_info);
end:
ff_cbs_fragment_reset(td);
diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c
index c90c9c1a69..693673b436 100644
--- a/libavcodec/av1dec.c
+++ b/libavcodec/av1dec.c
@@ -26,6 +26,7 @@
#include "libavutil/pixdesc.h"
#include "libavutil/opt.h"
#include "avcodec.h"
+#include "av1_parse.h"
#include "av1dec.h"
#include "atsc_a53.h"
#include "bytestream.h"
@@ -709,15 +710,8 @@ static int set_context_with_sequence(AVCodecContext *avctx,
}
avctx->sample_aspect_ratio = (AVRational) { 1, 1 };
- if (seq->timing_info.num_units_in_display_tick &&
- seq->timing_info.time_scale) {
- av_reduce(&avctx->framerate.den, &avctx->framerate.num,
- seq->timing_info.num_units_in_display_tick,
- seq->timing_info.time_scale,
- INT_MAX);
- if (seq->timing_info.equal_picture_interval)
- avctx->ticks_per_frame = seq->timing_info.num_ticks_per_picture_minus_1 + 1;
- }
+ if (seq->timing_info_present_flag)
+ avctx->framerate = ff_av1_framerate(&seq->timing_info);
return 0;
}
--
2.39.2
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 35+ messages in thread
* [FFmpeg-devel] [PATCH 06/13] lavc/libdav1d: fix exporting framerate
2023-05-07 13:32 [FFmpeg-devel] [PATCH 01/13] lavu/frame: extend AVFrame.repeat_pict documentation Anton Khirnov
` (3 preceding siblings ...)
2023-05-07 13:32 ` [FFmpeg-devel] [PATCH 05/13] lavc/av1*: fix exporting framerate Anton Khirnov
@ 2023-05-07 13:32 ` Anton Khirnov
2023-05-15 8:22 ` [FFmpeg-devel] [PATCH] " Anton Khirnov
2023-05-07 13:32 ` [FFmpeg-devel] [PATCH 07/13] lavc/ratecontrol: use AVCodecContext.framerate when available Anton Khirnov
` (7 subsequent siblings)
12 siblings, 1 reply; 35+ messages in thread
From: Anton Khirnov @ 2023-05-07 13:32 UTC (permalink / raw)
To: ffmpeg-devel
Same issues as in the previous commit.
---
libavcodec/libdav1d.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/libavcodec/libdav1d.c b/libavcodec/libdav1d.c
index 87aed16749..19b6a880da 100644
--- a/libavcodec/libdav1d.c
+++ b/libavcodec/libdav1d.c
@@ -154,11 +154,11 @@ static void libdav1d_init_params(AVCodecContext *c, const Dav1dSequenceHeader *s
else
c->pix_fmt = pix_fmt[seq->layout][seq->hbd];
- if (seq->num_units_in_tick && seq->time_scale) {
+ if (seq->num_units_in_tick && seq->time_scale &&
+ seq->num_ticks_per_picture < INT_MAX / seq->num_units_in_tick) {
av_reduce(&c->framerate.den, &c->framerate.num,
- seq->num_units_in_tick, seq->time_scale, INT_MAX);
- if (seq->equal_picture_interval)
- c->ticks_per_frame = seq->num_ticks_per_picture;
+ seq->num_units_in_tick * FFMAX(seq->num_ticks_per_picture, 1),
+ seq->time_scale, INT_MAX);
}
if (seq->film_grain_present)
--
2.39.2
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 35+ messages in thread
* [FFmpeg-devel] [PATCH 07/13] lavc/ratecontrol: use AVCodecContext.framerate when available
2023-05-07 13:32 [FFmpeg-devel] [PATCH 01/13] lavu/frame: extend AVFrame.repeat_pict documentation Anton Khirnov
` (4 preceding siblings ...)
2023-05-07 13:32 ` [FFmpeg-devel] [PATCH 06/13] lavc/libdav1d: " Anton Khirnov
@ 2023-05-07 13:32 ` Anton Khirnov
2023-05-07 13:32 ` [FFmpeg-devel] [PATCH 08/13] lavc/msmpeg4enc: " Anton Khirnov
` (6 subsequent siblings)
12 siblings, 0 replies; 35+ messages in thread
From: Anton Khirnov @ 2023-05-07 13:32 UTC (permalink / raw)
To: ffmpeg-devel
---
libavcodec/ratecontrol.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/libavcodec/ratecontrol.c b/libavcodec/ratecontrol.c
index 6a40f9cbdc..890ae33cb3 100644
--- a/libavcodec/ratecontrol.c
+++ b/libavcodec/ratecontrol.c
@@ -57,6 +57,9 @@ void ff_write_pass1_stats(MpegEncContext *s)
static double get_fps(AVCodecContext *avctx)
{
+ if (avctx->framerate.num > 0 && avctx->framerate.den > 0)
+ return av_q2d(avctx->framerate);
+
return 1.0 / av_q2d(avctx->time_base) / FFMAX(avctx->ticks_per_frame, 1);
}
--
2.39.2
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 35+ messages in thread
* [FFmpeg-devel] [PATCH 08/13] lavc/msmpeg4enc: use AVCodecContext.framerate when available
2023-05-07 13:32 [FFmpeg-devel] [PATCH 01/13] lavu/frame: extend AVFrame.repeat_pict documentation Anton Khirnov
` (5 preceding siblings ...)
2023-05-07 13:32 ` [FFmpeg-devel] [PATCH 07/13] lavc/ratecontrol: use AVCodecContext.framerate when available Anton Khirnov
@ 2023-05-07 13:32 ` Anton Khirnov
2023-05-07 13:32 ` [FFmpeg-devel] [PATCH 09/13] libaomenc: " Anton Khirnov
` (5 subsequent siblings)
12 siblings, 0 replies; 35+ messages in thread
From: Anton Khirnov @ 2023-05-07 13:32 UTC (permalink / raw)
To: ffmpeg-devel
---
libavcodec/msmpeg4enc.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/libavcodec/msmpeg4enc.c b/libavcodec/msmpeg4enc.c
index 54121438a0..df190d376c 100644
--- a/libavcodec/msmpeg4enc.c
+++ b/libavcodec/msmpeg4enc.c
@@ -280,7 +280,13 @@ void ff_msmpeg4_encode_picture_header(MpegEncContext * s)
void ff_msmpeg4_encode_ext_header(MpegEncContext * s)
{
- unsigned fps = s->avctx->time_base.den / s->avctx->time_base.num / FFMAX(s->avctx->ticks_per_frame, 1);
+ unsigned fps;
+
+ if (s->avctx->framerate.num > 0 && s->avctx->framerate.den > 0)
+ fps = s->avctx->framerate.num / s->avctx->framerate.den;
+ else
+ fps = s->avctx->time_base.den / s->avctx->time_base.num / FFMAX(s->avctx->ticks_per_frame, 1);
+
put_bits(&s->pb, 5, FFMIN(fps, 31)); //yes 29.97 -> 29
put_bits(&s->pb, 11, FFMIN(s->bit_rate / 1024, 2047));
--
2.39.2
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 35+ messages in thread
* [FFmpeg-devel] [PATCH 09/13] libaomenc: use AVCodecContext.framerate when available
2023-05-07 13:32 [FFmpeg-devel] [PATCH 01/13] lavu/frame: extend AVFrame.repeat_pict documentation Anton Khirnov
` (6 preceding siblings ...)
2023-05-07 13:32 ` [FFmpeg-devel] [PATCH 08/13] lavc/msmpeg4enc: " Anton Khirnov
@ 2023-05-07 13:32 ` Anton Khirnov
2023-05-07 13:32 ` [FFmpeg-devel] [PATCH 10/13] lavc/libkvazaar, libopenh264enc: drop redundant checks Anton Khirnov
` (4 subsequent siblings)
12 siblings, 0 replies; 35+ messages in thread
From: Anton Khirnov @ 2023-05-07 13:32 UTC (permalink / raw)
To: ffmpeg-devel
---
libavcodec/libaomenc.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
index 0b88102c77..1d3a4ae64c 100644
--- a/libavcodec/libaomenc.c
+++ b/libavcodec/libaomenc.c
@@ -1295,8 +1295,12 @@ static int aom_encode(AVCodecContext *avctx, AVPacket *pkt,
if (frame->duration > ULONG_MAX) {
av_log(avctx, AV_LOG_WARNING,
"Frame duration too large: %"PRId64"\n", frame->duration);
- } else
- duration = frame->duration ? frame->duration : avctx->ticks_per_frame;
+ } else if (frame->duration)
+ duration = frame->duration;
+ else if (avctx->framerate.num > 0 && avctx->framerate.den > 0)
+ duration = av_rescale_q(1, av_inv_q(avctx->framerate), avctx->time_base);
+ else
+ duration = avctx->ticks_per_frame ? avctx->ticks_per_frame : 1;
switch (frame->color_range) {
case AVCOL_RANGE_MPEG:
--
2.39.2
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 35+ messages in thread
* [FFmpeg-devel] [PATCH 10/13] lavc/libkvazaar, libopenh264enc: drop redundant checks
2023-05-07 13:32 [FFmpeg-devel] [PATCH 01/13] lavu/frame: extend AVFrame.repeat_pict documentation Anton Khirnov
` (7 preceding siblings ...)
2023-05-07 13:32 ` [FFmpeg-devel] [PATCH 09/13] libaomenc: " Anton Khirnov
@ 2023-05-07 13:32 ` Anton Khirnov
2023-05-07 13:32 ` [FFmpeg-devel] [PATCH 11/13] lavc/libvpxenc: send frame durations to the encoder Anton Khirnov
` (3 subsequent siblings)
12 siblings, 0 replies; 35+ messages in thread
From: Anton Khirnov @ 2023-05-07 13:32 UTC (permalink / raw)
To: ffmpeg-devel
The same check is present in encode_preinit_video().
---
libavcodec/libkvazaar.c | 5 -----
libavcodec/libopenh264enc.c | 5 -----
2 files changed, 10 deletions(-)
diff --git a/libavcodec/libkvazaar.c b/libavcodec/libkvazaar.c
index 168486f4ec..b3faa0a64b 100644
--- a/libavcodec/libkvazaar.c
+++ b/libavcodec/libkvazaar.c
@@ -85,11 +85,6 @@ static av_cold int libkvazaar_init(AVCodecContext *avctx)
cfg->framerate_num = avctx->framerate.num;
cfg->framerate_denom = avctx->framerate.den;
} else {
- if (avctx->ticks_per_frame > INT_MAX / avctx->time_base.num) {
- av_log(avctx, AV_LOG_ERROR,
- "Could not set framerate for kvazaar: integer overflow\n");
- return AVERROR(EINVAL);
- }
cfg->framerate_num = avctx->time_base.den;
cfg->framerate_denom = avctx->time_base.num * avctx->ticks_per_frame;
}
diff --git a/libavcodec/libopenh264enc.c b/libavcodec/libopenh264enc.c
index 3c605fe8ea..15c3822824 100644
--- a/libavcodec/libopenh264enc.c
+++ b/libavcodec/libopenh264enc.c
@@ -139,11 +139,6 @@ static av_cold int svc_encode_init(AVCodecContext *avctx)
if (avctx->framerate.num > 0 && avctx->framerate.den > 0) {
param.fMaxFrameRate = av_q2d(avctx->framerate);
} else {
- if (avctx->ticks_per_frame > INT_MAX / avctx->time_base.num) {
- av_log(avctx, AV_LOG_ERROR,
- "Could not set framerate for libopenh264enc: integer overflow\n");
- return AVERROR(EINVAL);
- }
param.fMaxFrameRate = 1.0 / av_q2d(avctx->time_base) / FFMAX(avctx->ticks_per_frame, 1);
}
param.iPicWidth = avctx->width;
--
2.39.2
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 35+ messages in thread
* [FFmpeg-devel] [PATCH 11/13] lavc/libvpxenc: send frame durations to the encoder
2023-05-07 13:32 [FFmpeg-devel] [PATCH 01/13] lavu/frame: extend AVFrame.repeat_pict documentation Anton Khirnov
` (8 preceding siblings ...)
2023-05-07 13:32 ` [FFmpeg-devel] [PATCH 10/13] lavc/libkvazaar, libopenh264enc: drop redundant checks Anton Khirnov
@ 2023-05-07 13:32 ` Anton Khirnov
2023-05-09 1:18 ` James Zern
2023-05-07 13:32 ` [FFmpeg-devel] [PATCH 12/13] lavc: deprecate AVCodecContext.ticks_per_frame Anton Khirnov
` (2 subsequent siblings)
12 siblings, 1 reply; 35+ messages in thread
From: Anton Khirnov @ 2023-05-07 13:32 UTC (permalink / raw)
To: ffmpeg-devel
Adapt similar code from libaomenc - stop using ticks_per_frame except as
a last resort.
---
libavcodec/libvpxenc.c | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
index a20e949842..a89497665b 100644
--- a/libavcodec/libvpxenc.c
+++ b/libavcodec/libvpxenc.c
@@ -1692,6 +1692,7 @@ static int vpx_encode(AVCodecContext *avctx, AVPacket *pkt,
const struct vpx_codec_enc_cfg *enccfg = ctx->encoder.config.enc;
vpx_svc_layer_id_t layer_id;
int layer_id_valid = 0;
+ unsigned long duration;
if (avctx->qmax >= 0 && enccfg->rc_max_quantizer != avctx->qmax) {
struct vpx_codec_enc_cfg cfg = *enccfg;
@@ -1820,8 +1821,18 @@ static int vpx_encode(AVCodecContext *avctx, AVPacket *pkt,
#endif
}
+ if (frame && frame->duration > ULONG_MAX) {
+ av_log(avctx, AV_LOG_WARNING,
+ "Frame duration too large: %"PRId64"\n", frame->duration);
+ } else if (frame && frame->duration)
+ duration = frame->duration;
+ else if (avctx->framerate.num > 0 && avctx->framerate.den > 0)
+ duration = av_rescale_q(1, av_inv_q(avctx->framerate), avctx->time_base);
+ else
+ duration = avctx->ticks_per_frame ? avctx->ticks_per_frame : 1;
+
res = vpx_codec_encode(&ctx->encoder, rawimg, timestamp,
- avctx->ticks_per_frame, flags, ctx->deadline);
+ duration, flags, ctx->deadline);
if (res != VPX_CODEC_OK) {
log_encoder_error(avctx, "Error encoding frame");
return AVERROR_INVALIDDATA;
@@ -1829,7 +1840,7 @@ static int vpx_encode(AVCodecContext *avctx, AVPacket *pkt,
if (ctx->is_alpha) {
res = vpx_codec_encode(&ctx->encoder_alpha, rawimg_alpha, timestamp,
- avctx->ticks_per_frame, flags, ctx->deadline);
+ duration, flags, ctx->deadline);
if (res != VPX_CODEC_OK) {
log_encoder_error(avctx, "Error encoding alpha frame");
return AVERROR_INVALIDDATA;
--
2.39.2
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 35+ messages in thread
* [FFmpeg-devel] [PATCH 12/13] lavc: deprecate AVCodecContext.ticks_per_frame
2023-05-07 13:32 [FFmpeg-devel] [PATCH 01/13] lavu/frame: extend AVFrame.repeat_pict documentation Anton Khirnov
` (9 preceding siblings ...)
2023-05-07 13:32 ` [FFmpeg-devel] [PATCH 11/13] lavc/libvpxenc: send frame durations to the encoder Anton Khirnov
@ 2023-05-07 13:32 ` Anton Khirnov
2023-05-07 13:32 ` [FFmpeg-devel] [PATCH 13/13] fftools/ffmpeg: stop using deprecated ticks_per_frame Anton Khirnov
2023-05-07 16:59 ` [FFmpeg-devel] [PATCH 01/13] lavu/frame: extend AVFrame.repeat_pict documentation Kieran Kunhya
12 siblings, 0 replies; 35+ messages in thread
From: Anton Khirnov @ 2023-05-07 13:32 UTC (permalink / raw)
To: ffmpeg-devel
For encoding, this field is entirely redundant with
AVCodecContext.framerate.
For decoding, this field is entirely redundant with
AV_CODEC_PROP_FIELDS.
---
doc/codecs.texi | 1 -
libavcodec/amfenc_av1.c | 8 +++++++-
libavcodec/amfenc_h264.c | 8 +++++++-
libavcodec/amfenc_hevc.c | 8 +++++++-
libavcodec/avcodec.h | 8 ++++++++
libavcodec/encode.c | 4 ++++
libavcodec/h264_slice.c | 2 +-
libavcodec/h264dec.c | 4 ++++
libavcodec/libaomenc.c | 8 +++++++-
libavcodec/libkvazaar.c | 8 +++++++-
libavcodec/libopenh264enc.c | 8 +++++++-
libavcodec/librav1e.c | 9 +++++++--
libavcodec/libsvtav1.c | 8 +++++++-
libavcodec/libvpxenc.c | 8 +++++++-
libavcodec/libx264.c | 8 +++++++-
libavcodec/libx265.c | 8 +++++++-
libavcodec/mfenc.c | 4 ++++
libavcodec/mpeg12dec.c | 8 ++++++++
libavcodec/mpegvideo_parser.c | 8 ++++++++
libavcodec/msmpeg4enc.c | 8 +++++++-
libavcodec/nvenc.c | 16 ++++++++++++++--
libavcodec/options_table.h | 2 ++
libavcodec/pthread_frame.c | 4 ++++
libavcodec/ratecontrol.c | 8 +++++++-
libavcodec/vc1.c | 11 ++++++++---
libavcodec/vc1_parser.c | 3 +--
libavcodec/vc1dec.c | 1 -
libavcodec/version_major.h | 1 +
libavformat/avformat.c | 15 +++++++++++++--
29 files changed, 171 insertions(+), 26 deletions(-)
diff --git a/doc/codecs.texi b/doc/codecs.texi
index 1adacd2b59..f903dad754 100644
--- a/doc/codecs.texi
+++ b/doc/codecs.texi
@@ -775,7 +775,6 @@ Possible values:
@end table
@item rc_max_vbv_use @var{float} (@emph{encoding,video})
@item rc_min_vbv_use @var{float} (@emph{encoding,video})
-@item ticks_per_frame @var{integer} (@emph{decoding/encoding,audio,video})
@item color_primaries @var{integer} (@emph{decoding/encoding,video})
Possible values:
diff --git a/libavcodec/amfenc_av1.c b/libavcodec/amfenc_av1.c
index 8093cb7357..ad09b7910a 100644
--- a/libavcodec/amfenc_av1.c
+++ b/libavcodec/amfenc_av1.c
@@ -117,7 +117,13 @@ static av_cold int amf_encode_init_av1(AVCodecContext* avctx)
framerate = AMFConstructRate(avctx->framerate.num, avctx->framerate.den);
}
else {
- framerate = AMFConstructRate(avctx->time_base.den, avctx->time_base.num * avctx->ticks_per_frame);
+FF_DISABLE_DEPRECATION_WARNINGS
+ framerate = AMFConstructRate(avctx->time_base.den, avctx->time_base.num
+#if FF_API_TICKS_PER_FRAME
+ * avctx->ticks_per_frame
+#endif
+ );
+FF_ENABLE_DEPRECATION_WARNINGS
}
if ((ret = ff_amf_encode_init(avctx)) < 0)
diff --git a/libavcodec/amfenc_h264.c b/libavcodec/amfenc_h264.c
index eaf7f974f3..d2fc33971b 100644
--- a/libavcodec/amfenc_h264.c
+++ b/libavcodec/amfenc_h264.c
@@ -142,7 +142,13 @@ static av_cold int amf_encode_init_h264(AVCodecContext *avctx)
if (avctx->framerate.num > 0 && avctx->framerate.den > 0) {
framerate = AMFConstructRate(avctx->framerate.num, avctx->framerate.den);
} else {
- framerate = AMFConstructRate(avctx->time_base.den, avctx->time_base.num * avctx->ticks_per_frame);
+FF_DISABLE_DEPRECATION_WARNINGS
+ framerate = AMFConstructRate(avctx->time_base.den, avctx->time_base.num
+#if FF_API_TICKS_PER_FRAME
+ * avctx->ticks_per_frame
+#endif
+ );
+FF_ENABLE_DEPRECATION_WARNINGS
}
if ((ret = ff_amf_encode_init(avctx)) != 0)
diff --git a/libavcodec/amfenc_hevc.c b/libavcodec/amfenc_hevc.c
index 9b46946f1e..674a4095d6 100644
--- a/libavcodec/amfenc_hevc.c
+++ b/libavcodec/amfenc_hevc.c
@@ -109,7 +109,13 @@ static av_cold int amf_encode_init_hevc(AVCodecContext *avctx)
if (avctx->framerate.num > 0 && avctx->framerate.den > 0) {
framerate = AMFConstructRate(avctx->framerate.num, avctx->framerate.den);
} else {
- framerate = AMFConstructRate(avctx->time_base.den, avctx->time_base.num * avctx->ticks_per_frame);
+FF_DISABLE_DEPRECATION_WARNINGS
+ framerate = AMFConstructRate(avctx->time_base.den, avctx->time_base.num
+#if FF_API_TICKS_PER_FRAME
+ * avctx->ticks_per_frame
+#endif
+ );
+FF_ENABLE_DEPRECATION_WARNINGS
}
if ((ret = ff_amf_encode_init(avctx)) < 0)
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 1e91b9cb53..06b1a120ab 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -556,14 +556,22 @@ typedef struct AVCodecContext {
*/
AVRational time_base;
+#if FF_API_TICKS_PER_FRAME
/**
* For some codecs, the time base is closer to the field rate than the frame rate.
* Most notably, H.264 and MPEG-2 specify time_base as half of frame duration
* if no telecine is used ...
*
* Set to time_base ticks per frame. Default 1, e.g., H.264/MPEG-2 set it to 2.
+ *
+ * @deprecated
+ * - decoding: Use AVCodecDescriptor.props & AV_CODEC_PROP_FIELDS
+ * - encoding: Set AVCodecContext.framerate instead
+ *
*/
+ attribute_deprecated
int ticks_per_frame;
+#endif
/**
* Codec delay.
diff --git a/libavcodec/encode.c b/libavcodec/encode.c
index 14e2876742..ab5f889615 100644
--- a/libavcodec/encode.c
+++ b/libavcodec/encode.c
@@ -582,6 +582,8 @@ static int encode_preinit_video(AVCodecContext *avctx)
return AVERROR(EINVAL);
}
+#if FF_API_TICKS_PER_FRAME
+FF_DISABLE_DEPRECATION_WARNINGS
if (avctx->ticks_per_frame && avctx->time_base.num &&
avctx->ticks_per_frame > INT_MAX / avctx->time_base.num) {
av_log(avctx, AV_LOG_ERROR,
@@ -591,6 +593,8 @@ static int encode_preinit_video(AVCodecContext *avctx)
avctx->time_base.den);
return AVERROR(EINVAL);
}
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
if (avctx->hw_frames_ctx) {
AVHWFramesContext *frames_ctx = (AVHWFramesContext*)avctx->hw_frames_ctx->data;
diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c
index 8526782560..be7a8e0b5a 100644
--- a/libavcodec/h264_slice.c
+++ b/libavcodec/h264_slice.c
@@ -957,7 +957,7 @@ static int h264_slice_header_init(H264Context *h)
if (h->x264_build < 44U)
den *= 2;
av_reduce(&h->avctx->framerate.den, &h->avctx->framerate.num,
- sps->num_units_in_tick * h->avctx->ticks_per_frame, den, 1 << 30);
+ sps->num_units_in_tick * 2, den, 1 << 30);
}
ff_h264_free_tables(h);
diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c
index cdd4b98c83..521b1e2235 100644
--- a/libavcodec/h264dec.c
+++ b/libavcodec/h264dec.c
@@ -382,7 +382,11 @@ static av_cold int h264_decode_init(AVCodecContext *avctx)
return AVERROR_UNKNOWN;
}
+#if FF_API_TICKS_PER_FRAME
+FF_DISABLE_DEPRECATION_WARNINGS
avctx->ticks_per_frame = 2;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
if (!avctx->internal->is_copy) {
if (avctx->extradata_size > 0 && avctx->extradata) {
diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
index 1d3a4ae64c..16747e7e92 100644
--- a/libavcodec/libaomenc.c
+++ b/libavcodec/libaomenc.c
@@ -1300,7 +1300,13 @@ static int aom_encode(AVCodecContext *avctx, AVPacket *pkt,
else if (avctx->framerate.num > 0 && avctx->framerate.den > 0)
duration = av_rescale_q(1, av_inv_q(avctx->framerate), avctx->time_base);
else
- duration = avctx->ticks_per_frame ? avctx->ticks_per_frame : 1;
+FF_DISABLE_DEPRECATION_WARNINGS
+ duration =
+#if FF_API_TICKS_PER_FRAME
+ avctx->ticks_per_frame ? avctx->ticks_per_frame :
+#endif
+ 1;
+FF_ENABLE_DEPRECATION_WARNINGS
switch (frame->color_range) {
case AVCOL_RANGE_MPEG:
diff --git a/libavcodec/libkvazaar.c b/libavcodec/libkvazaar.c
index b3faa0a64b..2ef34dd82e 100644
--- a/libavcodec/libkvazaar.c
+++ b/libavcodec/libkvazaar.c
@@ -86,7 +86,13 @@ static av_cold int libkvazaar_init(AVCodecContext *avctx)
cfg->framerate_denom = avctx->framerate.den;
} else {
cfg->framerate_num = avctx->time_base.den;
- cfg->framerate_denom = avctx->time_base.num * avctx->ticks_per_frame;
+FF_DISABLE_DEPRECATION_WARNINGS
+ cfg->framerate_denom = avctx->time_base.num
+#if FF_API_TICKS_PER_FRAME
+ * avctx->ticks_per_frame
+#endif
+ ;
+FF_ENABLE_DEPRECATION_WARNINGS
}
cfg->target_bitrate = avctx->bit_rate;
cfg->vui.sar_width = avctx->sample_aspect_ratio.num;
diff --git a/libavcodec/libopenh264enc.c b/libavcodec/libopenh264enc.c
index 15c3822824..5b59af6f94 100644
--- a/libavcodec/libopenh264enc.c
+++ b/libavcodec/libopenh264enc.c
@@ -139,7 +139,13 @@ static av_cold int svc_encode_init(AVCodecContext *avctx)
if (avctx->framerate.num > 0 && avctx->framerate.den > 0) {
param.fMaxFrameRate = av_q2d(avctx->framerate);
} else {
- param.fMaxFrameRate = 1.0 / av_q2d(avctx->time_base) / FFMAX(avctx->ticks_per_frame, 1);
+FF_DISABLE_DEPRECATION_WARNINGS
+ param.fMaxFrameRate = 1.0 / av_q2d(avctx->time_base)
+#if FF_API_TICKS_PER_FRAME
+ / FFMAX(avctx->ticks_per_frame, 1)
+#endif
+ ;
+FF_ENABLE_DEPRECATION_WARNINGS
}
param.iPicWidth = avctx->width;
param.iPicHeight = avctx->height;
diff --git a/libavcodec/librav1e.c b/libavcodec/librav1e.c
index 08affabe3e..56539435a7 100644
--- a/libavcodec/librav1e.c
+++ b/libavcodec/librav1e.c
@@ -219,10 +219,15 @@ static av_cold int librav1e_encode_init(AVCodecContext *avctx)
avctx->framerate.den, avctx->framerate.num
});
} else {
+FF_DISABLE_DEPRECATION_WARNINGS
rav1e_config_set_time_base(cfg, (RaRational) {
- avctx->time_base.num * avctx->ticks_per_frame,
- avctx->time_base.den
+ avctx->time_base.num
+#if FF_API_TICKS_PER_FRAME
+ * avctx->ticks_per_frame
+#endif
+ , avctx->time_base.den
});
+FF_ENABLE_DEPRECATION_WARNINGS
}
if ((avctx->flags & AV_CODEC_FLAG_PASS1 || avctx->flags & AV_CODEC_FLAG_PASS2) && !avctx->bit_rate) {
diff --git a/libavcodec/libsvtav1.c b/libavcodec/libsvtav1.c
index 9174e2753c..8354793a34 100644
--- a/libavcodec/libsvtav1.c
+++ b/libavcodec/libsvtav1.c
@@ -250,7 +250,13 @@ static int config_enc_params(EbSvtAv1EncConfiguration *param,
param->frame_rate_denominator = avctx->framerate.den;
} else {
param->frame_rate_numerator = avctx->time_base.den;
- param->frame_rate_denominator = avctx->time_base.num * avctx->ticks_per_frame;
+FF_DISABLE_DEPRECATION_WARNINGS
+ param->frame_rate_denominator = avctx->time_base.num
+#if FF_API_TICKS_PER_FRAME
+ * avctx->ticks_per_frame
+#endif
+ ;
+FF_ENABLE_DEPRECATION_WARNINGS
}
/* 2 = IDR, closed GOP, 1 = CRA, open GOP */
diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
index a89497665b..868b55b756 100644
--- a/libavcodec/libvpxenc.c
+++ b/libavcodec/libvpxenc.c
@@ -1829,7 +1829,13 @@ static int vpx_encode(AVCodecContext *avctx, AVPacket *pkt,
else if (avctx->framerate.num > 0 && avctx->framerate.den > 0)
duration = av_rescale_q(1, av_inv_q(avctx->framerate), avctx->time_base);
else
- duration = avctx->ticks_per_frame ? avctx->ticks_per_frame : 1;
+FF_DISABLE_DEPRECATION_WARNINGS
+ duration =
+#if FF_API_TICKS_PER_FRAME
+ avctx->ticks_per_frame ? avctx->ticks_per_frame :
+#endif
+ 1;
+FF_ENABLE_DEPRECATION_WARNINGS
res = vpx_codec_encode(&ctx->encoder, rawimg, timestamp,
duration, flags, ctx->deadline);
diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
index 3aea29e995..5736f1efa7 100644
--- a/libavcodec/libx264.c
+++ b/libavcodec/libx264.c
@@ -1018,7 +1018,13 @@ static av_cold int X264_init(AVCodecContext *avctx)
x4->params.i_fps_den = avctx->framerate.den;
} else {
x4->params.i_fps_num = avctx->time_base.den;
- x4->params.i_fps_den = avctx->time_base.num * avctx->ticks_per_frame;
+FF_DISABLE_DEPRECATION_WARNINGS
+ x4->params.i_fps_den = avctx->time_base.num
+#if FF_API_TICKS_PER_FRAME
+ * avctx->ticks_per_frame
+#endif
+ ;
+FF_ENABLE_DEPRECATION_WARNINGS
}
x4->params.analyse.b_psnr = avctx->flags & AV_CODEC_FLAG_PSNR;
diff --git a/libavcodec/libx265.c b/libavcodec/libx265.c
index 420d0953af..873b3021ee 100644
--- a/libavcodec/libx265.c
+++ b/libavcodec/libx265.c
@@ -220,7 +220,13 @@ static av_cold int libx265_encode_init(AVCodecContext *avctx)
ctx->params->fpsDenom = avctx->framerate.den;
} else {
ctx->params->fpsNum = avctx->time_base.den;
- ctx->params->fpsDenom = avctx->time_base.num * avctx->ticks_per_frame;
+FF_DISABLE_DEPRECATION_WARNINGS
+ ctx->params->fpsDenom = avctx->time_base.num
+#if FF_API_TICKS_PER_FRAME
+ * avctx->ticks_per_frame
+#endif
+ ;
+FF_ENABLE_DEPRECATION_WARNINGS
}
ctx->params->sourceWidth = avctx->width;
ctx->params->sourceHeight = avctx->height;
diff --git a/libavcodec/mfenc.c b/libavcodec/mfenc.c
index f3415df10b..8d950a3109 100644
--- a/libavcodec/mfenc.c
+++ b/libavcodec/mfenc.c
@@ -659,7 +659,11 @@ static int mf_encv_output_adjust(AVCodecContext *avctx, IMFMediaType *type)
framerate = avctx->framerate;
} else {
framerate = av_inv_q(avctx->time_base);
+#if FF_API_TICKS_PER_FRAME
+FF_DISABLE_DEPRECATION_WARNINGS
framerate.den *= avctx->ticks_per_frame;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
}
ff_MFSetAttributeRatio((IMFAttributes *)type, &MF_MT_FRAME_RATE, framerate.num, framerate.den);
diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c
index ebde68a4dd..27c862ffb2 100644
--- a/libavcodec/mpeg12dec.c
+++ b/libavcodec/mpeg12dec.c
@@ -1265,7 +1265,11 @@ static int mpeg_decode_postinit(AVCodecContext *avctx)
if (avctx->codec_id == AV_CODEC_ID_MPEG1VIDEO) {
// MPEG-1 fps
avctx->framerate = ff_mpeg12_frame_rate_tab[s1->frame_rate_index];
+#if FF_API_TICKS_PER_FRAME
+FF_DISABLE_DEPRECATION_WARNINGS
avctx->ticks_per_frame = 1;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
avctx->chroma_sample_location = AVCHROMA_LOC_CENTER;
} else { // MPEG-2
@@ -1275,7 +1279,11 @@ static int mpeg_decode_postinit(AVCodecContext *avctx)
ff_mpeg12_frame_rate_tab[s1->frame_rate_index].num * s1->frame_rate_ext.num,
ff_mpeg12_frame_rate_tab[s1->frame_rate_index].den * s1->frame_rate_ext.den,
1 << 30);
+#if FF_API_TICKS_PER_FRAME
+FF_DISABLE_DEPRECATION_WARNINGS
avctx->ticks_per_frame = 2;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
switch (s->chroma_format) {
case 1: avctx->chroma_sample_location = AVCHROMA_LOC_LEFT; break;
diff --git a/libavcodec/mpegvideo_parser.c b/libavcodec/mpegvideo_parser.c
index 08e5316960..1204789c67 100644
--- a/libavcodec/mpegvideo_parser.c
+++ b/libavcodec/mpegvideo_parser.c
@@ -145,7 +145,11 @@ static void mpegvideo_extract_headers(AVCodecParserContext *s,
pc->frame_rate = avctx->framerate = ff_mpeg12_frame_rate_tab[frame_rate_index];
bit_rate = (buf[4]<<10) | (buf[5]<<2) | (buf[6]>>6);
avctx->codec_id = AV_CODEC_ID_MPEG1VIDEO;
+#if FF_API_TICKS_PER_FRAME
+FF_DISABLE_DEPRECATION_WARNINGS
avctx->ticks_per_frame = 1;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
}
break;
case EXT_START_CODE:
@@ -177,7 +181,11 @@ static void mpegvideo_extract_headers(AVCodecParserContext *s,
avctx->framerate.num = pc->frame_rate.num * (frame_rate_ext_n + 1);
avctx->framerate.den = pc->frame_rate.den * (frame_rate_ext_d + 1);
avctx->codec_id = AV_CODEC_ID_MPEG2VIDEO;
+#if FF_API_TICKS_PER_FRAME
+FF_DISABLE_DEPRECATION_WARNINGS
avctx->ticks_per_frame = 2;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
}
break;
case 0x8: /* picture coding extension */
diff --git a/libavcodec/msmpeg4enc.c b/libavcodec/msmpeg4enc.c
index df190d376c..9828901bea 100644
--- a/libavcodec/msmpeg4enc.c
+++ b/libavcodec/msmpeg4enc.c
@@ -285,7 +285,13 @@ void ff_msmpeg4_encode_ext_header(MpegEncContext * s)
if (s->avctx->framerate.num > 0 && s->avctx->framerate.den > 0)
fps = s->avctx->framerate.num / s->avctx->framerate.den;
else
- fps = s->avctx->time_base.den / s->avctx->time_base.num / FFMAX(s->avctx->ticks_per_frame, 1);
+FF_DISABLE_DEPRECATION_WARNINGS
+ fps = s->avctx->time_base.den / s->avctx->time_base.num
+#if FF_API_TICKS_PER_FRAME
+ / FFMAX(s->avctx->ticks_per_frame, 1)
+#endif
+ ;
+FF_ENABLE_DEPRECATION_WARNINGS
put_bits(&s->pb, 5, FFMIN(fps, 31)); //yes 29.97 -> 29
diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c
index b2f6253a43..c1798ce564 100644
--- a/libavcodec/nvenc.c
+++ b/libavcodec/nvenc.c
@@ -1571,7 +1571,13 @@ static av_cold int nvenc_setup_encoder(AVCodecContext *avctx)
ctx->init_encode_params.frameRateDen = avctx->framerate.den;
} else {
ctx->init_encode_params.frameRateNum = avctx->time_base.den;
- ctx->init_encode_params.frameRateDen = avctx->time_base.num * avctx->ticks_per_frame;
+FF_DISABLE_DEPRECATION_WARNINGS
+ ctx->init_encode_params.frameRateDen = avctx->time_base.num
+#if FF_API_TICKS_PER_FRAME
+ * avctx->ticks_per_frame
+#endif
+ ;
+FF_ENABLE_DEPRECATION_WARNINGS
}
ctx->init_encode_params.enableEncodeAsync = 0;
@@ -2266,8 +2272,14 @@ static int nvenc_set_timestamp(AVCodecContext *avctx,
dts = reorder_queue_dequeue(ctx->reorder_queue, avctx, pkt);
if (avctx->codec_descriptor->props & AV_CODEC_PROP_REORDER) {
+FF_DISABLE_DEPRECATION_WARNINGS
pkt->dts = dts -
- FFMAX(ctx->encode_config.frameIntervalP - 1, 0) * FFMAX(avctx->ticks_per_frame, 1) * FFMAX(avctx->time_base.num, 1);
+ FFMAX(ctx->encode_config.frameIntervalP - 1, 0)
+#if FF_API_TICKS_PER_FRAME
+ * FFMAX(avctx->ticks_per_frame, 1)
+#endif
+ * FFMAX(avctx->time_base.num, 1);
+FF_ENABLE_DEPRECATION_WARNINGS
} else {
pkt->dts = pkt->pts;
}
diff --git a/libavcodec/options_table.h b/libavcodec/options_table.h
index 4f5918c7f6..03059cc39c 100644
--- a/libavcodec/options_table.h
+++ b/libavcodec/options_table.h
@@ -276,7 +276,9 @@ static const AVOption avcodec_options[] = {
#endif
{"rc_max_vbv_use", NULL, OFFSET(rc_max_available_vbv_use), AV_OPT_TYPE_FLOAT, {.dbl = 0 }, 0.0, FLT_MAX, V|E},
{"rc_min_vbv_use", NULL, OFFSET(rc_min_vbv_overflow_use), AV_OPT_TYPE_FLOAT, {.dbl = 3 }, 0.0, FLT_MAX, V|E},
+#if FF_API_TICKS_PER_FRAME
{"ticks_per_frame", NULL, OFFSET(ticks_per_frame), AV_OPT_TYPE_INT, {.i64 = 1 }, 1, INT_MAX, A|V|E|D},
+#endif
{"color_primaries", "color primaries", OFFSET(color_primaries), AV_OPT_TYPE_INT, {.i64 = AVCOL_PRI_UNSPECIFIED }, 1, INT_MAX, V|E|D, "color_primaries_type"},
{"bt709", "BT.709", 0, AV_OPT_TYPE_CONST, {.i64 = AVCOL_PRI_BT709 }, INT_MIN, INT_MAX, V|E|D, "color_primaries_type"},
{"unknown", "Unspecified", 0, AV_OPT_TYPE_CONST, {.i64 = AVCOL_PRI_UNSPECIFIED }, INT_MIN, INT_MAX, V|E|D, "color_primaries_type"},
diff --git a/libavcodec/pthread_frame.c b/libavcodec/pthread_frame.c
index 74864e19c5..773e78ae34 100644
--- a/libavcodec/pthread_frame.c
+++ b/libavcodec/pthread_frame.c
@@ -286,7 +286,11 @@ static int update_context_from_thread(AVCodecContext *dst, AVCodecContext *src,
dst->level = src->level;
dst->bits_per_raw_sample = src->bits_per_raw_sample;
+#if FF_API_TICKS_PER_FRAME
+FF_DISABLE_DEPRECATION_WARNINGS
dst->ticks_per_frame = src->ticks_per_frame;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
dst->color_primaries = src->color_primaries;
dst->color_trc = src->color_trc;
diff --git a/libavcodec/ratecontrol.c b/libavcodec/ratecontrol.c
index 890ae33cb3..649f570c9d 100644
--- a/libavcodec/ratecontrol.c
+++ b/libavcodec/ratecontrol.c
@@ -60,7 +60,13 @@ static double get_fps(AVCodecContext *avctx)
if (avctx->framerate.num > 0 && avctx->framerate.den > 0)
return av_q2d(avctx->framerate);
- return 1.0 / av_q2d(avctx->time_base) / FFMAX(avctx->ticks_per_frame, 1);
+FF_DISABLE_DEPRECATION_WARNINGS
+ return 1.0 / av_q2d(avctx->time_base)
+#if FF_API_TICKS_PER_FRAME
+ / FFMAX(avctx->ticks_per_frame, 1)
+#endif
+ ;
+FF_ENABLE_DEPRECATION_WARNINGS
}
static inline double qp2bits(RateControlEntry *rce, double qp)
diff --git a/libavcodec/vc1.c b/libavcodec/vc1.c
index d4014d25ab..795c6db541 100644
--- a/libavcodec/vc1.c
+++ b/libavcodec/vc1.c
@@ -418,6 +418,14 @@ static int decode_sequence_header_adv(VC1Context *v, GetBitContext *gb)
v->s.loop_filter, v->chromaformat, v->broadcast, v->interlace,
v->tfcntrflag, v->finterpflag);
+#if FF_API_TICKS_PER_FRAME
+FF_DISABLE_DEPRECATION_WARNINGS
+ if (v->broadcast) { // Pulldown may be present
+ v->s.avctx->ticks_per_frame = 2;
+ }
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+
v->psf = get_bits1(gb);
if (v->psf) { //PsF, 6.1.13
av_log(v->s.avctx, AV_LOG_ERROR, "Progressive Segmented Frame mode: not supported (yet)\n");
@@ -467,9 +475,6 @@ static int decode_sequence_header_adv(VC1Context *v, GetBitContext *gb)
v->s.avctx->framerate.num = ff_vc1_fps_nr[nr - 1] * 1000;
}
}
- if (v->broadcast) { // Pulldown may be present
- v->s.avctx->ticks_per_frame = 2;
- }
}
if (get_bits1(gb)) {
diff --git a/libavcodec/vc1_parser.c b/libavcodec/vc1_parser.c
index 4167215fb1..ec284dca00 100644
--- a/libavcodec/vc1_parser.c
+++ b/libavcodec/vc1_parser.c
@@ -89,11 +89,10 @@ static void vc1_extract_header(AVCodecParserContext *s, AVCodecContext *avctx,
else
s->pict_type = vpc->v.s.pict_type;
- if (avctx->ticks_per_frame > 1){
+ if (vpc->v.broadcast){
// process pulldown flags
s->repeat_pict = 1;
// Pulldown flags are only valid when 'broadcast' has been set.
- // So ticks_per_frame will be 2
if (vpc->v.rff){
// repeat field
s->repeat_pict = 2;
diff --git a/libavcodec/vc1dec.c b/libavcodec/vc1dec.c
index 8298cefbc7..9e343d003f 100644
--- a/libavcodec/vc1dec.c
+++ b/libavcodec/vc1dec.c
@@ -1087,7 +1087,6 @@ static int vc1_decode_frame(AVCodecContext *avctx, AVFrame *pict,
// process pulldown flags
s->current_picture_ptr->f->repeat_pict = 0;
// Pulldown flags are only valid when 'broadcast' has been set.
- // So ticks_per_frame will be 2
if (v->rff) {
// repeat field
s->current_picture_ptr->f->repeat_pict = 1;
diff --git a/libavcodec/version_major.h b/libavcodec/version_major.h
index 40db213499..546999ce76 100644
--- a/libavcodec/version_major.h
+++ b/libavcodec/version_major.h
@@ -46,6 +46,7 @@
#define FF_API_VT_HWACCEL_CONTEXT (LIBAVCODEC_VERSION_MAJOR < 61)
#define FF_API_AVCTX_FRAME_NUMBER (LIBAVCODEC_VERSION_MAJOR < 61)
#define FF_API_SLICE_OFFSET (LIBAVCODEC_VERSION_MAJOR < 61)
+#define FF_API_TICKS_PER_FRAME (LIBAVCODEC_VERSION_MAJOR < 61)
// reminder to remove CrystalHD decoders on next major bump
#define FF_CODEC_CRYSTAL_HD (LIBAVCODEC_VERSION_MAJOR < 61)
diff --git a/libavformat/avformat.c b/libavformat/avformat.c
index fea905693d..356b4de931 100644
--- a/libavformat/avformat.c
+++ b/libavformat/avformat.c
@@ -710,7 +710,6 @@ int avformat_transfer_internal_stream_timing_info(const AVOutputFormat *ofmt,
AVRational dec_ctx_tb = dec_ctx->framerate.num ? av_inv_q(av_mul_q(dec_ctx->framerate, mul))
: (ist->codecpar->codec_type == AVMEDIA_TYPE_AUDIO ? (AVRational){0, 1}
: ist->time_base);
-
enc_ctx->time_base = ist->time_base;
/*
* Avi is a special case here because it supports variable fps but
@@ -727,7 +726,11 @@ int avformat_transfer_internal_stream_timing_info(const AVOutputFormat *ofmt,
|| copy_tb == AVFMT_TBCF_R_FRAMERATE) {
enc_ctx->time_base.num = ist->r_frame_rate.den;
enc_ctx->time_base.den = 2*ist->r_frame_rate.num;
+#if FF_API_TICKS_PER_FRAME
+FF_DISABLE_DEPRECATION_WARNINGS
enc_ctx->ticks_per_frame = 2;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
} else
#endif
if (copy_tb == AVFMT_TBCF_AUTO && dec_ctx->framerate.num &&
@@ -736,9 +739,13 @@ int avformat_transfer_internal_stream_timing_info(const AVOutputFormat *ofmt,
|| (copy_tb == AVFMT_TBCF_DECODER &&
(dec_ctx->framerate.num || ist->codecpar->codec_type == AVMEDIA_TYPE_AUDIO))) {
enc_ctx->time_base = dec_ctx_tb;
- enc_ctx->time_base.num *= dec_ctx->ticks_per_frame;
enc_ctx->time_base.den *= 2;
+#if FF_API_TICKS_PER_FRAME
+FF_DISABLE_DEPRECATION_WARNINGS
+ enc_ctx->time_base.num *= dec_ctx->ticks_per_frame;
enc_ctx->ticks_per_frame = 2;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
}
} else if (!(ofmt->flags & AVFMT_VARIABLE_FPS)
&& !av_match_name(ofmt->name, "mov,mp4,3gp,3g2,psp,ipod,ismv,f4v")) {
@@ -748,7 +755,11 @@ int avformat_transfer_internal_stream_timing_info(const AVOutputFormat *ofmt,
|| (copy_tb == AVFMT_TBCF_DECODER &&
(dec_ctx->framerate.num || ist->codecpar->codec_type == AVMEDIA_TYPE_AUDIO))) {
enc_ctx->time_base = dec_ctx_tb;
+#if FF_API_TICKS_PER_FRAME
+FF_DISABLE_DEPRECATION_WARNINGS
enc_ctx->time_base.num *= dec_ctx->ticks_per_frame;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
}
}
--
2.39.2
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 35+ messages in thread
* [FFmpeg-devel] [PATCH 13/13] fftools/ffmpeg: stop using deprecated ticks_per_frame
2023-05-07 13:32 [FFmpeg-devel] [PATCH 01/13] lavu/frame: extend AVFrame.repeat_pict documentation Anton Khirnov
` (10 preceding siblings ...)
2023-05-07 13:32 ` [FFmpeg-devel] [PATCH 12/13] lavc: deprecate AVCodecContext.ticks_per_frame Anton Khirnov
@ 2023-05-07 13:32 ` Anton Khirnov
2023-05-07 16:59 ` [FFmpeg-devel] [PATCH 01/13] lavu/frame: extend AVFrame.repeat_pict documentation Kieran Kunhya
12 siblings, 0 replies; 35+ messages in thread
From: Anton Khirnov @ 2023-05-07 13:32 UTC (permalink / raw)
To: ffmpeg-devel
---
fftools/ffmpeg.c | 13 +++++++------
fftools/ffmpeg.h | 1 +
fftools/ffmpeg_demux.c | 2 ++
3 files changed, 10 insertions(+), 6 deletions(-)
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 4e45ab74b9..a731b4bd7d 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -1516,12 +1516,13 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo
} else if (pkt->duration) {
ist->next_dts += av_rescale_q(pkt->duration, pkt->time_base, AV_TIME_BASE_Q);
} else if(ist->dec_ctx->framerate.num != 0) {
- int ticks = ist->last_pkt_repeat_pict >= 0 ?
- ist->last_pkt_repeat_pict + 1 :
- ist->dec_ctx->ticks_per_frame;
- ist->next_dts += ((int64_t)AV_TIME_BASE *
- ist->dec_ctx->framerate.den * ticks) /
- ist->dec_ctx->framerate.num / ist->dec_ctx->ticks_per_frame;
+ int fields = (ist->codec_desc &&
+ (ist->codec_desc->props & AV_CODEC_PROP_FIELDS)) ?
+ ist->last_pkt_repeat_pict + 1 : 2;
+ AVRational field_rate = av_mul_q(ist->dec_ctx->framerate,
+ (AVRational){ 2, 1 });
+
+ ist->next_dts += av_rescale_q(fields, av_inv_q(field_rate), AV_TIME_BASE_Q);
}
break;
}
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index b6389d7f99..0cceffbe9b 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -354,6 +354,7 @@ typedef struct InputStream {
AVCodecParameters *par;
AVCodecContext *dec_ctx;
const AVCodec *dec;
+ const AVCodecDescriptor *codec_desc;
AVFrame *decoded_frame;
AVPacket *pkt;
diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index 26426c7ac1..6f26e4226d 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -941,6 +941,8 @@ static void add_input_streams(const OptionsContext *o, Demuxer *d)
av_log(ist, AV_LOG_ERROR, "Error initializing the decoder context.\n");
exit_program(1);
}
+
+ ist->codec_desc = avcodec_descriptor_get(ist->par->codec_id);
}
}
--
2.39.2
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [FFmpeg-devel] [PATCH 01/13] lavu/frame: extend AVFrame.repeat_pict documentation
2023-05-07 13:32 [FFmpeg-devel] [PATCH 01/13] lavu/frame: extend AVFrame.repeat_pict documentation Anton Khirnov
` (11 preceding siblings ...)
2023-05-07 13:32 ` [FFmpeg-devel] [PATCH 13/13] fftools/ffmpeg: stop using deprecated ticks_per_frame Anton Khirnov
@ 2023-05-07 16:59 ` Kieran Kunhya
2023-05-07 18:01 ` Anton Khirnov
12 siblings, 1 reply; 35+ messages in thread
From: Kieran Kunhya @ 2023-05-07 16:59 UTC (permalink / raw)
To: FFmpeg development discussions and patches
On Sun, 7 May 2023, 14:34 Anton Khirnov, <anton@khirnov.net> wrote:
> ---
> libavutil/frame.h | 18 ++++++++++++++++--
> 1 file changed, 16 insertions(+), 2 deletions(-)
>
> diff --git a/libavutil/frame.h b/libavutil/frame.h
> index f2b56beebb..ed3f199ce1 100644
> --- a/libavutil/frame.h
> +++ b/libavutil/frame.h
> @@ -491,8 +491,22 @@ typedef struct AVFrame {
> void *opaque;
>
> /**
> - * When decoding, this signals how much the picture must be delayed.
> - * extra_delay = repeat_pict / (2*fps)
> + * Number of fields in this frame which should be repeated, i.e. the
> total
> + * duration of this frame should be repeat_pict + 2 normal field
> durations.
> + *
> + * For interlaced frames this field may be set to 1, which signals
> that this
> + * frame should be presented as 3 fields: beginning with the first
> field (as
> + * determined by AV_FRAME_FLAG_TOP_FIELD_FIRST being set or not),
> followed
> + * by the second field, and then the first field again.
> + *
> + * For progressive frames this field may be set to a multiple of 2,
> which
> + * signals that this frame's duration should be (repeat_pict + 2) / 2
> + * normal frame durations.
This isn't correct, a progressive [coded] frame is allowed to have its
first field repeated.
There is a difference between the coded type and the display method of a
frame. The documentation suggests otherwise.
Kieran
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [FFmpeg-devel] [PATCH 01/13] lavu/frame: extend AVFrame.repeat_pict documentation
2023-05-07 16:59 ` [FFmpeg-devel] [PATCH 01/13] lavu/frame: extend AVFrame.repeat_pict documentation Kieran Kunhya
@ 2023-05-07 18:01 ` Anton Khirnov
0 siblings, 0 replies; 35+ messages in thread
From: Anton Khirnov @ 2023-05-07 18:01 UTC (permalink / raw)
To: FFmpeg development discussions and patches
Quoting Kieran Kunhya (2023-05-07 18:59:22)
> On Sun, 7 May 2023, 14:34 Anton Khirnov, <anton@khirnov.net> wrote:
>
> > ---
> > libavutil/frame.h | 18 ++++++++++++++++--
> > 1 file changed, 16 insertions(+), 2 deletions(-)
> >
> > diff --git a/libavutil/frame.h b/libavutil/frame.h
> > index f2b56beebb..ed3f199ce1 100644
> > --- a/libavutil/frame.h
> > +++ b/libavutil/frame.h
> > @@ -491,8 +491,22 @@ typedef struct AVFrame {
> > void *opaque;
> >
> > /**
> > - * When decoding, this signals how much the picture must be delayed.
> > - * extra_delay = repeat_pict / (2*fps)
> > + * Number of fields in this frame which should be repeated, i.e. the
> > total
> > + * duration of this frame should be repeat_pict + 2 normal field
> > durations.
> > + *
> > + * For interlaced frames this field may be set to 1, which signals
> > that this
> > + * frame should be presented as 3 fields: beginning with the first
> > field (as
> > + * determined by AV_FRAME_FLAG_TOP_FIELD_FIRST being set or not),
> > followed
> > + * by the second field, and then the first field again.
> > + *
> > + * For progressive frames this field may be set to a multiple of 2,
> > which
> > + * signals that this frame's duration should be (repeat_pict + 2) / 2
> > + * normal frame durations.
>
>
> This isn't correct, a progressive [coded] frame is allowed to have its
> first field repeated.
>
> There is a difference between the coded type and the display method of a
> frame. The documentation suggests otherwise.
In my understanding the AVFrame interlacing flag relates to how the
decoded frame is supposed to be treated (displayed or processed). It
says nothing about how the frame was coded or what source it comes from.
--
Anton Khirnov
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [FFmpeg-devel] [PATCH 04/13] lavf: use AV_CODEC_PROP_FIELDS where appropriate
2023-05-07 13:32 ` [FFmpeg-devel] [PATCH 04/13] lavf: use AV_CODEC_PROP_FIELDS where appropriate Anton Khirnov
@ 2023-05-08 14:12 ` Michael Niedermayer
2023-05-09 8:37 ` [FFmpeg-devel] [PATCH v2 " Anton Khirnov
2023-05-08 14:15 ` [FFmpeg-devel] [PATCH " Michael Niedermayer
1 sibling, 1 reply; 35+ messages in thread
From: Michael Niedermayer @ 2023-05-08 14:12 UTC (permalink / raw)
To: FFmpeg development discussions and patches
[-- Attachment #1.1: Type: text/plain, Size: 1100 bytes --]
On Sun, May 07, 2023 at 03:32:46PM +0200, Anton Khirnov wrote:
> H.264 and mpeg12 parsers need to be adjusted at the same time to stop
> using the value of AVCodecContext.ticks_per_frame, because it is not set
> correctly unless the codec has been opened. Previously this would result
> in both the parser and lavf seeing the same incorrect value, which would
> cancel out.
> Updating lavf and not the parsers would result in correct value in lavf,
> but the wrong one in parsers, which would break some tests.
> ---
> libavcodec/h264_parser.c | 4 ++--
> libavcodec/mpegvideo_parser.c | 2 +-
> libavformat/avformat.c | 9 ++++++---
> libavformat/demux.c | 29 +++++++++++++++++++----------
> libavformat/internal.h | 3 +++
> 5 files changed, 31 insertions(+), 16 deletions(-)
breaks:
./ffmpeg -i ~/tickets/104/cartonfold.avi -bitexact -f framecrc -
fps and timestamps look strange
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
It is what and why we do it that matters, not just one of them.
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
[-- Attachment #2: Type: text/plain, Size: 251 bytes --]
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [FFmpeg-devel] [PATCH 04/13] lavf: use AV_CODEC_PROP_FIELDS where appropriate
2023-05-07 13:32 ` [FFmpeg-devel] [PATCH 04/13] lavf: use AV_CODEC_PROP_FIELDS where appropriate Anton Khirnov
2023-05-08 14:12 ` Michael Niedermayer
@ 2023-05-08 14:15 ` Michael Niedermayer
2023-05-09 8:44 ` Anton Khirnov
1 sibling, 1 reply; 35+ messages in thread
From: Michael Niedermayer @ 2023-05-08 14:15 UTC (permalink / raw)
To: FFmpeg development discussions and patches
[-- Attachment #1.1: Type: text/plain, Size: 1153 bytes --]
On Sun, May 07, 2023 at 03:32:46PM +0200, Anton Khirnov wrote:
> H.264 and mpeg12 parsers need to be adjusted at the same time to stop
> using the value of AVCodecContext.ticks_per_frame, because it is not set
> correctly unless the codec has been opened. Previously this would result
> in both the parser and lavf seeing the same incorrect value, which would
> cancel out.
> Updating lavf and not the parsers would result in correct value in lavf,
> but the wrong one in parsers, which would break some tests.
> ---
> libavcodec/h264_parser.c | 4 ++--
> libavcodec/mpegvideo_parser.c | 2 +-
> libavformat/avformat.c | 9 ++++++---
> libavformat/demux.c | 29 +++++++++++++++++++----------
> libavformat/internal.h | 3 +++
> 5 files changed, 31 insertions(+), 16 deletions(-)
Doesnt this sort of change need a major ABI bump ?
it sounds like lavc and lavf interdepend here both ways
thx
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Elect your leaders based on what they did after the last election, not
based on what they say before an election.
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
[-- Attachment #2: Type: text/plain, Size: 251 bytes --]
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [FFmpeg-devel] [PATCH 11/13] lavc/libvpxenc: send frame durations to the encoder
2023-05-07 13:32 ` [FFmpeg-devel] [PATCH 11/13] lavc/libvpxenc: send frame durations to the encoder Anton Khirnov
@ 2023-05-09 1:18 ` James Zern
2023-05-09 9:09 ` [FFmpeg-devel] [PATCH v2 " Anton Khirnov
0 siblings, 1 reply; 35+ messages in thread
From: James Zern @ 2023-05-09 1:18 UTC (permalink / raw)
To: FFmpeg development discussions and patches
On Sun, May 7, 2023 at 6:34 AM Anton Khirnov <anton@khirnov.net> wrote:
>
> Adapt similar code from libaomenc - stop using ticks_per_frame except as
> a last resort.
> ---
> libavcodec/libvpxenc.c | 15 +++++++++++++--
> 1 file changed, 13 insertions(+), 2 deletions(-)
>
> diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
> index a20e949842..a89497665b 100644
> --- a/libavcodec/libvpxenc.c
> +++ b/libavcodec/libvpxenc.c
> @@ -1692,6 +1692,7 @@ static int vpx_encode(AVCodecContext *avctx, AVPacket *pkt,
> const struct vpx_codec_enc_cfg *enccfg = ctx->encoder.config.enc;
> vpx_svc_layer_id_t layer_id;
> int layer_id_valid = 0;
> + unsigned long duration;
>
> if (avctx->qmax >= 0 && enccfg->rc_max_quantizer != avctx->qmax) {
> struct vpx_codec_enc_cfg cfg = *enccfg;
> @@ -1820,8 +1821,18 @@ static int vpx_encode(AVCodecContext *avctx, AVPacket *pkt,
> #endif
> }
>
> + if (frame && frame->duration > ULONG_MAX) {
> + av_log(avctx, AV_LOG_WARNING,
> + "Frame duration too large: %"PRId64"\n", frame->duration);
duration would be left undefined in this case.
> + } else if (frame && frame->duration)
> + duration = frame->duration;
> + else if (avctx->framerate.num > 0 && avctx->framerate.den > 0)
> + duration = av_rescale_q(1, av_inv_q(avctx->framerate), avctx->time_base);
> + else
> + duration = avctx->ticks_per_frame ? avctx->ticks_per_frame : 1;
> +
> res = vpx_codec_encode(&ctx->encoder, rawimg, timestamp,
> - avctx->ticks_per_frame, flags, ctx->deadline);
> + duration, flags, ctx->deadline);
> if (res != VPX_CODEC_OK) {
> log_encoder_error(avctx, "Error encoding frame");
> return AVERROR_INVALIDDATA;
> @@ -1829,7 +1840,7 @@ static int vpx_encode(AVCodecContext *avctx, AVPacket *pkt,
>
> if (ctx->is_alpha) {
> res = vpx_codec_encode(&ctx->encoder_alpha, rawimg_alpha, timestamp,
> - avctx->ticks_per_frame, flags, ctx->deadline);
> + duration, flags, ctx->deadline);
> if (res != VPX_CODEC_OK) {
> log_encoder_error(avctx, "Error encoding alpha frame");
> return AVERROR_INVALIDDATA;
> --
> 2.39.2
>
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 35+ messages in thread
* [FFmpeg-devel] [PATCH v2 04/13] lavf: use AV_CODEC_PROP_FIELDS where appropriate
2023-05-08 14:12 ` Michael Niedermayer
@ 2023-05-09 8:37 ` Anton Khirnov
0 siblings, 0 replies; 35+ messages in thread
From: Anton Khirnov @ 2023-05-09 8:37 UTC (permalink / raw)
To: ffmpeg-devel
H.264 and mpeg12 parsers need to be adjusted at the same time to stop
using the value of AVCodecContext.ticks_per_frame, because it is not set
correctly unless the codec has been opened. Previously this would result
in both the parser and lavf seeing the same incorrect value, which would
cancel out.
Updating lavf and not the parsers would result in correct value in lavf,
but the wrong one in parsers, which would break some tests.
---
libavcodec/h264_parser.c | 4 ++--
libavcodec/mpegvideo_parser.c | 2 +-
libavformat/avformat.c | 9 ++++++---
libavformat/demux.c | 35 ++++++++++++++++++++---------------
libavformat/internal.h | 3 +++
5 files changed, 32 insertions(+), 21 deletions(-)
diff --git a/libavcodec/h264_parser.c b/libavcodec/h264_parser.c
index 46134a1c48..43abc45f9c 100644
--- a/libavcodec/h264_parser.c
+++ b/libavcodec/h264_parser.c
@@ -568,7 +568,7 @@ static inline int parse_nal_units(AVCodecParserContext *s,
if (p->sei.common.unregistered.x264_build < 44U)
den *= 2;
av_reduce(&avctx->framerate.den, &avctx->framerate.num,
- sps->num_units_in_tick * avctx->ticks_per_frame, den, 1 << 30);
+ sps->num_units_in_tick * 2, den, 1 << 30);
}
av_freep(&rbsp.rbsp_buffer);
@@ -625,7 +625,7 @@ static int h264_parse(AVCodecParserContext *s,
parse_nal_units(s, avctx, buf, buf_size);
if (avctx->framerate.num)
- time_base = av_inv_q(av_mul_q(avctx->framerate, (AVRational){avctx->ticks_per_frame, 1}));
+ time_base = av_inv_q(av_mul_q(avctx->framerate, (AVRational){2, 1}));
if (p->sei.picture_timing.cpb_removal_delay >= 0) {
s->dts_sync_point = p->sei.buffering_period.present;
s->dts_ref_dts_delta = p->sei.picture_timing.cpb_removal_delay;
diff --git a/libavcodec/mpegvideo_parser.c b/libavcodec/mpegvideo_parser.c
index 8e7e88ff25..08e5316960 100644
--- a/libavcodec/mpegvideo_parser.c
+++ b/libavcodec/mpegvideo_parser.c
@@ -129,6 +129,7 @@ static void mpegvideo_extract_headers(AVCodecParserContext *s,
s->pict_type = (buf[1] >> 3) & 7;
if (bytes_left >= 4)
vbv_delay = ((buf[1] & 0x07) << 13) | (buf[2] << 5) | (buf[3] >> 3);
+ s->repeat_pict = 1;
}
break;
case SEQ_START_CODE:
@@ -186,7 +187,6 @@ static void mpegvideo_extract_headers(AVCodecParserContext *s,
progressive_frame = buf[4] & (1 << 7);
/* check if we must repeat the frame */
- s->repeat_pict = 1;
if (repeat_first_field) {
if (pc->progressive_sequence) {
if (top_field_first)
diff --git a/libavformat/avformat.c b/libavformat/avformat.c
index 708d90b38c..fea905693d 100644
--- a/libavformat/avformat.c
+++ b/libavformat/avformat.c
@@ -679,6 +679,7 @@ AVRational av_guess_sample_aspect_ratio(AVFormatContext *format, AVStream *strea
AVRational av_guess_frame_rate(AVFormatContext *format, AVStream *st, AVFrame *frame)
{
AVRational fr = st->r_frame_rate;
+ const AVCodecDescriptor *desc = cffstream(st)->codec_desc;
AVCodecContext *const avctx = ffstream(st)->avctx;
AVRational codec_fr = avctx->framerate;
AVRational avg_fr = st->avg_frame_rate;
@@ -688,7 +689,7 @@ AVRational av_guess_frame_rate(AVFormatContext *format, AVStream *st, AVFrame *f
fr = avg_fr;
}
- if (avctx->ticks_per_frame > 1) {
+ if (desc && (desc->props & AV_CODEC_PROP_FIELDS)) {
if ( codec_fr.num > 0 && codec_fr.den > 0 &&
(fr.num == 0 || av_q2d(codec_fr) < av_q2d(fr)*0.7 && fabs(1.0 - av_q2d(av_div_q(avg_fr, fr))) > 0.1))
fr = codec_fr;
@@ -701,10 +702,12 @@ int avformat_transfer_internal_stream_timing_info(const AVOutputFormat *ofmt,
AVStream *ost, const AVStream *ist,
enum AVTimebaseSource copy_tb)
{
+ const AVCodecDescriptor *desc = cffstream(ist)->codec_desc;
const AVCodecContext *const dec_ctx = cffstream(ist)->avctx;
AVCodecContext *const enc_ctx = ffstream(ost)->avctx;
- AVRational dec_ctx_tb = dec_ctx->framerate.num ? av_inv_q(av_mul_q(dec_ctx->framerate,
- (AVRational){dec_ctx->ticks_per_frame, 1}))
+
+ AVRational mul = (AVRational){ desc && (desc->props & AV_CODEC_PROP_FIELDS) ? 2 : 1, 1 };
+ AVRational dec_ctx_tb = dec_ctx->framerate.num ? av_inv_q(av_mul_q(dec_ctx->framerate, mul))
: (ist->codecpar->codec_type == AVMEDIA_TYPE_AUDIO ? (AVRational){0, 1}
: ist->time_base);
diff --git a/libavformat/demux.c b/libavformat/demux.c
index 2a32bde7f5..dec02a1a6b 100644
--- a/libavformat/demux.c
+++ b/libavformat/demux.c
@@ -213,6 +213,8 @@ FF_ENABLE_DEPRECATION_WARNINGS
if (ret < 0)
return ret;
+ sti->codec_desc = avcodec_descriptor_get(sti->avctx->codec_id);
+
sti->need_context_update = 0;
}
return 0;
@@ -677,10 +679,11 @@ static void compute_frame_duration(AVFormatContext *s, int *pnum, int *pden,
*pnum = st->time_base.num;
*pden = st->time_base.den;
} else if (codec_framerate.den * 1000LL > codec_framerate.num) {
- av_assert0(sti->avctx->ticks_per_frame);
+ int ticks_per_frame = (sti->codec_desc &&
+ (sti->codec_desc->props & AV_CODEC_PROP_FIELDS)) ? 2 : 1;
av_reduce(pnum, pden,
codec_framerate.den,
- codec_framerate.num * (int64_t)sti->avctx->ticks_per_frame,
+ codec_framerate.num * (int64_t)ticks_per_frame,
INT_MAX);
if (pc && pc->repeat_pict) {
@@ -692,7 +695,8 @@ static void compute_frame_duration(AVFormatContext *s, int *pnum, int *pden,
/* If this codec can be interlaced or progressive then we need
* a parser to compute duration of a packet. Thus if we have
* no parser in such case leave duration undefined. */
- if (sti->avctx->ticks_per_frame > 1 && !pc)
+ if (sti->codec_desc &&
+ (sti->codec_desc->props & AV_CODEC_PROP_FIELDS) && !pc)
*pnum = *pden = 0;
}
break;
@@ -1288,6 +1292,8 @@ static int read_frame_internal(AVFormatContext *s, AVPacket *pkt)
return ret;
}
+ sti->codec_desc = avcodec_descriptor_get(sti->avctx->codec_id);
+
sti->need_context_update = 0;
}
@@ -2164,9 +2170,10 @@ static int get_std_framerate(int i)
static int tb_unreliable(AVFormatContext *ic, AVStream *st)
{
FFStream *const sti = ffstream(st);
+ const AVCodecDescriptor *desc = sti->codec_desc;
AVCodecContext *c = sti->avctx;
- AVRational time_base = c->framerate.num ? av_inv_q(av_mul_q(c->framerate,
- (AVRational){c->ticks_per_frame, 1}))
+ AVRational mul = (AVRational){ desc && (desc->props & AV_CODEC_PROP_FIELDS) ? 2 : 1, 1 };
+ AVRational time_base = c->framerate.num ? av_inv_q(av_mul_q(c->framerate, mul))
/* NOHEADER check added to not break existing behavior */
: (((ic->ctx_flags & AVFMTCTX_NOHEADER) ||
st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) ? (AVRational){0, 1}
@@ -2718,13 +2725,14 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
break;
}
if (pkt->duration > 0) {
+ const int fields = sti->codec_desc && (sti->codec_desc->props & AV_CODEC_PROP_FIELDS);
if (avctx->codec_type == AVMEDIA_TYPE_SUBTITLE && pkt->pts != AV_NOPTS_VALUE && st->start_time != AV_NOPTS_VALUE && pkt->pts >= st->start_time
&& (uint64_t)pkt->pts - st->start_time < INT64_MAX
) {
sti->info->codec_info_duration = FFMIN(pkt->pts - st->start_time, sti->info->codec_info_duration + pkt->duration);
} else
sti->info->codec_info_duration += pkt->duration;
- sti->info->codec_info_duration_fields += sti->parser && sti->need_parsing && avctx->ticks_per_frame == 2
+ sti->info->codec_info_duration_fields += sti->parser && sti->need_parsing && fields
? sti->parser->repeat_pict + 1 : 2;
}
}
@@ -2864,15 +2872,12 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
best_fps, 12 * 1001, INT_MAX);
}
if (!st->r_frame_rate.num) {
- AVRational time_base = avctx->framerate.num ? av_inv_q(av_mul_q(avctx->framerate,
- (AVRational){avctx->ticks_per_frame, 1}))
- /* NOHEADER check added to not break existing behavior */
- : ((ic->ctx_flags & AVFMTCTX_NOHEADER) ? (AVRational){0, 1}
- : st->time_base);
- if ( time_base.den * (int64_t) st->time_base.num
- <= time_base.num * (uint64_t)avctx->ticks_per_frame * st->time_base.den) {
- av_reduce(&st->r_frame_rate.num, &st->r_frame_rate.den,
- time_base.den, (int64_t)time_base.num * avctx->ticks_per_frame, INT_MAX);
+ const AVCodecDescriptor *desc = sti->codec_desc;
+ AVRational mul = (AVRational){ desc && (desc->props & AV_CODEC_PROP_FIELDS) ? 2 : 1, 1 };
+ AVRational fr = av_mul_q(avctx->framerate, mul);
+
+ if (fr.num && fr.den && av_cmp_q(st->time_base, av_inv_q(fr)) <= 0) {
+ st->r_frame_rate = fr;
} else {
st->r_frame_rate.num = st->time_base.den;
st->r_frame_rate.den = st->time_base.num;
diff --git a/libavformat/internal.h b/libavformat/internal.h
index f575064e8f..40c46311c8 100644
--- a/libavformat/internal.h
+++ b/libavformat/internal.h
@@ -23,6 +23,7 @@
#include <stdint.h>
+#include "libavcodec/codec_desc.h"
#include "libavcodec/packet_internal.h"
#include "avformat.h"
@@ -408,6 +409,8 @@ typedef struct FFStream {
*/
int64_t first_dts;
int64_t cur_dts;
+
+ const AVCodecDescriptor *codec_desc;
} FFStream;
static av_always_inline FFStream *ffstream(AVStream *st)
--
2.39.2
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [FFmpeg-devel] [PATCH 04/13] lavf: use AV_CODEC_PROP_FIELDS where appropriate
2023-05-08 14:15 ` [FFmpeg-devel] [PATCH " Michael Niedermayer
@ 2023-05-09 8:44 ` Anton Khirnov
2023-05-15 18:59 ` Michael Niedermayer
0 siblings, 1 reply; 35+ messages in thread
From: Anton Khirnov @ 2023-05-09 8:44 UTC (permalink / raw)
To: FFmpeg development discussions and patches
Quoting Michael Niedermayer (2023-05-08 16:15:42)
> On Sun, May 07, 2023 at 03:32:46PM +0200, Anton Khirnov wrote:
> > H.264 and mpeg12 parsers need to be adjusted at the same time to stop
> > using the value of AVCodecContext.ticks_per_frame, because it is not set
> > correctly unless the codec has been opened. Previously this would result
> > in both the parser and lavf seeing the same incorrect value, which would
> > cancel out.
> > Updating lavf and not the parsers would result in correct value in lavf,
> > but the wrong one in parsers, which would break some tests.
> > ---
> > libavcodec/h264_parser.c | 4 ++--
> > libavcodec/mpegvideo_parser.c | 2 +-
> > libavformat/avformat.c | 9 ++++++---
> > libavformat/demux.c | 29 +++++++++++++++++++----------
> > libavformat/internal.h | 3 +++
> > 5 files changed, 31 insertions(+), 16 deletions(-)
>
> Doesnt this sort of change need a major ABI bump ?
> it sounds like lavc and lavf interdepend here both ways
No, we do not guarantee bug compatibility.
Libavformat seeing ticks_per_frame=1 for codecs that set it to 2 upon
being opened is a bug. Same for the parser.
It just so happens that libavformat AND its internal parser instance see
the same incorrect value and this cancels out in cases that are tested
by FATE (it would break if we had more thorough tests for repeating
single fields).
I could split this into two patches, the first of which would fix one of
the bugs, expose the other one, breaking some tests. Then the second
patch would fix the second bug, fixing the tests again. It seems better
to do it in a single step to avoid the noise.
--
Anton Khirnov
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 35+ messages in thread
* [FFmpeg-devel] [PATCH v2 11/13] lavc/libvpxenc: send frame durations to the encoder
2023-05-09 1:18 ` James Zern
@ 2023-05-09 9:09 ` Anton Khirnov
2023-05-09 18:17 ` James Zern
0 siblings, 1 reply; 35+ messages in thread
From: Anton Khirnov @ 2023-05-09 9:09 UTC (permalink / raw)
To: ffmpeg-devel
Adapt similar code from libaomenc - stop using ticks_per_frame except as
a last resort.
---
libavcodec/libvpxenc.c | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
index a20e949842..f70cc87c41 100644
--- a/libavcodec/libvpxenc.c
+++ b/libavcodec/libvpxenc.c
@@ -1692,6 +1692,7 @@ static int vpx_encode(AVCodecContext *avctx, AVPacket *pkt,
const struct vpx_codec_enc_cfg *enccfg = ctx->encoder.config.enc;
vpx_svc_layer_id_t layer_id;
int layer_id_valid = 0;
+ unsigned long duration = 0;
if (avctx->qmax >= 0 && enccfg->rc_max_quantizer != avctx->qmax) {
struct vpx_codec_enc_cfg cfg = *enccfg;
@@ -1820,8 +1821,18 @@ static int vpx_encode(AVCodecContext *avctx, AVPacket *pkt,
#endif
}
+ if (frame && frame->duration > ULONG_MAX) {
+ av_log(avctx, AV_LOG_WARNING,
+ "Frame duration too large: %"PRId64"\n", frame->duration);
+ } else if (frame && frame->duration)
+ duration = frame->duration;
+ else if (avctx->framerate.num > 0 && avctx->framerate.den > 0)
+ duration = av_rescale_q(1, av_inv_q(avctx->framerate), avctx->time_base);
+ else
+ duration = avctx->ticks_per_frame ? avctx->ticks_per_frame : 1;
+
res = vpx_codec_encode(&ctx->encoder, rawimg, timestamp,
- avctx->ticks_per_frame, flags, ctx->deadline);
+ duration, flags, ctx->deadline);
if (res != VPX_CODEC_OK) {
log_encoder_error(avctx, "Error encoding frame");
return AVERROR_INVALIDDATA;
@@ -1829,7 +1840,7 @@ static int vpx_encode(AVCodecContext *avctx, AVPacket *pkt,
if (ctx->is_alpha) {
res = vpx_codec_encode(&ctx->encoder_alpha, rawimg_alpha, timestamp,
- avctx->ticks_per_frame, flags, ctx->deadline);
+ duration, flags, ctx->deadline);
if (res != VPX_CODEC_OK) {
log_encoder_error(avctx, "Error encoding alpha frame");
return AVERROR_INVALIDDATA;
--
2.39.2
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [FFmpeg-devel] [PATCH v2 11/13] lavc/libvpxenc: send frame durations to the encoder
2023-05-09 9:09 ` [FFmpeg-devel] [PATCH v2 " Anton Khirnov
@ 2023-05-09 18:17 ` James Zern
2023-05-10 6:34 ` Anton Khirnov
0 siblings, 1 reply; 35+ messages in thread
From: James Zern @ 2023-05-09 18:17 UTC (permalink / raw)
To: FFmpeg development discussions and patches
On Tue, May 9, 2023 at 2:10 AM Anton Khirnov <anton@khirnov.net> wrote:
>
> Adapt similar code from libaomenc - stop using ticks_per_frame except as
> a last resort.
> ---
> libavcodec/libvpxenc.c | 15 +++++++++++++--
> 1 file changed, 13 insertions(+), 2 deletions(-)
>
lgtm.
> diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
> index a20e949842..f70cc87c41 100644
> --- a/libavcodec/libvpxenc.c
> +++ b/libavcodec/libvpxenc.c
> @@ -1692,6 +1692,7 @@ static int vpx_encode(AVCodecContext *avctx, AVPacket *pkt,
> const struct vpx_codec_enc_cfg *enccfg = ctx->encoder.config.enc;
> vpx_svc_layer_id_t layer_id;
> int layer_id_valid = 0;
> + unsigned long duration = 0;
>
> if (avctx->qmax >= 0 && enccfg->rc_max_quantizer != avctx->qmax) {
> struct vpx_codec_enc_cfg cfg = *enccfg;
> @@ -1820,8 +1821,18 @@ static int vpx_encode(AVCodecContext *avctx, AVPacket *pkt,
> #endif
> }
>
> + if (frame && frame->duration > ULONG_MAX) {
> + av_log(avctx, AV_LOG_WARNING,
> + "Frame duration too large: %"PRId64"\n", frame->duration);
This could fall back to frame rate or ticks, but I imagine this case
would be unlikely in practice unless the timebase was quite large.
> + } else if (frame && frame->duration)
> + duration = frame->duration;
> + else if (avctx->framerate.num > 0 && avctx->framerate.den > 0)
> + duration = av_rescale_q(1, av_inv_q(avctx->framerate), avctx->time_base);
> + else
> + duration = avctx->ticks_per_frame ? avctx->ticks_per_frame : 1;
> +
> res = vpx_codec_encode(&ctx->encoder, rawimg, timestamp,
> - avctx->ticks_per_frame, flags, ctx->deadline);
> + duration, flags, ctx->deadline);
> if (res != VPX_CODEC_OK) {
> log_encoder_error(avctx, "Error encoding frame");
> return AVERROR_INVALIDDATA;
> @@ -1829,7 +1840,7 @@ static int vpx_encode(AVCodecContext *avctx, AVPacket *pkt,
>
> if (ctx->is_alpha) {
> res = vpx_codec_encode(&ctx->encoder_alpha, rawimg_alpha, timestamp,
> - avctx->ticks_per_frame, flags, ctx->deadline);
> + duration, flags, ctx->deadline);
> if (res != VPX_CODEC_OK) {
> log_encoder_error(avctx, "Error encoding alpha frame");
> return AVERROR_INVALIDDATA;
> --
> 2.39.2
>
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [FFmpeg-devel] [PATCH v2 11/13] lavc/libvpxenc: send frame durations to the encoder
2023-05-09 18:17 ` James Zern
@ 2023-05-10 6:34 ` Anton Khirnov
0 siblings, 0 replies; 35+ messages in thread
From: Anton Khirnov @ 2023-05-10 6:34 UTC (permalink / raw)
To: FFmpeg development discussions and patches
Quoting James Zern (2023-05-09 20:17:37)
> This could fall back to frame rate or ticks, but I imagine this case
> would be unlikely in practice unless the timebase was quite large.
Yeah, I think it's better not to get fancy unless we know it's needed.
Thanks,
--
Anton Khirnov
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [FFmpeg-devel] [PATCH 05/13] lavc/av1*: fix exporting framerate
2023-05-07 13:32 ` [FFmpeg-devel] [PATCH 05/13] lavc/av1*: fix exporting framerate Anton Khirnov
@ 2023-05-10 11:52 ` James Almer
2023-05-14 19:39 ` [FFmpeg-devel] [PATCH] " Anton Khirnov
0 siblings, 1 reply; 35+ messages in thread
From: James Almer @ 2023-05-10 11:52 UTC (permalink / raw)
To: ffmpeg-devel
On 5/7/2023 10:32 AM, Anton Khirnov wrote:
> * take num_ticks_per_picture_minus_1 into account, since that is a part
> of the framerate computation
> * stop exporting num_ticks_per_picture_minus_1 into
> AVCodecContext.ticks_per_frame, as that field is used for other
> purposes (in conjunction with repeat_pict, which is not used at all by
> av1)
> ---
> libavcodec/Makefile | 2 +-
> libavcodec/av1_parse.c | 15 +++++++++++++++
> libavcodec/av1_parse.h | 4 ++++
> libavcodec/av1_parser.c | 9 ++++-----
> libavcodec/av1dec.c | 12 +++---------
> 5 files changed, 27 insertions(+), 15 deletions(-)
>
> diff --git a/libavcodec/Makefile b/libavcodec/Makefile
> index b0971ce833..8162bcf4fa 100644
> --- a/libavcodec/Makefile
> +++ b/libavcodec/Makefile
> @@ -1143,7 +1143,7 @@ OBJS-$(CONFIG_AC3_PARSER) += aac_ac3_parser.o ac3tab.o \
> ac3_channel_layout_tab.o
> OBJS-$(CONFIG_ADX_PARSER) += adx_parser.o
> OBJS-$(CONFIG_AMR_PARSER) += amr_parser.o
> -OBJS-$(CONFIG_AV1_PARSER) += av1_parser.o
> +OBJS-$(CONFIG_AV1_PARSER) += av1_parser.o av1_parse.o
> OBJS-$(CONFIG_AVS2_PARSER) += avs2.o avs2_parser.o
> OBJS-$(CONFIG_AVS3_PARSER) += avs3_parser.o
> OBJS-$(CONFIG_BMP_PARSER) += bmp_parser.o
> diff --git a/libavcodec/av1_parse.c b/libavcodec/av1_parse.c
> index 59ea0bc6e7..cf325e09b9 100644
> --- a/libavcodec/av1_parse.c
> +++ b/libavcodec/av1_parse.c
> @@ -24,6 +24,7 @@
>
> #include "av1.h"
> #include "av1_parse.h"
> +#include "cbs_av1.h"
> #include "bytestream.h"
>
> int ff_av1_extract_obu(AV1OBU *obu, const uint8_t *buf, int length, void *logctx)
> @@ -108,3 +109,17 @@ void ff_av1_packet_uninit(AV1Packet *pkt)
> av_freep(&pkt->obus);
> pkt->obus_allocated = pkt->obus_allocated_size = 0;
> }
> +
> +AVRational ff_av1_framerate(const AV1RawTimingInfo *ti)
Could i ask you to instead pass num_units_in_display_tick, time_scale
and num_ticks_per_picture as arguments to this function, instead of
including cbs_av1 in av1_parse? I devised that module as a lightweight
and reduced alternative to the full bitstream parser that's CBS, used by
the extract_extradata bsf and even included by the av1 demuxer (for the
couple inlined functions in the header).
It should also let you reuse it in libdav1d.c, afaict.
> +{
> + const int ticks = ti->num_ticks_per_picture_minus_1 + 1;
> + AVRational fr = (AVRational){ 0, 1 };
> +
> + if (ti->num_units_in_display_tick && ti->time_scale &&
> + ticks < INT_MAX / ti->num_units_in_display_tick) {
> + av_reduce(&fr.den, &fr.num, ti->num_units_in_display_tick * ticks,
> + ti->time_scale, INT_MAX);
> + }
> +
> + return fr;
> +}
> diff --git a/libavcodec/av1_parse.h b/libavcodec/av1_parse.h
> index f4a5d2830e..60a6fd0ba2 100644
> --- a/libavcodec/av1_parse.h
> +++ b/libavcodec/av1_parse.h
> @@ -181,4 +181,8 @@ static inline int get_obu_bit_length(const uint8_t *buf, int size, int type)
> return size;
> }
>
> +struct AV1RawTimingInfo;
> +
> +AVRational ff_av1_framerate(const struct AV1RawTimingInfo *ti);
> +
> #endif /* AVCODEC_AV1_PARSE_H */
> diff --git a/libavcodec/av1_parser.c b/libavcodec/av1_parser.c
> index 14dae92fe9..978bbebe30 100644
> --- a/libavcodec/av1_parser.c
> +++ b/libavcodec/av1_parser.c
> @@ -21,6 +21,8 @@
> */
>
> #include "libavutil/avassert.h"
> +
> +#include "av1_parse.h"
> #include "cbs.h"
> #include "cbs_av1.h"
> #include "parser.h"
> @@ -162,11 +164,8 @@ static int av1_parser_parse(AVCodecParserContext *ctx,
> avctx->color_trc = (enum AVColorTransferCharacteristic) color->transfer_characteristics;
> avctx->color_range = color->color_range ? AVCOL_RANGE_JPEG : AVCOL_RANGE_MPEG;
>
> - if (seq->timing_info_present_flag) {
> - const AV1RawTimingInfo *timing = &seq->timing_info;
> - av_reduce(&avctx->framerate.den, &avctx->framerate.num,
> - timing->num_units_in_display_tick, timing->time_scale, INT_MAX);
> - }
> + if (seq->timing_info_present_flag)
> + avctx->framerate = ff_av1_framerate(&seq->timing_info);
>
> end:
> ff_cbs_fragment_reset(td);
> diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c
> index c90c9c1a69..693673b436 100644
> --- a/libavcodec/av1dec.c
> +++ b/libavcodec/av1dec.c
> @@ -26,6 +26,7 @@
> #include "libavutil/pixdesc.h"
> #include "libavutil/opt.h"
> #include "avcodec.h"
> +#include "av1_parse.h"
> #include "av1dec.h"
> #include "atsc_a53.h"
> #include "bytestream.h"
> @@ -709,15 +710,8 @@ static int set_context_with_sequence(AVCodecContext *avctx,
> }
> avctx->sample_aspect_ratio = (AVRational) { 1, 1 };
>
> - if (seq->timing_info.num_units_in_display_tick &&
> - seq->timing_info.time_scale) {
> - av_reduce(&avctx->framerate.den, &avctx->framerate.num,
> - seq->timing_info.num_units_in_display_tick,
> - seq->timing_info.time_scale,
> - INT_MAX);
> - if (seq->timing_info.equal_picture_interval)
> - avctx->ticks_per_frame = seq->timing_info.num_ticks_per_picture_minus_1 + 1;
> - }
> + if (seq->timing_info_present_flag)
> + avctx->framerate = ff_av1_framerate(&seq->timing_info);
>
> return 0;
> }
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 35+ messages in thread
* [FFmpeg-devel] [PATCH] lavc/av1*: fix exporting framerate
2023-05-10 11:52 ` James Almer
@ 2023-05-14 19:39 ` Anton Khirnov
2023-05-14 19:50 ` James Almer
0 siblings, 1 reply; 35+ messages in thread
From: Anton Khirnov @ 2023-05-14 19:39 UTC (permalink / raw)
To: ffmpeg-devel
* take num_ticks_per_picture_minus_1 into account, since that is a part
of the framerate computation
* stop exporting num_ticks_per_picture_minus_1 into
AVCodecContext.ticks_per_frame, as that field is used for other
purposes (in conjunction with repeat_pict, which is not used at all by
av1)
---
libavcodec/Makefile | 2 +-
libavcodec/av1_parse.c | 14 ++++++++++++++
libavcodec/av1_parse.h | 3 +++
libavcodec/av1_parser.c | 13 +++++++++----
libavcodec/av1dec.c | 16 ++++++++--------
5 files changed, 35 insertions(+), 13 deletions(-)
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 3cf4444b7e..9587e56493 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1143,7 +1143,7 @@ OBJS-$(CONFIG_AC3_PARSER) += aac_ac3_parser.o ac3tab.o \
ac3_channel_layout_tab.o
OBJS-$(CONFIG_ADX_PARSER) += adx_parser.o
OBJS-$(CONFIG_AMR_PARSER) += amr_parser.o
-OBJS-$(CONFIG_AV1_PARSER) += av1_parser.o
+OBJS-$(CONFIG_AV1_PARSER) += av1_parser.o av1_parse.o
OBJS-$(CONFIG_AVS2_PARSER) += avs2.o avs2_parser.o
OBJS-$(CONFIG_AVS3_PARSER) += avs3_parser.o
OBJS-$(CONFIG_BMP_PARSER) += bmp_parser.o
diff --git a/libavcodec/av1_parse.c b/libavcodec/av1_parse.c
index 59ea0bc6e7..26b70845f2 100644
--- a/libavcodec/av1_parse.c
+++ b/libavcodec/av1_parse.c
@@ -108,3 +108,17 @@ void ff_av1_packet_uninit(AV1Packet *pkt)
av_freep(&pkt->obus);
pkt->obus_allocated = pkt->obus_allocated_size = 0;
}
+
+AVRational ff_av1_framerate(int ticks_per_frame, int units_per_tick,
+ int time_scale)
+{
+ AVRational fr = (AVRational){ 0, 1 };
+
+ if (ticks_per_frame && units_per_tick && time_scale &&
+ ticks_per_frame < INT_MAX / units_per_tick) {
+ av_reduce(&fr.den, &fr.num, units_per_tick * ticks_per_frame,
+ time_scale, INT_MAX);
+ }
+
+ return fr;
+}
diff --git a/libavcodec/av1_parse.h b/libavcodec/av1_parse.h
index f4a5d2830e..11f9c77de4 100644
--- a/libavcodec/av1_parse.h
+++ b/libavcodec/av1_parse.h
@@ -181,4 +181,7 @@ static inline int get_obu_bit_length(const uint8_t *buf, int size, int type)
return size;
}
+AVRational ff_av1_framerate(int ticks_per_frame, int units_per_tick,
+ int time_scale);
+
#endif /* AVCODEC_AV1_PARSE_H */
diff --git a/libavcodec/av1_parser.c b/libavcodec/av1_parser.c
index 14dae92fe9..0d81c29e63 100644
--- a/libavcodec/av1_parser.c
+++ b/libavcodec/av1_parser.c
@@ -21,6 +21,8 @@
*/
#include "libavutil/avassert.h"
+
+#include "av1_parse.h"
#include "cbs.h"
#include "cbs_av1.h"
#include "parser.h"
@@ -162,10 +164,13 @@ static int av1_parser_parse(AVCodecParserContext *ctx,
avctx->color_trc = (enum AVColorTransferCharacteristic) color->transfer_characteristics;
avctx->color_range = color->color_range ? AVCOL_RANGE_JPEG : AVCOL_RANGE_MPEG;
- if (seq->timing_info_present_flag) {
- const AV1RawTimingInfo *timing = &seq->timing_info;
- av_reduce(&avctx->framerate.den, &avctx->framerate.num,
- timing->num_units_in_display_tick, timing->time_scale, INT_MAX);
+ if (seq->timing_info_present_flag &&
+ seq->timing_info.num_ticks_per_picture_minus_1 < INT_MAX - 1 &&
+ seq->timing_info.num_units_in_display_tick < INT_MAX &&
+ seq->timing_info.time_scale < INT_MAX) {
+ avctx->framerate = ff_av1_framerate(seq->timing_info.num_ticks_per_picture_minus_1 + 1,
+ seq->timing_info.num_units_in_display_tick,
+ seq->timing_info.time_scale);
}
end:
diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c
index c90c9c1a69..dae1d8e8da 100644
--- a/libavcodec/av1dec.c
+++ b/libavcodec/av1dec.c
@@ -26,6 +26,7 @@
#include "libavutil/pixdesc.h"
#include "libavutil/opt.h"
#include "avcodec.h"
+#include "av1_parse.h"
#include "av1dec.h"
#include "atsc_a53.h"
#include "bytestream.h"
@@ -709,14 +710,13 @@ static int set_context_with_sequence(AVCodecContext *avctx,
}
avctx->sample_aspect_ratio = (AVRational) { 1, 1 };
- if (seq->timing_info.num_units_in_display_tick &&
- seq->timing_info.time_scale) {
- av_reduce(&avctx->framerate.den, &avctx->framerate.num,
- seq->timing_info.num_units_in_display_tick,
- seq->timing_info.time_scale,
- INT_MAX);
- if (seq->timing_info.equal_picture_interval)
- avctx->ticks_per_frame = seq->timing_info.num_ticks_per_picture_minus_1 + 1;
+ if (seq->timing_info_present_flag &&
+ seq->timing_info.num_ticks_per_picture_minus_1 < INT_MAX - 1 &&
+ seq->timing_info.num_units_in_display_tick < INT_MAX &&
+ seq->timing_info.time_scale < INT_MAX) {
+ avctx->framerate = ff_av1_framerate(seq->timing_info.num_ticks_per_picture_minus_1 + 1,
+ seq->timing_info.num_units_in_display_tick,
+ seq->timing_info.time_scale);
}
return 0;
--
2.39.2
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [FFmpeg-devel] [PATCH] lavc/av1*: fix exporting framerate
2023-05-14 19:39 ` [FFmpeg-devel] [PATCH] " Anton Khirnov
@ 2023-05-14 19:50 ` James Almer
2023-05-15 8:22 ` Anton Khirnov
0 siblings, 1 reply; 35+ messages in thread
From: James Almer @ 2023-05-14 19:50 UTC (permalink / raw)
To: ffmpeg-devel
On 5/14/2023 4:39 PM, Anton Khirnov wrote:
> * take num_ticks_per_picture_minus_1 into account, since that is a part
> of the framerate computation
> * stop exporting num_ticks_per_picture_minus_1 into
> AVCodecContext.ticks_per_frame, as that field is used for other
> purposes (in conjunction with repeat_pict, which is not used at all by
> av1)
> ---
> libavcodec/Makefile | 2 +-
> libavcodec/av1_parse.c | 14 ++++++++++++++
> libavcodec/av1_parse.h | 3 +++
> libavcodec/av1_parser.c | 13 +++++++++----
> libavcodec/av1dec.c | 16 ++++++++--------
> 5 files changed, 35 insertions(+), 13 deletions(-)
>
> diff --git a/libavcodec/Makefile b/libavcodec/Makefile
> index 3cf4444b7e..9587e56493 100644
> --- a/libavcodec/Makefile
> +++ b/libavcodec/Makefile
> @@ -1143,7 +1143,7 @@ OBJS-$(CONFIG_AC3_PARSER) += aac_ac3_parser.o ac3tab.o \
> ac3_channel_layout_tab.o
> OBJS-$(CONFIG_ADX_PARSER) += adx_parser.o
> OBJS-$(CONFIG_AMR_PARSER) += amr_parser.o
> -OBJS-$(CONFIG_AV1_PARSER) += av1_parser.o
> +OBJS-$(CONFIG_AV1_PARSER) += av1_parser.o av1_parse.o
> OBJS-$(CONFIG_AVS2_PARSER) += avs2.o avs2_parser.o
> OBJS-$(CONFIG_AVS3_PARSER) += avs3_parser.o
> OBJS-$(CONFIG_BMP_PARSER) += bmp_parser.o
> diff --git a/libavcodec/av1_parse.c b/libavcodec/av1_parse.c
> index 59ea0bc6e7..26b70845f2 100644
> --- a/libavcodec/av1_parse.c
> +++ b/libavcodec/av1_parse.c
> @@ -108,3 +108,17 @@ void ff_av1_packet_uninit(AV1Packet *pkt)
> av_freep(&pkt->obus);
> pkt->obus_allocated = pkt->obus_allocated_size = 0;
> }
> +
> +AVRational ff_av1_framerate(int ticks_per_frame, int units_per_tick,
> + int time_scale)
> +{
> + AVRational fr = (AVRational){ 0, 1 };
> +
> + if (ticks_per_frame && units_per_tick && time_scale &&
> + ticks_per_frame < INT_MAX / units_per_tick) {
av_reduce takes int64_t as input, so you could just cast units_per_tick.
> + av_reduce(&fr.den, &fr.num, units_per_tick * ticks_per_frame,
> + time_scale, INT_MAX);
> + }
> +
> + return fr;
> +}
> diff --git a/libavcodec/av1_parse.h b/libavcodec/av1_parse.h
> index f4a5d2830e..11f9c77de4 100644
> --- a/libavcodec/av1_parse.h
> +++ b/libavcodec/av1_parse.h
> @@ -181,4 +181,7 @@ static inline int get_obu_bit_length(const uint8_t *buf, int size, int type)
> return size;
> }
>
> +AVRational ff_av1_framerate(int ticks_per_frame, int units_per_tick,
> + int time_scale);
> +
> #endif /* AVCODEC_AV1_PARSE_H */
> diff --git a/libavcodec/av1_parser.c b/libavcodec/av1_parser.c
> index 14dae92fe9..0d81c29e63 100644
> --- a/libavcodec/av1_parser.c
> +++ b/libavcodec/av1_parser.c
> @@ -21,6 +21,8 @@
> */
>
> #include "libavutil/avassert.h"
> +
> +#include "av1_parse.h"
> #include "cbs.h"
> #include "cbs_av1.h"
> #include "parser.h"
> @@ -162,10 +164,13 @@ static int av1_parser_parse(AVCodecParserContext *ctx,
> avctx->color_trc = (enum AVColorTransferCharacteristic) color->transfer_characteristics;
> avctx->color_range = color->color_range ? AVCOL_RANGE_JPEG : AVCOL_RANGE_MPEG;
>
> - if (seq->timing_info_present_flag) {
> - const AV1RawTimingInfo *timing = &seq->timing_info;
> - av_reduce(&avctx->framerate.den, &avctx->framerate.num,
> - timing->num_units_in_display_tick, timing->time_scale, INT_MAX);
> + if (seq->timing_info_present_flag &&
> + seq->timing_info.num_ticks_per_picture_minus_1 < INT_MAX - 1 &&
> + seq->timing_info.num_units_in_display_tick < INT_MAX &&
> + seq->timing_info.time_scale < INT_MAX) {
You could pass all uint32_t values as they are and check the return
value of av_reduce(). If it's 0 (non exact result) then don't set
avctx->framerate (or set it to { 0, 1 }, whatever is cleaner).
There could be samples with bitstream values > INT_MAX where the reduced
AVRational is still within INT_MAX for num and den.
> + avctx->framerate = ff_av1_framerate(seq->timing_info.num_ticks_per_picture_minus_1 + 1,
> + seq->timing_info.num_units_in_display_tick,
> + seq->timing_info.time_scale);
> }
>
> end:
> diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c
> index c90c9c1a69..dae1d8e8da 100644
> --- a/libavcodec/av1dec.c
> +++ b/libavcodec/av1dec.c
> @@ -26,6 +26,7 @@
> #include "libavutil/pixdesc.h"
> #include "libavutil/opt.h"
> #include "avcodec.h"
> +#include "av1_parse.h"
> #include "av1dec.h"
> #include "atsc_a53.h"
> #include "bytestream.h"
> @@ -709,14 +710,13 @@ static int set_context_with_sequence(AVCodecContext *avctx,
> }
> avctx->sample_aspect_ratio = (AVRational) { 1, 1 };
>
> - if (seq->timing_info.num_units_in_display_tick &&
> - seq->timing_info.time_scale) {
> - av_reduce(&avctx->framerate.den, &avctx->framerate.num,
> - seq->timing_info.num_units_in_display_tick,
> - seq->timing_info.time_scale,
> - INT_MAX);
> - if (seq->timing_info.equal_picture_interval)
> - avctx->ticks_per_frame = seq->timing_info.num_ticks_per_picture_minus_1 + 1;
> + if (seq->timing_info_present_flag &&
> + seq->timing_info.num_ticks_per_picture_minus_1 < INT_MAX - 1 &&
> + seq->timing_info.num_units_in_display_tick < INT_MAX &&
> + seq->timing_info.time_scale < INT_MAX) {
> + avctx->framerate = ff_av1_framerate(seq->timing_info.num_ticks_per_picture_minus_1 + 1,
> + seq->timing_info.num_units_in_display_tick,
> + seq->timing_info.time_scale);
> }
>
> return 0;
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 35+ messages in thread
* [FFmpeg-devel] [PATCH] lavc/av1*: fix exporting framerate
2023-05-14 19:50 ` James Almer
@ 2023-05-15 8:22 ` Anton Khirnov
2023-05-15 11:41 ` James Almer
0 siblings, 1 reply; 35+ messages in thread
From: Anton Khirnov @ 2023-05-15 8:22 UTC (permalink / raw)
To: ffmpeg-devel
* take num_ticks_per_picture_minus_1 into account, since that is a part
of the framerate computation
* stop exporting num_ticks_per_picture_minus_1 into
AVCodecContext.ticks_per_frame, as that field is used for other
purposes (in conjunction with repeat_pict, which is not used at all by
av1)
---
libavcodec/Makefile | 2 +-
libavcodec/av1_parse.c | 14 ++++++++++++++
libavcodec/av1_parse.h | 3 +++
libavcodec/av1_parser.c | 11 ++++++-----
libavcodec/av1dec.c | 14 +++++---------
5 files changed, 29 insertions(+), 15 deletions(-)
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 3cf4444b7e..9587e56493 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1143,7 +1143,7 @@ OBJS-$(CONFIG_AC3_PARSER) += aac_ac3_parser.o ac3tab.o \
ac3_channel_layout_tab.o
OBJS-$(CONFIG_ADX_PARSER) += adx_parser.o
OBJS-$(CONFIG_AMR_PARSER) += amr_parser.o
-OBJS-$(CONFIG_AV1_PARSER) += av1_parser.o
+OBJS-$(CONFIG_AV1_PARSER) += av1_parser.o av1_parse.o
OBJS-$(CONFIG_AVS2_PARSER) += avs2.o avs2_parser.o
OBJS-$(CONFIG_AVS3_PARSER) += avs3_parser.o
OBJS-$(CONFIG_BMP_PARSER) += bmp_parser.o
diff --git a/libavcodec/av1_parse.c b/libavcodec/av1_parse.c
index 59ea0bc6e7..136ad1a58f 100644
--- a/libavcodec/av1_parse.c
+++ b/libavcodec/av1_parse.c
@@ -108,3 +108,17 @@ void ff_av1_packet_uninit(AV1Packet *pkt)
av_freep(&pkt->obus);
pkt->obus_allocated = pkt->obus_allocated_size = 0;
}
+
+AVRational ff_av1_framerate(int64_t ticks_per_frame, int64_t units_per_tick,
+ int64_t time_scale)
+{
+ AVRational fr;
+
+ if (ticks_per_frame && units_per_tick && time_scale &&
+ ticks_per_frame < INT64_MAX / units_per_tick &&
+ av_reduce(&fr.den, &fr.num, units_per_tick * ticks_per_frame,
+ time_scale, INT_MAX))
+ return fr;
+
+ return (AVRational){ 0, 1 };
+}
diff --git a/libavcodec/av1_parse.h b/libavcodec/av1_parse.h
index f4a5d2830e..1f3001d2a5 100644
--- a/libavcodec/av1_parse.h
+++ b/libavcodec/av1_parse.h
@@ -181,4 +181,7 @@ static inline int get_obu_bit_length(const uint8_t *buf, int size, int type)
return size;
}
+AVRational ff_av1_framerate(int64_t ticks_per_frame, int64_t units_per_tick,
+ int64_t time_scale);
+
#endif /* AVCODEC_AV1_PARSE_H */
diff --git a/libavcodec/av1_parser.c b/libavcodec/av1_parser.c
index 14dae92fe9..2b79493bf8 100644
--- a/libavcodec/av1_parser.c
+++ b/libavcodec/av1_parser.c
@@ -21,6 +21,8 @@
*/
#include "libavutil/avassert.h"
+
+#include "av1_parse.h"
#include "cbs.h"
#include "cbs_av1.h"
#include "parser.h"
@@ -162,11 +164,10 @@ static int av1_parser_parse(AVCodecParserContext *ctx,
avctx->color_trc = (enum AVColorTransferCharacteristic) color->transfer_characteristics;
avctx->color_range = color->color_range ? AVCOL_RANGE_JPEG : AVCOL_RANGE_MPEG;
- if (seq->timing_info_present_flag) {
- const AV1RawTimingInfo *timing = &seq->timing_info;
- av_reduce(&avctx->framerate.den, &avctx->framerate.num,
- timing->num_units_in_display_tick, timing->time_scale, INT_MAX);
- }
+ if (seq->timing_info_present_flag)
+ avctx->framerate = ff_av1_framerate(1LL + seq->timing_info.num_ticks_per_picture_minus_1,
+ seq->timing_info.num_units_in_display_tick,
+ seq->timing_info.time_scale);
end:
ff_cbs_fragment_reset(td);
diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c
index c90c9c1a69..d46ee48335 100644
--- a/libavcodec/av1dec.c
+++ b/libavcodec/av1dec.c
@@ -26,6 +26,7 @@
#include "libavutil/pixdesc.h"
#include "libavutil/opt.h"
#include "avcodec.h"
+#include "av1_parse.h"
#include "av1dec.h"
#include "atsc_a53.h"
#include "bytestream.h"
@@ -709,15 +710,10 @@ static int set_context_with_sequence(AVCodecContext *avctx,
}
avctx->sample_aspect_ratio = (AVRational) { 1, 1 };
- if (seq->timing_info.num_units_in_display_tick &&
- seq->timing_info.time_scale) {
- av_reduce(&avctx->framerate.den, &avctx->framerate.num,
- seq->timing_info.num_units_in_display_tick,
- seq->timing_info.time_scale,
- INT_MAX);
- if (seq->timing_info.equal_picture_interval)
- avctx->ticks_per_frame = seq->timing_info.num_ticks_per_picture_minus_1 + 1;
- }
+ if (seq->timing_info_present_flag)
+ avctx->framerate = ff_av1_framerate(1LL + seq->timing_info.num_ticks_per_picture_minus_1,
+ seq->timing_info.num_units_in_display_tick,
+ seq->timing_info.time_scale);
return 0;
}
--
2.39.2
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 35+ messages in thread
* [FFmpeg-devel] [PATCH] lavc/libdav1d: fix exporting framerate
2023-05-07 13:32 ` [FFmpeg-devel] [PATCH 06/13] lavc/libdav1d: " Anton Khirnov
@ 2023-05-15 8:22 ` Anton Khirnov
2023-05-15 11:47 ` James Almer
0 siblings, 1 reply; 35+ messages in thread
From: Anton Khirnov @ 2023-05-15 8:22 UTC (permalink / raw)
To: ffmpeg-devel
Same issues as in the previous commit.
---
Updated for changes in previous patch.
---
libavcodec/Makefile | 2 +-
libavcodec/libdav1d.c | 10 ++++------
2 files changed, 5 insertions(+), 7 deletions(-)
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 9587e56493..4d59411662 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1086,7 +1086,7 @@ OBJS-$(CONFIG_LIBARIBCAPTION_DECODER) += libaribcaption.o ass.o
OBJS-$(CONFIG_LIBCELT_DECODER) += libcelt_dec.o
OBJS-$(CONFIG_LIBCODEC2_DECODER) += libcodec2.o
OBJS-$(CONFIG_LIBCODEC2_ENCODER) += libcodec2.o
-OBJS-$(CONFIG_LIBDAV1D_DECODER) += libdav1d.o
+OBJS-$(CONFIG_LIBDAV1D_DECODER) += libdav1d.o av1_parse.o
OBJS-$(CONFIG_LIBDAVS2_DECODER) += libdavs2.o
OBJS-$(CONFIG_LIBFDK_AAC_DECODER) += libfdk-aacdec.o
OBJS-$(CONFIG_LIBFDK_AAC_ENCODER) += libfdk-aacenc.o
diff --git a/libavcodec/libdav1d.c b/libavcodec/libdav1d.c
index af072da681..0320ae7c6c 100644
--- a/libavcodec/libdav1d.c
+++ b/libavcodec/libdav1d.c
@@ -30,6 +30,7 @@
#include "libavutil/opt.h"
#include "atsc_a53.h"
+#include "av1_parse.h"
#include "avcodec.h"
#include "bytestream.h"
#include "codec_internal.h"
@@ -154,12 +155,9 @@ static void libdav1d_init_params(AVCodecContext *c, const Dav1dSequenceHeader *s
else
c->pix_fmt = pix_fmt[seq->layout][seq->hbd];
- if (seq->num_units_in_tick && seq->time_scale) {
- av_reduce(&c->framerate.den, &c->framerate.num,
- seq->num_units_in_tick, seq->time_scale, INT_MAX);
- if (seq->equal_picture_interval)
- c->ticks_per_frame = seq->num_ticks_per_picture;
- }
+ c->framerate = ff_av1_framerate(seq->num_ticks_per_picture,
+ seq->num_units_in_tick,
+ seq->time_scale);
if (seq->film_grain_present)
c->properties |= FF_CODEC_PROPERTY_FILM_GRAIN;
--
2.39.2
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [FFmpeg-devel] [PATCH] lavc/av1*: fix exporting framerate
2023-05-15 8:22 ` Anton Khirnov
@ 2023-05-15 11:41 ` James Almer
0 siblings, 0 replies; 35+ messages in thread
From: James Almer @ 2023-05-15 11:41 UTC (permalink / raw)
To: ffmpeg-devel
On 5/15/2023 5:22 AM, Anton Khirnov wrote:
> * take num_ticks_per_picture_minus_1 into account, since that is a part
> of the framerate computation
> * stop exporting num_ticks_per_picture_minus_1 into
> AVCodecContext.ticks_per_frame, as that field is used for other
> purposes (in conjunction with repeat_pict, which is not used at all by
> av1)
> ---
> libavcodec/Makefile | 2 +-
> libavcodec/av1_parse.c | 14 ++++++++++++++
> libavcodec/av1_parse.h | 3 +++
> libavcodec/av1_parser.c | 11 ++++++-----
> libavcodec/av1dec.c | 14 +++++---------
> 5 files changed, 29 insertions(+), 15 deletions(-)
LGTM
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [FFmpeg-devel] [PATCH] lavc/libdav1d: fix exporting framerate
2023-05-15 8:22 ` [FFmpeg-devel] [PATCH] " Anton Khirnov
@ 2023-05-15 11:47 ` James Almer
2023-05-15 12:22 ` Anton Khirnov
0 siblings, 1 reply; 35+ messages in thread
From: James Almer @ 2023-05-15 11:47 UTC (permalink / raw)
To: ffmpeg-devel
On 5/15/2023 5:22 AM, Anton Khirnov wrote:
> Same issues as in the previous commit.
> ---
> Updated for changes in previous patch.
> ---
> libavcodec/Makefile | 2 +-
> libavcodec/libdav1d.c | 10 ++++------
> 2 files changed, 5 insertions(+), 7 deletions(-)
>
> diff --git a/libavcodec/Makefile b/libavcodec/Makefile
> index 9587e56493..4d59411662 100644
> --- a/libavcodec/Makefile
> +++ b/libavcodec/Makefile
> @@ -1086,7 +1086,7 @@ OBJS-$(CONFIG_LIBARIBCAPTION_DECODER) += libaribcaption.o ass.o
> OBJS-$(CONFIG_LIBCELT_DECODER) += libcelt_dec.o
> OBJS-$(CONFIG_LIBCODEC2_DECODER) += libcodec2.o
> OBJS-$(CONFIG_LIBCODEC2_ENCODER) += libcodec2.o
> -OBJS-$(CONFIG_LIBDAV1D_DECODER) += libdav1d.o
> +OBJS-$(CONFIG_LIBDAV1D_DECODER) += libdav1d.o av1_parse.o
> OBJS-$(CONFIG_LIBDAVS2_DECODER) += libdavs2.o
> OBJS-$(CONFIG_LIBFDK_AAC_DECODER) += libfdk-aacdec.o
> OBJS-$(CONFIG_LIBFDK_AAC_ENCODER) += libfdk-aacenc.o
> diff --git a/libavcodec/libdav1d.c b/libavcodec/libdav1d.c
> index af072da681..0320ae7c6c 100644
> --- a/libavcodec/libdav1d.c
> +++ b/libavcodec/libdav1d.c
> @@ -30,6 +30,7 @@
> #include "libavutil/opt.h"
>
> #include "atsc_a53.h"
> +#include "av1_parse.h"
> #include "avcodec.h"
> #include "bytestream.h"
> #include "codec_internal.h"
> @@ -154,12 +155,9 @@ static void libdav1d_init_params(AVCodecContext *c, const Dav1dSequenceHeader *s
> else
> c->pix_fmt = pix_fmt[seq->layout][seq->hbd];
>
> - if (seq->num_units_in_tick && seq->time_scale) {
> - av_reduce(&c->framerate.den, &c->framerate.num,
> - seq->num_units_in_tick, seq->time_scale, INT_MAX);
> - if (seq->equal_picture_interval)
> - c->ticks_per_frame = seq->num_ticks_per_picture;
> - }
> + c->framerate = ff_av1_framerate(seq->num_ticks_per_picture,
> + seq->num_units_in_tick,
> + seq->time_scale);
libdav1d unfortunately is currently exporting num_units_in_tick and
time_scale as int, so in the (very unlikely but valid) case a value was
> INT_MAX in the bitstream, it will be stored in those as a negative value.
I suppose casting them to unsigned here should be enough.
>
> if (seq->film_grain_present)
> c->properties |= FF_CODEC_PROPERTY_FILM_GRAIN;
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 35+ messages in thread
* [FFmpeg-devel] [PATCH] lavc/libdav1d: fix exporting framerate
2023-05-15 11:47 ` James Almer
@ 2023-05-15 12:22 ` Anton Khirnov
2023-05-15 12:41 ` James Almer
0 siblings, 1 reply; 35+ messages in thread
From: Anton Khirnov @ 2023-05-15 12:22 UTC (permalink / raw)
To: ffmpeg-devel
Same issues as in the previous commit.
---
libavcodec/Makefile | 2 +-
libavcodec/libdav1d.c | 10 ++++------
2 files changed, 5 insertions(+), 7 deletions(-)
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 9587e56493..4d59411662 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1086,7 +1086,7 @@ OBJS-$(CONFIG_LIBARIBCAPTION_DECODER) += libaribcaption.o ass.o
OBJS-$(CONFIG_LIBCELT_DECODER) += libcelt_dec.o
OBJS-$(CONFIG_LIBCODEC2_DECODER) += libcodec2.o
OBJS-$(CONFIG_LIBCODEC2_ENCODER) += libcodec2.o
-OBJS-$(CONFIG_LIBDAV1D_DECODER) += libdav1d.o
+OBJS-$(CONFIG_LIBDAV1D_DECODER) += libdav1d.o av1_parse.o
OBJS-$(CONFIG_LIBDAVS2_DECODER) += libdavs2.o
OBJS-$(CONFIG_LIBFDK_AAC_DECODER) += libfdk-aacdec.o
OBJS-$(CONFIG_LIBFDK_AAC_ENCODER) += libfdk-aacenc.o
diff --git a/libavcodec/libdav1d.c b/libavcodec/libdav1d.c
index af072da681..4c48f0099a 100644
--- a/libavcodec/libdav1d.c
+++ b/libavcodec/libdav1d.c
@@ -30,6 +30,7 @@
#include "libavutil/opt.h"
#include "atsc_a53.h"
+#include "av1_parse.h"
#include "avcodec.h"
#include "bytestream.h"
#include "codec_internal.h"
@@ -154,12 +155,9 @@ static void libdav1d_init_params(AVCodecContext *c, const Dav1dSequenceHeader *s
else
c->pix_fmt = pix_fmt[seq->layout][seq->hbd];
- if (seq->num_units_in_tick && seq->time_scale) {
- av_reduce(&c->framerate.den, &c->framerate.num,
- seq->num_units_in_tick, seq->time_scale, INT_MAX);
- if (seq->equal_picture_interval)
- c->ticks_per_frame = seq->num_ticks_per_picture;
- }
+ c->framerate = ff_av1_framerate(seq->num_ticks_per_picture,
+ (unsigned)seq->num_units_in_tick,
+ (unsigned)seq->time_scale);
if (seq->film_grain_present)
c->properties |= FF_CODEC_PROPERTY_FILM_GRAIN;
--
2.39.2
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [FFmpeg-devel] [PATCH] lavc/libdav1d: fix exporting framerate
2023-05-15 12:22 ` Anton Khirnov
@ 2023-05-15 12:41 ` James Almer
0 siblings, 0 replies; 35+ messages in thread
From: James Almer @ 2023-05-15 12:41 UTC (permalink / raw)
To: ffmpeg-devel
On 5/15/2023 9:22 AM, Anton Khirnov wrote:
> Same issues as in the previous commit.
> ---
> libavcodec/Makefile | 2 +-
> libavcodec/libdav1d.c | 10 ++++------
> 2 files changed, 5 insertions(+), 7 deletions(-)
>
> diff --git a/libavcodec/Makefile b/libavcodec/Makefile
> index 9587e56493..4d59411662 100644
> --- a/libavcodec/Makefile
> +++ b/libavcodec/Makefile
> @@ -1086,7 +1086,7 @@ OBJS-$(CONFIG_LIBARIBCAPTION_DECODER) += libaribcaption.o ass.o
> OBJS-$(CONFIG_LIBCELT_DECODER) += libcelt_dec.o
> OBJS-$(CONFIG_LIBCODEC2_DECODER) += libcodec2.o
> OBJS-$(CONFIG_LIBCODEC2_ENCODER) += libcodec2.o
> -OBJS-$(CONFIG_LIBDAV1D_DECODER) += libdav1d.o
> +OBJS-$(CONFIG_LIBDAV1D_DECODER) += libdav1d.o av1_parse.o
> OBJS-$(CONFIG_LIBDAVS2_DECODER) += libdavs2.o
> OBJS-$(CONFIG_LIBFDK_AAC_DECODER) += libfdk-aacdec.o
> OBJS-$(CONFIG_LIBFDK_AAC_ENCODER) += libfdk-aacenc.o
> diff --git a/libavcodec/libdav1d.c b/libavcodec/libdav1d.c
> index af072da681..4c48f0099a 100644
> --- a/libavcodec/libdav1d.c
> +++ b/libavcodec/libdav1d.c
> @@ -30,6 +30,7 @@
> #include "libavutil/opt.h"
>
> #include "atsc_a53.h"
> +#include "av1_parse.h"
> #include "avcodec.h"
> #include "bytestream.h"
> #include "codec_internal.h"
> @@ -154,12 +155,9 @@ static void libdav1d_init_params(AVCodecContext *c, const Dav1dSequenceHeader *s
> else
> c->pix_fmt = pix_fmt[seq->layout][seq->hbd];
>
> - if (seq->num_units_in_tick && seq->time_scale) {
> - av_reduce(&c->framerate.den, &c->framerate.num,
> - seq->num_units_in_tick, seq->time_scale, INT_MAX);
> - if (seq->equal_picture_interval)
> - c->ticks_per_frame = seq->num_ticks_per_picture;
> - }
> + c->framerate = ff_av1_framerate(seq->num_ticks_per_picture,
> + (unsigned)seq->num_units_in_tick,
> + (unsigned)seq->time_scale);
>
> if (seq->film_grain_present)
> c->properties |= FF_CODEC_PROPERTY_FILM_GRAIN;
LGTM
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [FFmpeg-devel] [PATCH 04/13] lavf: use AV_CODEC_PROP_FIELDS where appropriate
2023-05-09 8:44 ` Anton Khirnov
@ 2023-05-15 18:59 ` Michael Niedermayer
2023-05-15 20:44 ` Anton Khirnov
0 siblings, 1 reply; 35+ messages in thread
From: Michael Niedermayer @ 2023-05-15 18:59 UTC (permalink / raw)
To: FFmpeg development discussions and patches
[-- Attachment #1.1: Type: text/plain, Size: 2389 bytes --]
On Tue, May 09, 2023 at 10:44:50AM +0200, Anton Khirnov wrote:
> Quoting Michael Niedermayer (2023-05-08 16:15:42)
> > On Sun, May 07, 2023 at 03:32:46PM +0200, Anton Khirnov wrote:
> > > H.264 and mpeg12 parsers need to be adjusted at the same time to stop
> > > using the value of AVCodecContext.ticks_per_frame, because it is not set
> > > correctly unless the codec has been opened. Previously this would result
> > > in both the parser and lavf seeing the same incorrect value, which would
> > > cancel out.
> > > Updating lavf and not the parsers would result in correct value in lavf,
> > > but the wrong one in parsers, which would break some tests.
> > > ---
> > > libavcodec/h264_parser.c | 4 ++--
> > > libavcodec/mpegvideo_parser.c | 2 +-
> > > libavformat/avformat.c | 9 ++++++---
> > > libavformat/demux.c | 29 +++++++++++++++++++----------
> > > libavformat/internal.h | 3 +++
> > > 5 files changed, 31 insertions(+), 16 deletions(-)
> >
> > Doesnt this sort of change need a major ABI bump ?
> > it sounds like lavc and lavf interdepend here both ways
>
> No, we do not guarantee bug compatibility.
>
> Libavformat seeing ticks_per_frame=1 for codecs that set it to 2 upon
> being opened is a bug. Same for the parser.
>
> It just so happens that libavformat AND its internal parser instance see
> the same incorrect value and this cancels out in cases that are tested
> by FATE (it would break if we had more thorough tests for repeating
> single fields).
This patch seems to change tbr
./ffmpeg -i fate-suite//h264/lossless.h264
Stream #0:0: Video: h264 (High 4:4:4 Predictive), yuv420p(progressive), 640x480, 25 fps, 60 tbr, 1200k tbn
vs.
Stream #0:0: Video: h264 (High 4:4:4 Predictive), yuv420p(progressive), 640x480, 25 fps, 120 tbr, 1200k tbn
with
./ffmpeg -i fate-suite//h264/lossless.h264 -f framecrc -
The output uses 1/60 thats odd because if every frame can be represented in
1/60 then tbr is 1/60 or more course
OTOH if tbr is finer than 1/60 then not every frame can be represented in 1/60
maybe iam missing something but the new value seems worse and also
not consistent with what ffmpeg actually uses
thx
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Avoid a single point of failure, be that a person or equipment.
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
[-- Attachment #2: Type: text/plain, Size: 251 bytes --]
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [FFmpeg-devel] [PATCH 04/13] lavf: use AV_CODEC_PROP_FIELDS where appropriate
2023-05-15 18:59 ` Michael Niedermayer
@ 2023-05-15 20:44 ` Anton Khirnov
2023-05-16 17:41 ` Michael Niedermayer
0 siblings, 1 reply; 35+ messages in thread
From: Anton Khirnov @ 2023-05-15 20:44 UTC (permalink / raw)
To: FFmpeg development discussions and patches
Quoting Michael Niedermayer (2023-05-15 20:59:42)
> On Tue, May 09, 2023 at 10:44:50AM +0200, Anton Khirnov wrote:
> > Quoting Michael Niedermayer (2023-05-08 16:15:42)
> > > On Sun, May 07, 2023 at 03:32:46PM +0200, Anton Khirnov wrote:
> > > > H.264 and mpeg12 parsers need to be adjusted at the same time to stop
> > > > using the value of AVCodecContext.ticks_per_frame, because it is not set
> > > > correctly unless the codec has been opened. Previously this would result
> > > > in both the parser and lavf seeing the same incorrect value, which would
> > > > cancel out.
> > > > Updating lavf and not the parsers would result in correct value in lavf,
> > > > but the wrong one in parsers, which would break some tests.
> > > > ---
> > > > libavcodec/h264_parser.c | 4 ++--
> > > > libavcodec/mpegvideo_parser.c | 2 +-
> > > > libavformat/avformat.c | 9 ++++++---
> > > > libavformat/demux.c | 29 +++++++++++++++++++----------
> > > > libavformat/internal.h | 3 +++
> > > > 5 files changed, 31 insertions(+), 16 deletions(-)
> > >
> > > Doesnt this sort of change need a major ABI bump ?
> > > it sounds like lavc and lavf interdepend here both ways
> >
> > No, we do not guarantee bug compatibility.
> >
> > Libavformat seeing ticks_per_frame=1 for codecs that set it to 2 upon
> > being opened is a bug. Same for the parser.
> >
> > It just so happens that libavformat AND its internal parser instance see
> > the same incorrect value and this cancels out in cases that are tested
> > by FATE (it would break if we had more thorough tests for repeating
> > single fields).
>
> This patch seems to change tbr
> ./ffmpeg -i fate-suite//h264/lossless.h264
> Stream #0:0: Video: h264 (High 4:4:4 Predictive), yuv420p(progressive), 640x480, 25 fps, 60 tbr, 1200k tbn
> vs.
> Stream #0:0: Video: h264 (High 4:4:4 Predictive), yuv420p(progressive), 640x480, 25 fps, 120 tbr, 1200k tbn
>
> with
> ./ffmpeg -i fate-suite//h264/lossless.h264 -f framecrc -
>
> The output uses 1/60 thats odd because if every frame can be represented in
> 1/60 then tbr is 1/60 or more course
> OTOH if tbr is finer than 1/60 then not every frame can be represented in 1/60
>
> maybe iam missing something but the new value seems worse and also
> not consistent with what ffmpeg actually uses
ticks_per_frame was added by you in 3797c74ba53, and according to your
code it's supposed to be 2 for H.264. It just so happens that for this
specific sample libavformat invokes the parser without opening the
decoder, so it sees the default value of 1. If it did open the decoder,
it would see 2. This patch at least makes it consistent, even if it
might not always be the optimal choice.
As far as I'm concerned, the entire notion of 'tbr' is fundamentally
flawed and should be abandoned. There is no magical way for the code to
know what timebase is truly the right one here, without reading the
whole file.
Furthermore, the entire approach of "some sample X is now getting
slightly worse arbitrary numbers than before" seems highly questionable
to me. Our timestamps code is a unholy mess of hacks upon hacks upon
hacks. For pretty much ANY change one can find or construct a sample
that decodes worse after it. We should stop focusing on individual
samples and prioritize overall consistency and correctness.
--
Anton Khirnov
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [FFmpeg-devel] [PATCH 04/13] lavf: use AV_CODEC_PROP_FIELDS where appropriate
2023-05-15 20:44 ` Anton Khirnov
@ 2023-05-16 17:41 ` Michael Niedermayer
0 siblings, 0 replies; 35+ messages in thread
From: Michael Niedermayer @ 2023-05-16 17:41 UTC (permalink / raw)
To: FFmpeg development discussions and patches
[-- Attachment #1.1: Type: text/plain, Size: 4791 bytes --]
On Mon, May 15, 2023 at 10:44:56PM +0200, Anton Khirnov wrote:
> Quoting Michael Niedermayer (2023-05-15 20:59:42)
> > On Tue, May 09, 2023 at 10:44:50AM +0200, Anton Khirnov wrote:
> > > Quoting Michael Niedermayer (2023-05-08 16:15:42)
> > > > On Sun, May 07, 2023 at 03:32:46PM +0200, Anton Khirnov wrote:
> > > > > H.264 and mpeg12 parsers need to be adjusted at the same time to stop
> > > > > using the value of AVCodecContext.ticks_per_frame, because it is not set
> > > > > correctly unless the codec has been opened. Previously this would result
> > > > > in both the parser and lavf seeing the same incorrect value, which would
> > > > > cancel out.
> > > > > Updating lavf and not the parsers would result in correct value in lavf,
> > > > > but the wrong one in parsers, which would break some tests.
> > > > > ---
> > > > > libavcodec/h264_parser.c | 4 ++--
> > > > > libavcodec/mpegvideo_parser.c | 2 +-
> > > > > libavformat/avformat.c | 9 ++++++---
> > > > > libavformat/demux.c | 29 +++++++++++++++++++----------
> > > > > libavformat/internal.h | 3 +++
> > > > > 5 files changed, 31 insertions(+), 16 deletions(-)
> > > >
> > > > Doesnt this sort of change need a major ABI bump ?
> > > > it sounds like lavc and lavf interdepend here both ways
> > >
> > > No, we do not guarantee bug compatibility.
> > >
> > > Libavformat seeing ticks_per_frame=1 for codecs that set it to 2 upon
> > > being opened is a bug. Same for the parser.
> > >
> > > It just so happens that libavformat AND its internal parser instance see
> > > the same incorrect value and this cancels out in cases that are tested
> > > by FATE (it would break if we had more thorough tests for repeating
> > > single fields).
> >
> > This patch seems to change tbr
> > ./ffmpeg -i fate-suite//h264/lossless.h264
> > Stream #0:0: Video: h264 (High 4:4:4 Predictive), yuv420p(progressive), 640x480, 25 fps, 60 tbr, 1200k tbn
> > vs.
> > Stream #0:0: Video: h264 (High 4:4:4 Predictive), yuv420p(progressive), 640x480, 25 fps, 120 tbr, 1200k tbn
> >
> > with
> > ./ffmpeg -i fate-suite//h264/lossless.h264 -f framecrc -
> >
> > The output uses 1/60 thats odd because if every frame can be represented in
> > 1/60 then tbr is 1/60 or more course
> > OTOH if tbr is finer than 1/60 then not every frame can be represented in 1/60
> >
> > maybe iam missing something but the new value seems worse and also
> > not consistent with what ffmpeg actually uses
>
> ticks_per_frame was added by you in 3797c74ba53, and according to your
> code it's supposed to be 2 for H.264. It just so happens that for this
> specific sample libavformat invokes the parser without opening the
> decoder, so it sees the default value of 1. If it did open the decoder,
> it would see 2. This patch at least makes it consistent, even if it
> might not always be the optimal choice.
Iam not sure how it is consistent if the value used is different than the
value displayed
>
> As far as I'm concerned, the entire notion of 'tbr' is fundamentally
> flawed and should be abandoned. There is no magical way for the code to
> know what timebase is truly the right one here, without reading the
> whole file.
>
> Furthermore, the entire approach of "some sample X is now getting
> slightly worse arbitrary numbers than before" seems highly questionable
> to me. Our timestamps code is a unholy mess of hacks upon hacks upon
> hacks. For pretty much ANY change one can find or construct a sample
> that decodes worse after it. We should stop focusing on individual
> samples and prioritize overall consistency and correctness.
I think the important part is provide the user with what (s)he wants
If more files work better, thats a win.
The world of multimedia is a bit messy in some corners (as you know)
so i am not sure if true beauty, cleanliness and consistency can be
achieved while having well working/fast code
But i certainly support making the code nicer.
about "correctness", iam not even sure what exactly is "correct"
in some cases.
just the recent hls case, the first 4 links i tried used 2 mime types
the rfc would consider wrong. id say adding them is "correct" with
the "SHOULD" recommandition but others surely will disagree
about tbr, i think its a usefull field, It wont be the global optimal
value for some videos but neither would width and height be, if they
change midstream.
But any improvment is good and i support that, in this case here i
saw one file change and i reported it.
Thanks
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
I am the wisest man alive, for I know one thing, and that is that I know
nothing. -- Socrates
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
[-- Attachment #2: Type: text/plain, Size: 251 bytes --]
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 35+ messages in thread
end of thread, other threads:[~2023-05-16 17:41 UTC | newest]
Thread overview: 35+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-07 13:32 [FFmpeg-devel] [PATCH 01/13] lavu/frame: extend AVFrame.repeat_pict documentation Anton Khirnov
2023-05-07 13:32 ` [FFmpeg-devel] [PATCH 02/13] fftools/ffmpeg: fix computing video frame duration from repeat_pict Anton Khirnov
2023-05-07 13:32 ` [FFmpeg-devel] [PATCH 03/13] lavc/codec_desc: add a property for codecs that support field coding Anton Khirnov
2023-05-07 13:32 ` [FFmpeg-devel] [PATCH 04/13] lavf: use AV_CODEC_PROP_FIELDS where appropriate Anton Khirnov
2023-05-08 14:12 ` Michael Niedermayer
2023-05-09 8:37 ` [FFmpeg-devel] [PATCH v2 " Anton Khirnov
2023-05-08 14:15 ` [FFmpeg-devel] [PATCH " Michael Niedermayer
2023-05-09 8:44 ` Anton Khirnov
2023-05-15 18:59 ` Michael Niedermayer
2023-05-15 20:44 ` Anton Khirnov
2023-05-16 17:41 ` Michael Niedermayer
2023-05-07 13:32 ` [FFmpeg-devel] [PATCH 05/13] lavc/av1*: fix exporting framerate Anton Khirnov
2023-05-10 11:52 ` James Almer
2023-05-14 19:39 ` [FFmpeg-devel] [PATCH] " Anton Khirnov
2023-05-14 19:50 ` James Almer
2023-05-15 8:22 ` Anton Khirnov
2023-05-15 11:41 ` James Almer
2023-05-07 13:32 ` [FFmpeg-devel] [PATCH 06/13] lavc/libdav1d: " Anton Khirnov
2023-05-15 8:22 ` [FFmpeg-devel] [PATCH] " Anton Khirnov
2023-05-15 11:47 ` James Almer
2023-05-15 12:22 ` Anton Khirnov
2023-05-15 12:41 ` James Almer
2023-05-07 13:32 ` [FFmpeg-devel] [PATCH 07/13] lavc/ratecontrol: use AVCodecContext.framerate when available Anton Khirnov
2023-05-07 13:32 ` [FFmpeg-devel] [PATCH 08/13] lavc/msmpeg4enc: " Anton Khirnov
2023-05-07 13:32 ` [FFmpeg-devel] [PATCH 09/13] libaomenc: " Anton Khirnov
2023-05-07 13:32 ` [FFmpeg-devel] [PATCH 10/13] lavc/libkvazaar, libopenh264enc: drop redundant checks Anton Khirnov
2023-05-07 13:32 ` [FFmpeg-devel] [PATCH 11/13] lavc/libvpxenc: send frame durations to the encoder Anton Khirnov
2023-05-09 1:18 ` James Zern
2023-05-09 9:09 ` [FFmpeg-devel] [PATCH v2 " Anton Khirnov
2023-05-09 18:17 ` James Zern
2023-05-10 6:34 ` Anton Khirnov
2023-05-07 13:32 ` [FFmpeg-devel] [PATCH 12/13] lavc: deprecate AVCodecContext.ticks_per_frame Anton Khirnov
2023-05-07 13:32 ` [FFmpeg-devel] [PATCH 13/13] fftools/ffmpeg: stop using deprecated ticks_per_frame Anton Khirnov
2023-05-07 16:59 ` [FFmpeg-devel] [PATCH 01/13] lavu/frame: extend AVFrame.repeat_pict documentation Kieran Kunhya
2023-05-07 18:01 ` Anton Khirnov
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git