mltframework/mlt

Setting lowres>=1 for codecs that don't support lowres results in broken output

Tjoppen opened this issue · 0 comments

For some codecs such as JPEG2000 it's possible to set lowres=1 to halve width and height which is useful for speeding up decode. But doing this for codecs which don't support lowres, for example speedhq (SHQ), results in garbled output like this:

image

This is with a command like melt V75UPPSNACK_LORDAG_P01_195335.mov lowres=1

Here's a patch that fixes the issue (GitHub doesn't seem to support attaching patches). Perhaps it could be done some other way also, but this works:

From de5a0fae54db4805ea475570fa641dacbfce4188 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tomas=20H=C3=A4rdin?= <git@haerdin.se>
Date: Wed, 15 May 2024 13:21:56 +0200
Subject: [PATCH] producer_avformat: Fix lowres if set too high

---
 src/modules/avformat/producer_avformat.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/src/modules/avformat/producer_avformat.c b/src/modules/avformat/producer_avformat.c
index 6a73cd95..f91f334f 100644
--- a/src/modules/avformat/producer_avformat.c
+++ b/src/modules/avformat/producer_avformat.c
@@ -2650,6 +2650,13 @@ static int video_codec_init(producer_avformat self, int index, mlt_properties pr
         if (thread_count >= 0)
             codec_context->thread_count = thread_count;
 
+		// fix lowres if set too high
+		int lowres = mlt_properties_get_int(properties, "lowres");
+		if (lowres > codec_context->codec->max_lowres) {
+			mlt_log_debug( MLT_PRODUCER_SERVICE( self->parent ), "clamping lowres=%i to max_lowres=%i\n", lowres, codec_context->codec->max_lowres );
+			mlt_properties_set_int(properties, "lowres", codec_context->codec->max_lowres);
+		}
+
 #if USE_HWACCEL
         if (self->hwaccel.device_type == AV_HWDEVICE_TYPE_NONE
             || self->hwaccel.pix_fmt == AV_PIX_FMT_NONE) {
-- 
2.39.2

With the patch applied to master the output is as expected:

image

This possibly relates to #795.