Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH] avcodec/libjxlenc: avoid failure when level 10 is required
@ 2022-06-26  6:47 Leo Izen
  0 siblings, 0 replies; only message in thread
From: Leo Izen @ 2022-06-26  6:47 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Leo Izen

If a level 10 codestream is required, JxlEncoderSetBasicInfo
will fail as it verifies the codestream level restrictions.
However, there's no way for the library to provide the info
on what codestream level is actually required until the BasicInfo
struct is already set. Thus, we work around this problem by
setting the codestream level to 10 in order to prevent
JxlEncoderSetBasicInfo from failing, and then we later query
the required codestream level.

Signed-off-by: Leo Izen <leo.izen@gmail.com>
---
 libavcodec/libjxlenc.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/libavcodec/libjxlenc.c b/libavcodec/libjxlenc.c
index 6a948cc3ae..b427d5d1a7 100644
--- a/libavcodec/libjxlenc.c
+++ b/libavcodec/libjxlenc.c
@@ -257,11 +257,25 @@ static int libjxl_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFra
         return ret;
     }
 
+    /*
+     * We set all codestreams to level 10 here first, because
+     * JxlEncoderSetBasicInfo fails if level10 is required, but there is no
+     * way to determine if level10 is required until after the basic info is
+     * already set (a catch-22). To work around this problem, we set the level
+     * to level10 immediately, populate the basic info, and then query the
+     * level that is actually required.
+     *
+     * Return value is not checked because on a fresh encoder instance this
+     * cannot fail.
+     */
+    JxlEncoderSetCodestreamLevel(ctx->encoder, 10);
+
     /* populate the basic info settings */
     JxlEncoderInitBasicInfo(&info);
     jxl_fmt.num_channels = pix_desc->nb_components;
     info.xsize = frame->width;
     info.ysize = frame->height;
+    /* num_extra_channels includes the alpha channel */
     info.num_extra_channels = (jxl_fmt.num_channels + 1) % 2;
     info.num_color_channels = jxl_fmt.num_channels - info.num_extra_channels;
     info.bits_per_sample = av_get_bits_per_pixel(pix_desc) / jxl_fmt.num_channels;
-- 
2.36.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".

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-06-26  6:47 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-26  6:47 [FFmpeg-devel] [PATCH] avcodec/libjxlenc: avoid failure when level 10 is required Leo Izen

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