Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Tjoppen opened this issue May 15, 2024 · 0 comments
Labels
Milestone

Comments

@Tjoppen
Copy link
Contributor

Tjoppen commented May 15, 2024

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?= <[email protected]>
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.

@ddennedy ddennedy added this to the v7.26.0 milestone May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants