From 6ac468554c7fea0dfaefde85fb6cdd0fceaf5cad Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Fri, 1 Dec 2023 21:25:54 +0100 Subject: Fix scaling of bitmap subs when the corresponding video is cropped (#2670). Previously we would scale the bitmap size/position to a proportion of the original video frame, then scale it back up again to the DCP container. This didn't take into account some cropped cases where the picture would end up the same shape but the subtitles would be stretched. --- src/lib/ffmpeg_decoder.cc | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'src/lib/ffmpeg_decoder.cc') diff --git a/src/lib/ffmpeg_decoder.cc b/src/lib/ffmpeg_decoder.cc index 6e9d671a2..dcad184fa 100644 --- a/src/lib/ffmpeg_decoder.cc +++ b/src/lib/ffmpeg_decoder.cc @@ -781,11 +781,23 @@ FFmpegDecoder::process_bitmap_subtitle (AVSubtitleRect const * rect) if (target_height == 0 && video_codec_context()) { target_height = video_codec_context()->height; } - DCPOMATIC_ASSERT (target_width); - DCPOMATIC_ASSERT (target_height); + + int x_offset = 0; + int y_offset = 0; + if (_ffmpeg_content->video && _ffmpeg_content->video->use()) { + auto const crop = _ffmpeg_content->video->actual_crop(); + target_width -= crop.left + crop.right; + target_height -= crop.top + crop.bottom; + x_offset = -crop.left; + y_offset = -crop.top; + } + + DCPOMATIC_ASSERT(target_width > 0); + DCPOMATIC_ASSERT(target_height > 0); + dcpomatic::Rect const scaled_rect ( - static_cast(rect->x) / target_width, - static_cast(rect->y) / target_height, + static_cast(rect->x + x_offset) / target_width, + static_cast(rect->y + y_offset) / target_height, static_cast(rect->w) / target_width, static_cast(rect->h) / target_height ); -- cgit v1.2.3