From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> To: ffmpeg-devel@ffmpeg.org Cc: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> Subject: [FFmpeg-devel] [PATCH 01/13] avcodec/h261enc: Use LUT to write motion vector differences Date: Mon, 1 Jul 2024 14:01:55 +0200 Message-ID: <GV1P250MB0737B9F8B8BA2F37597B5A598FD32@GV1P250MB0737.EURP250.PROD.OUTLOOK.COM> (raw) Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- libavcodec/h261enc.c | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/libavcodec/h261enc.c b/libavcodec/h261enc.c index a901c32e42..d3d724bef6 100644 --- a/libavcodec/h261enc.c +++ b/libavcodec/h261enc.c @@ -39,6 +39,7 @@ #define H261_MAX_RUN 26 #define H261_MAX_LEVEL 15 #define H261_ESC_LEN (6 + 6 + 8) +#define MV_TAB_OFFSET 32 static struct VLCLUT { uint8_t len; @@ -47,6 +48,7 @@ static struct VLCLUT { 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]; typedef struct H261EncContext { MpegEncContext s; @@ -140,20 +142,8 @@ void ff_h261_reorder_mb_index(MpegEncContext *s) static void h261_encode_motion(PutBitContext *pb, int val) { - int sign, code; - if (val == 0) { - // Corresponds to ff_h261_mv_tab[0] - put_bits(pb, 1, 1); - } else { - if (val > 15) - val -= 32; - if (val < -16) - val += 32; - sign = val < 0; - code = sign ? -val : val; - put_bits(pb, ff_h261_mv_tab[code][1], ff_h261_mv_tab[code][0]); - put_bits(pb, 1, sign); - } + put_bits(pb, h261_mv_codes[MV_TAB_OFFSET + val][1], + h261_mv_codes[MV_TAB_OFFSET + val][0]); } static inline int get_cbp(MpegEncContext *s, int16_t block[6][64]) @@ -323,6 +313,7 @@ void ff_h261_encode_mb(MpegEncContext *s, int16_t block[6][64], static av_cold void h261_encode_init_static(void) { + uint8_t (*const mv_codes)[2] = h261_mv_codes + MV_TAB_OFFSET; memset(uni_h261_rl_len, H261_ESC_LEN, sizeof(uni_h261_rl_len)); memset(uni_h261_rl_len_last, H261_ESC_LEN + 2 /* EOB */, sizeof(uni_h261_rl_len_last)); @@ -341,6 +332,20 @@ static av_cold void h261_encode_init_static(void) uni_h261_rl_len_last[UNI_AC_ENC_INDEX(run, 64 + level)] = len + 2; uni_h261_rl_len_last[UNI_AC_ENC_INDEX(run, 64 - level)] = len + 2; } + + for (size_t i = 1;; i++) { + // sign-one MV codes; diff -16..-1, 16..31 + mv_codes[32 - i][0] = mv_codes[-i][0] = (ff_h261_mv_tab[i][0] << 1) | 1 /* sign */; + mv_codes[32 - i][1] = mv_codes[-i][1] = ff_h261_mv_tab[i][1] + 1; + if (i == 16) + break; + // sign-zero MV codes: diff -31..-17, 1..15 + mv_codes[i][0] = mv_codes[i - 32][0] = ff_h261_mv_tab[i][0] << 1; + mv_codes[i][1] = mv_codes[i - 32][1] = ff_h261_mv_tab[i][1] + 1; + } + // MV code for difference zero; has no sign + mv_codes[0][0] = 1; + mv_codes[0][1] = 1; } av_cold int ff_h261_encode_init(MpegEncContext *s) -- 2.40.1 _______________________________________________ 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".
next reply other threads:[~2024-07-01 12:02 UTC|newest] Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top 2024-07-01 12:01 Andreas Rheinhardt [this message] 2024-07-01 12:15 ` [FFmpeg-devel] [PATCH 02/13] avcodec/mpeg12dec: Move resetting last_dc to decoder Andreas Rheinhardt 2024-07-01 12:16 ` [FFmpeg-devel] [PATCH 03/13] avcodec/mpeg12enc: Move resetting last_dc to encoder Andreas Rheinhardt 2024-07-01 12:16 ` [FFmpeg-devel] [PATCH 04/13] avcodec/h263dec: Clean intra tables in decoder, not ff_mpv_reconstruct_mb Andreas Rheinhardt 2024-07-01 12:16 ` [FFmpeg-devel] [PATCH 05/13] avcodec/mpegvideo_enc: Don't reset intra buffers in mpv_reconstruct_mb() Andreas Rheinhardt 2024-07-01 12:16 ` [FFmpeg-devel] [PATCH 06/13] avcodec/mpv_reconstruct_mb_template: Merge template into its users Andreas Rheinhardt 2024-07-01 13:04 ` Rémi Denis-Courmont 2024-07-01 12:16 ` [FFmpeg-devel] [PATCH 07/13] avcodec/mpegvideo_{dec, enc}: Reindent after the previous commit Andreas Rheinhardt 2024-07-01 12:16 ` [FFmpeg-devel] [PATCH 08/13] avcodec/mpegvideo_enc: Don't set qscale_table value prematurely Andreas Rheinhardt 2024-07-01 12:16 ` [FFmpeg-devel] [PATCH 09/13] avcodec/mpegvideo_enc: Add AV_CODEC_CAP_DR1 Andreas Rheinhardt 2024-07-01 12:16 ` [FFmpeg-devel] [PATCH 10/13] avcodec/motion_est: Avoid branches for put(_no_rnd) selection Andreas Rheinhardt 2024-07-01 12:16 ` [FFmpeg-devel] [PATCH 11/13] avcodec/mpegvideo_dec: Use picture-dimensions in ff_print_debug_info() Andreas Rheinhardt 2024-07-01 12:16 ` [FFmpeg-devel] [PATCH 12/13] avcodec/vc1dec: Reenable debug-info output for field pictures Andreas Rheinhardt 2024-07-01 12:16 ` [FFmpeg-devel] [PATCH 13/13] avcodec/h261dec: Remove dead check Andreas Rheinhardt
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=GV1P250MB0737B9F8B8BA2F37597B5A598FD32@GV1P250MB0737.EURP250.PROD.OUTLOOK.COM \ --to=andreas.rheinhardt@outlook.com \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
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