Commit bc292d97 for libheif
commit bc292d97abed6b1ba1fc3d95c4191829ee99b088
Author: John Preston <johnprestonmail@gmail.com>
Date: Fri Sep 25 19:40:21 2026 +0400
FFmpeg decoder: crop exactly as the bitstream signals
Without AV_CODEC_FLAG_UNALIGNED, libavcodec rounds a left conformance-window
crop down to keep the plane pointers aligned. The decoded image then comes out
wider than the ispe size and is rejected with "Decoded image does not have the
size signaled in the file".
diff --git a/libheif/plugins/decoder_ffmpeg.cc b/libheif/plugins/decoder_ffmpeg.cc
index 0f315a54..c253e84c 100644
--- a/libheif/plugins/decoder_ffmpeg.cc
+++ b/libheif/plugins/decoder_ffmpeg.cc
@@ -203,6 +203,11 @@ static heif_error ffmpeg_new_decoder2(void** dec, const heif_decoder_plugin_opti
return { heif_error_Memory_allocation_error, heif_suberror_Unspecified, "avcodec_alloc_context3 returned error" };
}
+ // Crop exactly as the bitstream signals. Otherwise FFmpeg rounds a left crop
+ // down to keep the plane pointers aligned, and the decoded image comes out
+ // wider than the size signaled in the file.
+ decoder->av_codec_context->flags |= AV_CODEC_FLAG_UNALIGNED;
+
/* open it */
if (avcodec_open2(decoder->av_codec_context, decoder->av_codec, NULL) < 0) {
return { heif_error_Decoder_plugin_error, heif_suberror_Unspecified, "avcodec_open2 returned error" };