From: Manuel Lauss <code@ffmpeg.org> To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH] avcodec/sanm: bl16: fix artifacts in larger videos (PR #20235) Date: Thu, 14 Aug 2025 01:32:14 +0300 (EEST) Message-ID: <20250813223214.1287D68D01D@ffbox0-bg.ffmpeg.org> (raw) PR #20235 opened by Manuel Lauss (mlauss2) URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20235 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20235.patch The DOS/Windows decoder precomputed a linear offset table of all possible motion vectors into an int16_t with the formula offset = my * width + mx. For larger widths (>=768), the pairs 1-4 and 252-255 of motion_vectors[] will overflow the int16_t, changing the sign. Playing back the 800x600 "jonesopn_8.snm" video of "Indiana Jones and the Infernal Machine" reveals a lot of artifacts and a lot of "Ignoring invalid motion vector (149, -41)->(136, 0), block size = 8" messages. Fix this by doing the calculation that the DOS/Windows players do, let the value overflow and reextract the "new" mvec x/y components. Here are 2 videos to demonstrate: [Video pre-patch](http://mlau.at/bl16_before.mp4) [Video post-patch](http://mlau.at/bl16_after.mp4) From 2cfc357042cded849ff4e666b14c68241157b366 Mon Sep 17 00:00:00 2001 From: Manuel Lauss <manuel.lauss@gmail.com> Date: Thu, 14 Aug 2025 00:21:09 +0200 Subject: [PATCH] avcodec/sanm: bl16: fix artifacts in larger videos The DOS/Windows decoder precomputed a linear offset table of all possible motion vectors into an int16_t with the formula offset = my * width + mx. For larger widths (>=768), the pairs 1-4 and 252-255 of motion_vectors[] will overflow the int16_t, changing the sign. Playing back the 800x600 "jonesopn_8.snm" video of "Indiana Jones and the Infernal Machine" reveals a lot of artifacts and a lot of "Ignoring invalid motion vector (149, -41)->(136, 0), block size = 8" messages. Fix this by doing the calculation that the DOS/Windows players do, let the value overflow and reextract the "new" mvec x/y components. --- libavcodec/sanm.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libavcodec/sanm.c b/libavcodec/sanm.c index a066a864eb..7319f5ad3b 100644 --- a/libavcodec/sanm.c +++ b/libavcodec/sanm.c @@ -2069,6 +2069,18 @@ static int codec2subblock(SANMVideoContext *ctx, int cx, int cy, int blk_size) mx = motion_vectors[opcode][0]; my = motion_vectors[opcode][1]; + /* The original implementation of this codec precomputes a table + * of all possible linear offsets, with type int16_t. + * For larger widths (commonly seen in the 800x600 videos), the calculation + * of opcodes 1-4 and 252-255 overflows the int16_t, turning the vector + * in the opposite direction. This is actively exploited in e.g. the + * "jonesopn_8.snm" video of "Indiana Jones and the Infernal Machine". + * Therefore do the calculation, let it overflow and extract the new + * x/y mv components from there. + */ + index = (int16_t)(my * ctx->width + mx); + mx = index % ctx->width; + my = index / ctx->width; if (good_mvec(ctx, cx, cy, mx, my, blk_size)) { copy_block(ctx->frm0 + cx + ctx->pitch * cy, ctx->frm2 + cx + mx + ctx->pitch * (cy + my), -- 2.49.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".
reply other threads:[~2025-08-13 22:32 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20250813223214.1287D68D01D@ffbox0-bg.ffmpeg.org \ --to=code@ffmpeg.org \ --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