PR #22364 opened by mkver URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/22364 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/22364.patch
>From 31e813eaa87167266c6cadd8c29cc5247bd18d41 Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt <[email protected]> Date: Fri, 27 Jun 2025 12:09:42 +0200 Subject: [PATCH 1/8] tests/fate/vcodec: Test intra_dc_precision Signed-off-by: Andreas Rheinhardt <[email protected]> --- tests/fate/vcodec.mak | 2 +- tests/ref/vsynth/vsynth1-mpeg2-idct-int | 8 ++++---- tests/ref/vsynth/vsynth2-mpeg2-idct-int | 6 +++--- tests/ref/vsynth/vsynth3-mpeg2-idct-int | 8 ++++---- tests/ref/vsynth/vsynth_lena-mpeg2-idct-int | 6 +++--- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/tests/fate/vcodec.mak b/tests/fate/vcodec.mak index 4a005ec760..0261ca30b6 100644 --- a/tests/fate/vcodec.mak +++ b/tests/fate/vcodec.mak @@ -284,7 +284,7 @@ fate-vsynth%-mpeg2-422: ENCOPTS = -b:v 1000k \ -intra_vlc 1 \ -mbd rd \ -pix_fmt yuv422p -fate-vsynth%-mpeg2-idct-int: ENCOPTS = -qscale 10 -idct int -dct int +fate-vsynth%-mpeg2-idct-int: ENCOPTS = -qscale 10 -idct int -dct int -dc 2 fate-vsynth%-mpeg2-ilace: ENCOPTS = -qscale 10 -flags +ildct+ilme fate-vsynth%-mpeg2-ivlc-qprd: ENCOPTS = -b:v 500k \ -bf 2 \ diff --git a/tests/ref/vsynth/vsynth1-mpeg2-idct-int b/tests/ref/vsynth/vsynth1-mpeg2-idct-int index 89356d060b..8fa2239783 100644 --- a/tests/ref/vsynth/vsynth1-mpeg2-idct-int +++ b/tests/ref/vsynth/vsynth1-mpeg2-idct-int @@ -1,4 +1,4 @@ -b63161625d83d39c9114c7018cac5e9b *tests/data/fate/vsynth1-mpeg2-idct-int.mpeg2video -725668 tests/data/fate/vsynth1-mpeg2-idct-int.mpeg2video -8130f71a467315c9e7bd1a25a01dbb23 *tests/data/fate/vsynth1-mpeg2-idct-int.out.rawvideo -stddev: 7.65 PSNR: 30.45 MAXDIFF: 80 bytes: 7603200/ 7603200 +65a2071d2c2f29991bea7aee25df1a97 *tests/data/fate/vsynth1-mpeg2-idct-int.mpeg2video +731973 tests/data/fate/vsynth1-mpeg2-idct-int.mpeg2video +61489d779b9c18a4de911d7088395402 *tests/data/fate/vsynth1-mpeg2-idct-int.out.rawvideo +stddev: 7.64 PSNR: 30.46 MAXDIFF: 81 bytes: 7603200/ 7603200 diff --git a/tests/ref/vsynth/vsynth2-mpeg2-idct-int b/tests/ref/vsynth/vsynth2-mpeg2-idct-int index 3cbfde939c..4d262e6cb4 100644 --- a/tests/ref/vsynth/vsynth2-mpeg2-idct-int +++ b/tests/ref/vsynth/vsynth2-mpeg2-idct-int @@ -1,4 +1,4 @@ -67a99a21e2b88e22b64d8e3d1b5572e8 *tests/data/fate/vsynth2-mpeg2-idct-int.mpeg2video -267370 tests/data/fate/vsynth2-mpeg2-idct-int.mpeg2video -b750f48d58f157da94613fe92012e7a5 *tests/data/fate/vsynth2-mpeg2-idct-int.out.rawvideo +9a18a664ce47d39066e8d968e9d82c9c *tests/data/fate/vsynth2-mpeg2-idct-int.mpeg2video +272885 tests/data/fate/vsynth2-mpeg2-idct-int.mpeg2video +a58f0769c6672f6877ee8482a3aba39e *tests/data/fate/vsynth2-mpeg2-idct-int.out.rawvideo stddev: 5.56 PSNR: 33.22 MAXDIFF: 77 bytes: 7603200/ 7603200 diff --git a/tests/ref/vsynth/vsynth3-mpeg2-idct-int b/tests/ref/vsynth/vsynth3-mpeg2-idct-int index 3b2f714654..15c07a72ec 100644 --- a/tests/ref/vsynth/vsynth3-mpeg2-idct-int +++ b/tests/ref/vsynth/vsynth3-mpeg2-idct-int @@ -1,4 +1,4 @@ -e79b543bed136bca385b2a870d532870 *tests/data/fate/vsynth3-mpeg2-idct-int.mpeg2video -29614 tests/data/fate/vsynth3-mpeg2-idct-int.mpeg2video -aebaf03348e2e114d9f487101f61fe3d *tests/data/fate/vsynth3-mpeg2-idct-int.out.rawvideo -stddev: 9.10 PSNR: 28.94 MAXDIFF: 65 bytes: 86700/ 86700 +c37cc40f3e7424f2947e22025ebbd8cb *tests/data/fate/vsynth3-mpeg2-idct-int.mpeg2video +30129 tests/data/fate/vsynth3-mpeg2-idct-int.mpeg2video +5f38af6d2887319d2012e184e98e2431 *tests/data/fate/vsynth3-mpeg2-idct-int.out.rawvideo +stddev: 9.10 PSNR: 28.95 MAXDIFF: 67 bytes: 86700/ 86700 diff --git a/tests/ref/vsynth/vsynth_lena-mpeg2-idct-int b/tests/ref/vsynth/vsynth_lena-mpeg2-idct-int index 35269dca14..df83c7281b 100644 --- a/tests/ref/vsynth/vsynth_lena-mpeg2-idct-int +++ b/tests/ref/vsynth/vsynth_lena-mpeg2-idct-int @@ -1,4 +1,4 @@ -505371e1b10f5af01b63b3f57606b26e *tests/data/fate/vsynth_lena-mpeg2-idct-int.mpeg2video -198041 tests/data/fate/vsynth_lena-mpeg2-idct-int.mpeg2video -92794e70e4a19a494f10efe353d9895d *tests/data/fate/vsynth_lena-mpeg2-idct-int.out.rawvideo +35bf200e9305f0274c29bc4b5bd8748d *tests/data/fate/vsynth_lena-mpeg2-idct-int.mpeg2video +203760 tests/data/fate/vsynth_lena-mpeg2-idct-int.mpeg2video +7ce627708c26ee66e2bc2f5aa93ba6ac *tests/data/fate/vsynth_lena-mpeg2-idct-int.out.rawvideo stddev: 4.97 PSNR: 34.19 MAXDIFF: 58 bytes: 7603200/ 7603200 -- 2.52.0 >From 893bd27905d50ccb14ff54440d42c54a3f141148 Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt <[email protected]> Date: Fri, 27 Jun 2025 12:55:33 +0200 Subject: [PATCH 2/8] avcodec/mpegvideo_enc: Inline intra_dc_precision when known Signed-off-by: Andreas Rheinhardt <[email protected]> --- libavcodec/mjpegenc.c | 2 +- libavcodec/mpegvideo_enc.c | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/libavcodec/mjpegenc.c b/libavcodec/mjpegenc.c index c5531b1c9f..ee70e17bcd 100644 --- a/libavcodec/mjpegenc.c +++ b/libavcodec/mjpegenc.c @@ -279,7 +279,7 @@ int ff_mjpeg_encode_stuffing(MPVEncContext *const s) fail: for (int i = 0; i < 3; i++) - s->last_dc[i] = 128 << s->c.intra_dc_precision; + s->last_dc[i] = 128; return ret; } diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index 90ff7bf1cb..c0bae3f3e4 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -3024,7 +3024,7 @@ static int encode_thread(AVCodecContext *c, void *arg){ mb_y = ff_speedhq_mb_y_order_to_mb(mb_y_order, s->c.mb_height, &first_in_slice); if (first_in_slice && mb_y_order != s->c.start_mb_y) ff_speedhq_end_slice(s); - s->last_dc[0] = s->last_dc[1] = s->last_dc[2] = 1024 << s->c.intra_dc_precision; + s->last_dc[0] = s->last_dc[1] = s->last_dc[2] = 1024; } else { mb_y = mb_y_order; } @@ -3882,9 +3882,8 @@ static int encode_picture(MPVMainEncContext *const m, const AVPacket *pkt) s->c. intra_matrix[j] = av_clip_uint8(( luma_matrix[i] * s->c.qscale) >> 3); } s->c.y_dc_scale_table = - s->c.c_dc_scale_table = ff_mpeg12_dc_scale_table[s->c.intra_dc_precision]; - s->c.chroma_intra_matrix[0] = - s->c.intra_matrix[0] = ff_mpeg12_dc_scale_table[s->c.intra_dc_precision][8]; + s->c.c_dc_scale_table = ff_mpeg12_dc_scale_table[0]; + s->c.chroma_intra_matrix[0] = s->c.intra_matrix[0] = 8; } else { static const uint8_t y[32] = {13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13}; static const uint8_t c[32] = {14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14}; -- 2.52.0 >From 713f6fb01ec054eda5ac082f20f9c208b102c418 Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt <[email protected]> Date: Sat, 28 Jun 2025 04:56:18 +0200 Subject: [PATCH 3/8] avcodec/mpegvideo_enc: Move dimension-alignment check to rv10enc.c Signed-off-by: Andreas Rheinhardt <[email protected]> --- libavcodec/mpegvideo_enc.c | 7 ------- libavcodec/rv10enc.c | 12 +++++++++++- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index c0bae3f3e4..23ec03e71e 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -774,13 +774,6 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx) return AVERROR(EINVAL); } - if (s->c.codec_id == AV_CODEC_ID_RV10 && - (avctx->width &15 || - avctx->height&15 )) { - av_log(avctx, AV_LOG_ERROR, "width and height must be a multiple of 16\n"); - return AVERROR(EINVAL); - } - if ((s->c.codec_id == AV_CODEC_ID_WMV1 || s->c.codec_id == AV_CODEC_ID_WMV2) && avctx->width & 1) { diff --git a/libavcodec/rv10enc.c b/libavcodec/rv10enc.c index 534b93fd81..3609d82161 100644 --- a/libavcodec/rv10enc.c +++ b/libavcodec/rv10enc.c @@ -66,6 +66,16 @@ int ff_rv10_encode_picture_header(MPVMainEncContext *const m) return 0; } +static av_cold int rv10_encode_init(AVCodecContext *avctx) +{ + if ((avctx->width | avctx->height) & 15) { + av_log(avctx, AV_LOG_ERROR, "width and height must be a multiple of 16\n"); + return AVERROR(EINVAL); + } + + return ff_mpv_encode_init(avctx); +} + const FFCodec ff_rv10_encoder = { .p.name = "rv10", CODEC_LONG_NAME("RealVideo 1.0"), @@ -74,7 +84,7 @@ const FFCodec ff_rv10_encoder = { .p.priv_class = &ff_mpv_enc_class, .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE, .priv_data_size = sizeof(MPVMainEncContext), - .init = ff_mpv_encode_init, + .init = rv10_encode_init, FF_CODEC_ENCODE_CB(ff_mpv_encode_picture), .close = ff_mpv_encode_end, .caps_internal = FF_CODEC_CAP_INIT_CLEANUP, -- 2.52.0 >From 5e9d6e9f3fc7b82cc0eaa0b521c3f553919ae44f Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt <[email protected]> Date: Sat, 28 Jun 2025 05:03:59 +0200 Subject: [PATCH 4/8] avcodec/rv10enc: Check dimensions once during init Signed-off-by: Andreas Rheinhardt <[email protected]> --- libavcodec/rv10enc.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libavcodec/rv10enc.c b/libavcodec/rv10enc.c index 3609d82161..70a1e3c769 100644 --- a/libavcodec/rv10enc.c +++ b/libavcodec/rv10enc.c @@ -52,11 +52,6 @@ int ff_rv10_encode_picture_header(MPVMainEncContext *const m) /* if multiple packets per frame are sent, the position at which to display the macroblocks is coded here */ if(!full_frame){ - if (s->c.mb_width * s->c.mb_height >= (1U << 12)) { - avpriv_report_missing_feature(s->c.avctx, "Encoding frames with %d (>= 4096) macroblocks", - s->c.mb_width * s->c.mb_height); - return AVERROR(ENOSYS); - } put_bits(&s->pb, 6, 0); /* mb_x */ put_bits(&s->pb, 6, 0); /* mb_y */ put_bits(&s->pb, 12, s->c.mb_width * s->c.mb_height); @@ -72,6 +67,11 @@ static av_cold int rv10_encode_init(AVCodecContext *avctx) av_log(avctx, AV_LOG_ERROR, "width and height must be a multiple of 16\n"); return AVERROR(EINVAL); } + if (avctx->width * avctx->height >= 1U << 20) { + avpriv_report_missing_feature(avctx, "Encoding frames with %d (>= 4096) macroblocks", + avctx->width * avctx->height >> 8); + return AVERROR(ENOSYS); + } return ff_mpv_encode_init(avctx); } -- 2.52.0 >From a8a5fca79f2c5ace2b68db3142db0cd8c17c4a06 Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt <[email protected]> Date: Sat, 28 Jun 2025 05:10:42 +0200 Subject: [PATCH 5/8] avcodec/rv10enc: Set encode_picture_header in rv10_encode_init() Signed-off-by: Andreas Rheinhardt <[email protected]> --- libavcodec/mpegvideo_enc.c | 3 +-- libavcodec/rv10enc.c | 7 +++++-- libavcodec/rv20enc.c | 2 +- libavcodec/{rv10enc.h => rv20enc.h} | 7 +++---- 4 files changed, 10 insertions(+), 9 deletions(-) rename libavcodec/{rv10enc.h => rv20enc.h} (86%) diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index 23ec03e71e..99a697994b 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -72,7 +72,7 @@ #include "mpeg4videoenc.h" #include "internal.h" #include "bytestream.h" -#include "rv10enc.h" +#include "rv20enc.h" #include "libavutil/refstruct.h" #include <limits.h> #include "sp5x.h" @@ -930,7 +930,6 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx) break; #if CONFIG_RV10_ENCODER case AV_CODEC_ID_RV10: - m->encode_picture_header = ff_rv10_encode_picture_header; s->c.out_format = FMT_H263; avctx->delay = 0; s->c.low_delay = 1; diff --git a/libavcodec/rv10enc.c b/libavcodec/rv10enc.c index 70a1e3c769..54941e6acc 100644 --- a/libavcodec/rv10enc.c +++ b/libavcodec/rv10enc.c @@ -29,9 +29,8 @@ #include "mpegvideo.h" #include "mpegvideoenc.h" #include "put_bits.h" -#include "rv10enc.h" -int ff_rv10_encode_picture_header(MPVMainEncContext *const m) +static int rv10_encode_picture_header(MPVMainEncContext *const m) { MPVEncContext *const s = &m->s; int full_frame= 0; @@ -63,6 +62,10 @@ int ff_rv10_encode_picture_header(MPVMainEncContext *const m) static av_cold int rv10_encode_init(AVCodecContext *avctx) { + MPVMainEncContext *const m = avctx->priv_data; + + m->encode_picture_header = rv10_encode_picture_header; + if ((avctx->width | avctx->height) & 15) { av_log(avctx, AV_LOG_ERROR, "width and height must be a multiple of 16\n"); return AVERROR(EINVAL); diff --git a/libavcodec/rv20enc.c b/libavcodec/rv20enc.c index 8bf93e7c09..835dc7b4c8 100644 --- a/libavcodec/rv20enc.c +++ b/libavcodec/rv20enc.c @@ -32,7 +32,7 @@ #include "h263data.h" #include "h263enc.h" #include "put_bits.h" -#include "rv10enc.h" +#include "rv20enc.h" int ff_rv20_encode_picture_header(MPVMainEncContext *const m) { diff --git a/libavcodec/rv10enc.h b/libavcodec/rv20enc.h similarity index 86% rename from libavcodec/rv10enc.h rename to libavcodec/rv20enc.h index 5aa7250e87..e70f1ddfd1 100644 --- a/libavcodec/rv10enc.h +++ b/libavcodec/rv20enc.h @@ -18,12 +18,11 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef AVCODEC_RV10ENC_H -#define AVCODEC_RV10ENC_H +#ifndef AVCODEC_RV20ENC_H +#define AVCODEC_RV20ENC_H typedef struct MPVMainEncContext MPVMainEncContext; -int ff_rv10_encode_picture_header(MPVMainEncContext *m); int ff_rv20_encode_picture_header(MPVMainEncContext *m); -#endif /* AVCODEC_RV10ENC_H */ +#endif /* AVCODEC_RV20ENC_H */ -- 2.52.0 >From e7ed188de148cdc343ea06f72e790d507817a85d Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt <[email protected]> Date: Thu, 3 Jul 2025 01:08:12 +0200 Subject: [PATCH 6/8] avcodec/mpegvideo_enc: Ignore intra_dc_precision for non-MPEG-2 This option is only allowed to be set for MPEG-2, so ignore it except for MPEG-2 and move handling of it to mpeg12enc.c. This is in preparation for deprecating the AVCodecContext option. Signed-off-by: Andreas Rheinhardt <[email protected]> --- libavcodec/mpeg12enc.c | 23 +++++++++++++++++++++++ libavcodec/mpeg12enc.h | 10 ---------- libavcodec/mpegvideo_enc.c | 20 -------------------- 3 files changed, 23 insertions(+), 30 deletions(-) diff --git a/libavcodec/mpeg12enc.c b/libavcodec/mpeg12enc.c index 3baadbcfeb..c4a16d1508 100644 --- a/libavcodec/mpeg12enc.c +++ b/libavcodec/mpeg12enc.c @@ -47,6 +47,7 @@ #include "mpeg12vlc.h" #include "mpegutils.h" #include "mpegvideo.h" +#include "mpegvideodata.h" #include "mpegvideoenc.h" #include "profiles.h" #include "put_bits.h" @@ -1125,7 +1126,29 @@ static av_cold int encode_init(AVCodecContext *avctx) s->min_qcoeff = -2047; s->max_qcoeff = 2047; s->mpeg_quant = 1; + + s->c.intra_dc_precision = avctx->intra_dc_precision; + // workaround some differences between how applications specify dc precision + if (s->c.intra_dc_precision < 0) { + s->c.intra_dc_precision += 8; + } else if (s->c.intra_dc_precision >= 8) + s->c.intra_dc_precision -= 8; + + if (s->c.intra_dc_precision < 0) { + av_log(avctx, AV_LOG_ERROR, + "intra dc precision must be positive, note some applications use" + " 0 and some 8 as base meaning 8bit, the value must not be smaller than that\n"); + return AVERROR(EINVAL); + } + + if (s->c.intra_dc_precision > 3) { + av_log(avctx, AV_LOG_ERROR, "intra dc precision too large\n"); + return AVERROR(EINVAL); + } } + s->c.y_dc_scale_table = + s->c.c_dc_scale_table = ff_mpeg12_dc_scale_table[s->c.intra_dc_precision]; + if (s->c.intra_vlc_format) { s->intra_ac_vlc_length = s->intra_ac_vlc_last_length = uni_mpeg2_ac_vlc_len; diff --git a/libavcodec/mpeg12enc.h b/libavcodec/mpeg12enc.h index e04c7dea38..89ac6a0643 100644 --- a/libavcodec/mpeg12enc.h +++ b/libavcodec/mpeg12enc.h @@ -22,20 +22,10 @@ #ifndef AVCODEC_MPEG12ENC_H #define AVCODEC_MPEG12ENC_H -#include <stdint.h> - #include "mpegvideoenc.h" -#include "mpegvideodata.h" void ff_mpeg1_encode_slice_header(MPVEncContext *s); -// Must not be called before intra_dc_precision has been sanitized in ff_mpv_encode_init() -static inline void ff_mpeg1_encode_init(MPVEncContext *s) -{ - s->c.y_dc_scale_table = - s->c.c_dc_scale_table = ff_mpeg12_dc_scale_table[s->c.intra_dc_precision]; -} - static inline void ff_mpeg1_clean_buffers(MPVEncContext *s) { s->last_dc[0] = 128 << s->c.intra_dc_precision; diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index 99a697994b..83bc4cee09 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -608,25 +608,6 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx) s->c.quarter_sample = (avctx->flags & AV_CODEC_FLAG_QPEL) != 0; s->rtp_mode = !!s->rtp_payload_size; - s->c.intra_dc_precision = avctx->intra_dc_precision; - - // workaround some differences between how applications specify dc precision - if (s->c.intra_dc_precision < 0) { - s->c.intra_dc_precision += 8; - } else if (s->c.intra_dc_precision >= 8) - s->c.intra_dc_precision -= 8; - - if (s->c.intra_dc_precision < 0) { - av_log(avctx, AV_LOG_ERROR, - "intra dc precision must be positive, note some applications use" - " 0 and some 8 as base meaning 8bit, the value must not be smaller than that\n"); - return AVERROR(EINVAL); - } - - if (s->c.intra_dc_precision > (avctx->codec_id == AV_CODEC_ID_MPEG2VIDEO ? 3 : 0)) { - av_log(avctx, AV_LOG_ERROR, "intra dc precision too large\n"); - return AVERROR(EINVAL); - } m->user_specified_pts = AV_NOPTS_VALUE; if (m->gop_size <= 1) { @@ -867,7 +848,6 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx) s->c.out_format = FMT_MPEG1; s->c.low_delay = !!(avctx->flags & AV_CODEC_FLAG_LOW_DELAY); avctx->delay = s->c.low_delay ? 0 : (m->max_b_frames + 1); - ff_mpeg1_encode_init(s); break; #endif #if CONFIG_MJPEG_ENCODER || CONFIG_AMV_ENCODER -- 2.52.0 >From e18c5830e0e61cf597e394babc1051dc4fd96367 Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt <[email protected]> Date: Thu, 3 Jul 2025 02:31:52 +0200 Subject: [PATCH 7/8] avcodec/avcodec: Deprecate intra_dc_precision It is only used by the MPEG-2 encoder, so replace it by a private option instead. Use a more elaborate term for it: intra_dc_precision ("dc" could be anything). Signed-off-by: Andreas Rheinhardt <[email protected]> --- doc/APIchanges | 3 +++ libavcodec/avcodec.h | 4 ++++ libavcodec/mpeg12enc.c | 12 +++++++++++- libavcodec/options_table.h | 4 +++- libavcodec/version_major.h | 1 + tests/fate/lavf-container.mak | 2 +- tests/fate/vcodec.mak | 2 +- 7 files changed, 24 insertions(+), 4 deletions(-) diff --git a/doc/APIchanges b/doc/APIchanges index 88005bb28e..2ba86ab0a3 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -2,6 +2,9 @@ The last version increases of all libraries were on 2025-03-28 API changes, most recent first: +2026-03-03 - xxxxxxxxxx - lavc 62.x.100 - avcodec.h + Deprecate AVCodecContext.intra_dc_precision. + 2026-02-xx - xxxxxxxxxx - lsws 9.4.100 - swscale.h Add sws_test_hw_format(). diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 1a8f77af82..6824bfc9a6 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -971,12 +971,16 @@ typedef struct AVCodecContext { */ uint16_t *chroma_intra_matrix; +#if FF_API_INTRA_DC_PRECISION /** * precision of the intra DC coefficient - 8 * - encoding: Set by user. * - decoding: Set by libavcodec + * @deprecated Use the MPEG-2 encoder's private option "intra_dc_precision" instead. */ + attribute_deprecated int intra_dc_precision; +#endif /** * minimum MB Lagrange multiplier diff --git a/libavcodec/mpeg12enc.c b/libavcodec/mpeg12enc.c index c4a16d1508..7537327149 100644 --- a/libavcodec/mpeg12enc.c +++ b/libavcodec/mpeg12enc.c @@ -1126,8 +1126,11 @@ static av_cold int encode_init(AVCodecContext *avctx) s->min_qcoeff = -2047; s->max_qcoeff = 2047; s->mpeg_quant = 1; - +#if FF_API_INTRA_DC_PRECISION + if (s->c.intra_dc_precision < 0) { +FF_DISABLE_DEPRECATION_WARNINGS s->c.intra_dc_precision = avctx->intra_dc_precision; +FF_ENABLE_DEPRECATION_WARNINGS // workaround some differences between how applications specify dc precision if (s->c.intra_dc_precision < 0) { s->c.intra_dc_precision += 8; @@ -1145,6 +1148,8 @@ static av_cold int encode_init(AVCodecContext *avctx) av_log(avctx, AV_LOG_ERROR, "intra dc precision too large\n"); return AVERROR(EINVAL); } + } +#endif } s->c.y_dc_scale_table = s->c.c_dc_scale_table = ff_mpeg12_dc_scale_table[s->c.intra_dc_precision]; @@ -1254,6 +1259,11 @@ static const AVOption mpeg1_options[] = { static const AVOption mpeg2_options[] = { COMMON_OPTS +#if FF_API_INTRA_DC_PRECISION + { "intra_dc_precision", "Precision of the DC coefficient - 8", FF_MPV_OFFSET(c.intra_dc_precision), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 3, VE }, +#else + { "intra_dc_precision", "Precision of the DC coefficient - 8", FF_MPV_OFFSET(c.intra_dc_precision), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 3, VE }, +#endif { "intra_vlc", "Use MPEG-2 intra VLC table.", FF_MPV_OFFSET(c.intra_vlc_format), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE }, { "non_linear_quant", "Use nonlinear quantizer.", FF_MPV_OFFSET(c.q_scale_type), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE }, diff --git a/libavcodec/options_table.h b/libavcodec/options_table.h index 8567451919..99e7002076 100644 --- a/libavcodec/options_table.h +++ b/libavcodec/options_table.h @@ -214,7 +214,9 @@ static const AVOption avcodec_options[] = { {"rc_init_occupancy", "number of bits which should be loaded into the rc buffer before decoding starts", OFFSET(rc_initial_buffer_occupancy), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, INT_MIN, INT_MAX, V|E}, {"threads", "set the number of threads", OFFSET(thread_count), AV_OPT_TYPE_INT, {.i64 = 1 }, 0, INT_MAX, V|A|E|D, .unit = "threads"}, {"auto", "autodetect a suitable number of threads to use", 0, AV_OPT_TYPE_CONST, {.i64 = 0 }, INT_MIN, INT_MAX, V|E|D, .unit = "threads"}, -{"dc", "intra_dc_precision", OFFSET(intra_dc_precision), AV_OPT_TYPE_INT, {.i64 = 0 }, -8, 16, V|E}, +#if FF_API_INTRA_DC_PRECISION +{"dc", "deprecated; use intra_dc_precision for MPEG-2 instead", OFFSET(intra_dc_precision), AV_OPT_TYPE_INT, {.i64 = 0 }, -8, 16, AV_OPT_FLAG_DEPRECATED|V|E}, +#endif {"nssew", "nsse weight", OFFSET(nsse_weight), AV_OPT_TYPE_INT, {.i64 = 8 }, INT_MIN, INT_MAX, V|E}, {"skip_top", "number of macroblock rows at the top which are skipped", OFFSET(skip_top), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, INT_MIN, INT_MAX, V|D}, {"skip_bottom", "number of macroblock rows at the bottom which are skipped", OFFSET(skip_bottom), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, INT_MIN, INT_MAX, V|D}, diff --git a/libavcodec/version_major.h b/libavcodec/version_major.h index 5eed53e038..6c652374dd 100644 --- a/libavcodec/version_major.h +++ b/libavcodec/version_major.h @@ -42,6 +42,7 @@ #define FF_API_V408_CODECID (LIBAVCODEC_VERSION_MAJOR < 63) #define FF_API_CODEC_PROPS (LIBAVCODEC_VERSION_MAJOR < 63) #define FF_API_EXR_GAMMA (LIBAVCODEC_VERSION_MAJOR < 63) +#define FF_API_INTRA_DC_PRECISION (LIBAVCODEC_VERSION_MAJOR < 63) #define FF_API_NVDEC_OLD_PIX_FMTS (LIBAVCODEC_VERSION_MAJOR < 63) diff --git a/tests/fate/lavf-container.mak b/tests/fate/lavf-container.mak index d1007a428a..6194f18f28 100644 --- a/tests/fate/lavf-container.mak +++ b/tests/fate/lavf-container.mak @@ -55,7 +55,7 @@ fate-lavf-mov_hybrid_frag: CMD = lavf_container "" "-movflags +hybrid_fragmented fate-lavf-mp4: CMD = lavf_container_timecode "-c:v mpeg4 -an -threads 1" fate-lavf-mpg: CMD = lavf_container_timecode "-ar 44100 -threads 1" fate-lavf-mxf: CMD = lavf_container_timecode "-af aresample=48000:tsf=s16p -bf 2 -threads 1" -fate-lavf-mxf_d10: CMD = lavf_container "-ar 48000 -ac 2" "-r 25 -vf scale=720:576,pad=720:608:0:32,setfield=tff -c:v mpeg2video -g 0 -flags +ildct+low_delay -dc 10 -non_linear_quant 1 -intra_vlc 1 -qscale 1 -ps 1 -qmin 1 -rc_max_vbv_use 1 -rc_min_vbv_use 1 -pix_fmt yuv422p -minrate 30000k -maxrate 30000k -b 30000k -bufsize 1200000 -rc_init_occupancy 1200000 -qmax 12 -f mxf_d10" +fate-lavf-mxf_d10: CMD = lavf_container "-ar 48000 -ac 2" "-r 25 -vf scale=720:576,pad=720:608:0:32,setfield=tff -c:v mpeg2video -g 0 -flags +ildct+low_delay -intra_dc_precision 2 -non_linear_quant 1 -intra_vlc 1 -qscale 1 -ps 1 -qmin 1 -rc_max_vbv_use 1 -rc_min_vbv_use 1 -pix_fmt yuv422p -minrate 30000k -maxrate 30000k -b 30000k -bufsize 1200000 -rc_init_occupancy 1200000 -qmax 12 -f mxf_d10" fate-lavf-mxf_dv25: CMD = lavf_container "-ar 48000 -ac 2" "-r 25 -vf scale=720:576,setdar=4/3,setfield=bff -c:v dvvideo -pix_fmt yuv420p -b 25000k -f mxf" fate-lavf-mxf_dvcpro50: CMD = lavf_container "-ar 48000 -ac 2" "-r 25 -vf scale=720:576,setdar=16/9,setfield=bff -c:v dvvideo -pix_fmt yuv422p -b 50000k -f mxf" fate-lavf-mxf_dvcpro100: CMD = lavf_container "-ar 48000 -ac 2" "-r 25 -vf scale=1440:1080,setdar=16/9,setfield=bff -c:v dvvideo -pix_fmt yuv422p -b 100000k -f mxf" diff --git a/tests/fate/vcodec.mak b/tests/fate/vcodec.mak index 0261ca30b6..895d5d55bc 100644 --- a/tests/fate/vcodec.mak +++ b/tests/fate/vcodec.mak @@ -284,7 +284,7 @@ fate-vsynth%-mpeg2-422: ENCOPTS = -b:v 1000k \ -intra_vlc 1 \ -mbd rd \ -pix_fmt yuv422p -fate-vsynth%-mpeg2-idct-int: ENCOPTS = -qscale 10 -idct int -dct int -dc 2 +fate-vsynth%-mpeg2-idct-int: ENCOPTS = -qscale 10 -idct int -dct int -intra_dc_precision 2 fate-vsynth%-mpeg2-ilace: ENCOPTS = -qscale 10 -flags +ildct+ilme fate-vsynth%-mpeg2-ivlc-qprd: ENCOPTS = -b:v 500k \ -bf 2 \ -- 2.52.0 >From a6d5197d25d7857bd2634dc4afe7cbb8ff2a9914 Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt <[email protected]> Date: Thu, 3 Jul 2025 11:56:24 +0200 Subject: [PATCH 8/8] avcodec/h261dec: Don't pretend decoding a skipped macroblock can fail Signed-off-by: Andreas Rheinhardt <[email protected]> --- libavcodec/h261dec.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/libavcodec/h261dec.c b/libavcodec/h261dec.c index a25595faf6..566143cc5d 100644 --- a/libavcodec/h261dec.c +++ b/libavcodec/h261dec.c @@ -182,9 +182,8 @@ static int h261_decode_gob_header(H261DecContext *h) /** * Decode skipped macroblocks. - * @return 0 */ -static int h261_decode_mb_skipped(H261DecContext *h, int mba1, int mba2) +static void h261_decode_mb_skipped(H261DecContext *h, int mba1, int mba2) { MpegEncContext *const s = &h->s; int i; @@ -219,8 +218,6 @@ static int h261_decode_mb_skipped(H261DecContext *h, int mba1, int mba2) ff_mpv_reconstruct_mb(s, h->block); } - - return 0; } static int decode_mv_component(GetBitContext *gb, int v) -- 2.52.0 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
