[FFmpeg-devel] Misc mpegvideo patches
Andreas Rheinhardt
andreas.rheinhardt at outlook.com
Tue Mar 4 23:06:28 EET 2025
Ramiro Polla:
> On Tue, Mar 4, 2025 at 6:05 PM Andreas Rheinhardt
> <andreas.rheinhardt at outlook.com> wrote:
>> Ramiro Polla:
>>>
>>> On 3/4/25 14:42, Andreas Rheinhardt wrote:
>>>> (Mostly trivial) patches attached. A branch is at
>>>> https://github.com/mkver/FFmpeg/tree/mpegvideo_misc
>>>
>>>
>>> [PATCH 10/40] avcodec/mpegvideo_enc: Move default_mv_penalty to h261enc.c
>>>
>>>> diff --git a/libavcodec/h261enc.c b/libavcodec/h261enc.c
>>>> index dabab9d80a..e33bf35a8a 100644
>>>> --- a/libavcodec/h261enc.c
>>>> +++ b/libavcodec/h261enc.c
>>>> @@ -46,6 +46,7 @@ static struct VLCLUT {
>>>> uint16_t code;
>>>> } vlc_lut[H261_MAX_RUN + 1][32 /* 0..2 * H261_MAX_LEN are used */];
>>>>
>>>> +static uint8_t mv_penalty[MAX_FCODE + 1][MAX_DMV * 2 + 1];
>>>> static uint8_t uni_h261_rl_len [64 * 128];
>>>> static uint8_t uni_h261_rl_len_last[64 * 128];
>>>> static uint8_t h261_mv_codes[64][2];
>>>> @@ -370,6 +371,8 @@ av_cold int ff_h261_encode_init(MpegEncContext *s)
>>>> s->max_qcoeff = 127;
>>>> s->ac_esc_length = H261_ESC_LEN;
>>>>
>>>> + s->me.mv_penalty = mv_penalty;
>>>> +
>>>> s->intra_ac_vlc_length = s->inter_ac_vlc_length =
>>>> uni_h261_rl_len;
>>>> s->intra_ac_vlc_last_length = s->inter_ac_vlc_last_length =
>>>> uni_h261_rl_len_last;
>>>> ff_thread_once(&init_static_once, h261_encode_init_static);
>>>
>>> This global mv_penalty doesn't seem to be ever initialized; it could be
>>> declared const.
>>
>> But then it would no longer be placed in .bss, but instead in .rodata
>> and increase binary size.
>
> Wow, that's a huge array.
>
>>> But it also makes me think that whatever code is using this mv_penalty,
>>> which is always set to zero, might be calculating things wrong.
>>>
>>
>> It is obviously done to avoid branches for the codecs that matter. H.261
>> does not matter much. Apart from that, it is a very cheap workaround
>> given that this table is .bss.
>
> Could you add some comments (either next to the declaration or the
> commit message) to reflect this? (save space from .rodata, and this
> being a noop for h.261, which doesn't matter that much)
>
>>> [PATCH 15/40] avcodec/ituh263enc: Make SVQ1+Snowenc stop calling
>>> ff_h263_encode_init()
>>>
>>>> diff --git a/libavcodec/ituh263enc.c b/libavcodec/ituh263enc.c
>>>> index 02da090ba4..8313b2c2c1 100644
>>>> --- a/libavcodec/ituh263enc.c
>>>> +++ b/libavcodec/ituh263enc.c
>>>> @@ -65,6 +65,127 @@ static uint8_t uni_h263_inter_rl_len [64*64*2*2];
>>> [...]
>>>> +static av_cold void h263_encode_init_static(void)
>>>> +{
>>>> + static uint8_t rl_intra_table[2][2 * MAX_RUN + MAX_LEVEL + 3];
>>>> +
>>>> + ff_rl_init(&ff_rl_intra_aic, rl_intra_table);
>>>> + ff_h263_init_rl_inter();
>>>> +
>>>> + init_uni_h263_rl_tab(&ff_rl_intra_aic, uni_h263_intra_aic_rl_len);
>>>> + init_uni_h263_rl_tab(&ff_h263_rl_inter, uni_h263_inter_rl_len);
>>>> +
>>>> + init_mv_penalty_and_fcode();
>>>> +}
>>>> +
>>>> +av_cold const uint8_t (*ff_h263_get_mv_penalty(void))[MAX_DMV*2+1]
>>>> +{
>>>> + static AVOnce init_static_once = AV_ONCE_INIT;
>>>> +
>>>> + ff_thread_once(&init_static_once, h263_encode_init_static);
>>>> +
>>>> + return mv_penalty;
>>>> +}
>>>> +
>>>
>>> This approach kind of hides the rest of h263_encode_init_static() inside
>>> ff_h263_get_mv_penalty(), so the name is a bit misleading. I'd expect
>>> h263 to still call some init function and ff_h263_get_mv_penalty(), and
>>> SVQ1 and Snow to only call ff_h263_get_mv_penalty(), which would only
>>> take care of the mv_penalty table.
>>>
>>
>> This would entail using another AVOnce etc. and this level of
>> granularity is just not worth it.
>
> Ok.
>
>> The name is chosen for what it does for an outsider (i.e. from the
>> perspective of svq1enc or snowenc, not the actual H.263 based encoders).
>
> I'm still not quite happy with the name and how it's used, but it's
> good enough so I won't insist.
>
>>> [PATCH 20/40] avcodec/mpeg4video: Split ff_mpeg4_pred_dc()
>>>
>>>> diff --git a/libavcodec/mpeg4videoenc.c b/libavcodec/mpeg4videoenc.c
>>>> index 64fb96a0cf..26f9b40ff7 100644
>>>> --- a/libavcodec/mpeg4videoenc.c
>>>> +++ b/libavcodec/mpeg4videoenc.c
>>>> @@ -806,8 +806,14 @@ void ff_mpeg4_encode_mb(MpegEncContext *s,
>>>> int16_t block[6][64],
>>>> const uint8_t *scan_table[6];
>>>> int i;
>>>>
>>>> - for (i = 0; i < 6; i++)
>>>> - dc_diff[i] = ff_mpeg4_pred_dc(s, i, block[i][0], &dir[i],
>>>> 1);
>>>> + for (int i = 0; i < 6; i++) {
>>>
>>> Redeclaring i inside for.
>>
>> There are other loops which use this i as loop variable. The shadowing
>> is IMO less bad than keeping loops in their current form (with iterators
>> that don't have loop-scope).
>
> Agreed. I also prefer scoped iterators.
I added a comment to #10 and modified #18 as described. I also changed
#21 to protect the macro in parentheses and simplified the FF_RC_OFFSET
macro in #31. Furthermore, there are now five more patches. All
attached. https://github.com/mkver/FFmpeg/tree/mpegvideo_misc has been
force-pushed.
- Andreas
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-avcodec-rv34-Make-ff_rv34_get_start_offset-honor-its.patch
Type: text/x-patch
Size: 2551 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20250304/11157837/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0002-avcodec-vc1_block-vc1dec-Don-t-use-c_dc_scale-_table.patch
Type: text/x-patch
Size: 6538 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20250304/11157837/attachment-0001.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0003-avcodec-vc1_block-Inline-y_dc_scale_table.patch
Type: text/x-patch
Size: 5796 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20250304/11157837/attachment-0002.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0004-avcodec-vc1dec-Don-t-initialize-unused-parts-of-Scan.patch
Type: text/x-patch
Size: 1088 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20250304/11157837/attachment-0003.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0005-avcodec-Remove-leftover-alpha-declarations.patch
Type: text/x-patch
Size: 4178 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20250304/11157837/attachment-0004.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0006-avcodec-mpeg12dec-Don-t-count-errors-from-first-thre.patch
Type: text/x-patch
Size: 3395 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20250304/11157837/attachment-0005.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0007-avcodec-mpeg12dec-Mark-flush-as-cold.patch
Type: text/x-patch
Size: 797 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20250304/11157837/attachment-0006.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0008-avcodec-h261dec-Don-t-call-ff_set_qscale.patch
Type: text/x-patch
Size: 1544 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20250304/11157837/attachment-0007.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0009-avcodec-h261-Use-forward-declaration-for-MpegEncCont.patch
Type: text/x-patch
Size: 1036 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20250304/11157837/attachment-0008.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0010-avcodec-mpegvideo_enc-Move-default_mv_penalty-to-h26.patch
Type: text/x-patch
Size: 2694 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20250304/11157837/attachment-0009.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0011-avcodec-mpegutils-Move-MAX_FCODE-to-mpegvideoenc.h.patch
Type: text/x-patch
Size: 1138 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20250304/11157837/attachment-0010.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0012-avcodec-ituh263enc-Move-MPEG-4-fcode_tab-to-mpeg4vid.patch
Type: text/x-patch
Size: 2959 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20250304/11157837/attachment-0011.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0013-avcodec-ituh263enc-Remove-redundant-setting-of-dc_sc.patch
Type: text/x-patch
Size: 1170 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20250304/11157837/attachment-0012.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0014-avcodec-ituh263enc-Combine-branches.patch
Type: text/x-patch
Size: 1260 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20250304/11157837/attachment-0013.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0015-avcodec-ituh263enc-Make-SVQ1-Snowenc-stop-calling-ff.patch
Type: text/x-patch
Size: 10809 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20250304/11157837/attachment-0014.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0016-avcodec-ituh263enc-Use-memset-where-appropriate.patch
Type: text/x-patch
Size: 1035 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20250304/11157837/attachment-0015.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0017-avcodec-flvenc-Remove-redundant-setting-of-dc_scale_.patch
Type: text/x-patch
Size: 1474 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20250304/11157837/attachment-0016.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0018-avcodec-ituh263dec-Reorder-branches.patch
Type: text/x-patch
Size: 1499 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20250304/11157837/attachment-0017.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0019-avcodec-mpeg4videodec-Bail-out-earlier-when-parsing.patch
Type: text/x-patch
Size: 1907 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20250304/11157837/attachment-0018.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0020-avcodec-mpeg4video-Split-ff_mpeg4_pred_dc.patch
Type: text/x-patch
Size: 7713 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20250304/11157837/attachment-0019.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0021-avcodec-mpeg4video-Move-IS_3IV1-macro-to-mpeg4videod.patch
Type: text/x-patch
Size: 1672 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20250304/11157837/attachment-0020.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0022-avcodec-mpegvideo_enc-Only-allocate-chroma-intra-mat.patch
Type: text/x-patch
Size: 3113 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20250304/11157837/attachment-0021.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0023-avcodec-mpegvideo_enc-Set-chroma_intra_matrix-for-Sp.patch
Type: text/x-patch
Size: 1426 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20250304/11157837/attachment-0022.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0024-avcodec-mpegvideo_enc-Factor-checks-out-of-loop.patch
Type: text/x-patch
Size: 3364 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20250304/11157837/attachment-0023.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0025-avcodec-mpegvideo_enc-Only-allocate-inter-matrices-w.patch
Type: text/x-patch
Size: 4132 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20250304/11157837/attachment-0024.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0026-avcodec-mpegvideo_enc-Don-t-init-matrices-unnecessar.patch
Type: text/x-patch
Size: 1190 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20250304/11157837/attachment-0025.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0027-avcodec-mpegvideo_enc-Move-q_matrix-init-to-init_mat.patch
Type: text/x-patch
Size: 2561 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20250304/11157837/attachment-0026.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0028-avcodec-mpegvideo_enc-Move-q_scale_type-check-to-mpe.patch
Type: text/x-patch
Size: 1914 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20250304/11157837/attachment-0027.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0029-avcodec-mpegvideo_enc-Move-vbv_delay-warning-to-mpeg.patch
Type: text/x-patch
Size: 2283 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20250304/11157837/attachment-0028.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0030-avcodec-mpegvideo_enc-Move-H.263-specific-check-to-i.patch
Type: text/x-patch
Size: 1472 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20250304/11157837/attachment-0029.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0031-avcodec-mpegvideo-Move-ratecontrol-only-options-to-R.patch
Type: text/x-patch
Size: 11146 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20250304/11157837/attachment-0030.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0032-avcodec-mpegvideo-Move-temp-ratecontrol-bufs-to-Rate.patch
Type: text/x-patch
Size: 4675 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20250304/11157837/attachment-0031.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0033-avcodec-mpegvideo-Mark-ff_mpv_common_defaults-as-av_.patch
Type: text/x-patch
Size: 956 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20250304/11157837/attachment-0032.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0034-avcodec-speedhqenc-Don-t-log-to-the-private-context.patch
Type: text/x-patch
Size: 1283 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20250304/11157837/attachment-0033.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0035-avcodec-speedhqenc-Inline-ff_speedhq_mb_y_order_to_m.patch
Type: text/x-patch
Size: 2507 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20250304/11157837/attachment-0034.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0036-avcodec-mjpegenc-Remove-nonsensical-AMV-options.patch
Type: text/x-patch
Size: 2234 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20250304/11157837/attachment-0035.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0037-avcodec-mjpegenc-Don-t-log-to-private-context.patch
Type: text/x-patch
Size: 925 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20250304/11157837/attachment-0036.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0038-avcodec-mpeg12enc-Simplify-writing-bits.patch
Type: text/x-patch
Size: 2333 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20250304/11157837/attachment-0037.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0039-avcodec-mpegvideo-Move-vbv_delay-to-Mpeg1Context.patch
Type: text/x-patch
Size: 2400 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20250304/11157837/attachment-0038.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0040-avcodec-mpegvideo_enc-motion_est-Pre-center-fcode_ta.patch
Type: text/x-patch
Size: 3302 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20250304/11157837/attachment-0039.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0041-avcodec-mjpegenc-Use-forward-decl-for-MpegEncContext.patch
Type: text/x-patch
Size: 3045 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20250304/11157837/attachment-0040.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0042-avcodec-mjpegenc-Don-t-use-ff_-prefix-for-static-fun.patch
Type: text/x-patch
Size: 2983 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20250304/11157837/attachment-0041.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0043-avcodec-mjpegenc_common-Constify-ff_mjpeg_encode_-dc.patch
Type: text/x-patch
Size: 4782 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20250304/11157837/attachment-0042.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0044-avcodec-mjpegenc-Constify-parent-ctx-in-encode_block.patch
Type: text/x-patch
Size: 1205 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20250304/11157837/attachment-0043.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0045-avcodec-mpeg12dec-Use-CHROMA_-defines.patch
Type: text/x-patch
Size: 3701 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20250304/11157837/attachment-0044.bin>
More information about the ffmpeg-devel
mailing list