diff mbox series

[FFmpeg-devel] Add support for LJ92 compressed MLV files

Message ID CAB+1MHrN9jRT7OLbanRQd39x-R=MGMQwohZY6_JN1YiirAHaWA@mail.gmail.com
State New
Headers show
Series [FFmpeg-devel] Add support for LJ92 compressed MLV files | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 fail Make fate failed

Commit Message

South East Oct. 21, 2024, 6:44 p.m. UTC
ffmpeg has existing support for MLV raw video files; libavformat/mlvdec.c.
Since this was added, MLV has been extended to support LJ92 compressed
image data.  These patches build on lossless DNG support in 7.2-dev to
enable handling LJ92 MLV via existing libavcodec/mjpegdec.c code.

I can provide MLV sample files if desired, being raw video these tend to be
large.

Thanks to JEEB and Lynne for help via IRC.
diff mbox series

Patch

From bda19449cce6ae028ef751f0f4f21da63214ab3f Mon Sep 17 00:00:00 2001
From: stephen-e <33672591+reticulatedpines@users.noreply.github.com>
Date: Mon, 21 Oct 2024 16:32:01 +0100
Subject: [PATCH 1/2] avcodec/mjpegdec: set bayer flag based on pix_fmt

dng_decode_jpeg() does this directly in tiff.c,
this change allows signalling via the pixel format
(to support LJ92 compressed raw video in MLV containers,
which is the next commit).
---
 libavcodec/mjpegdec.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c
index 86ec58713c..9c990f3e03 100644
--- a/libavcodec/mjpegdec.c
+++ b/libavcodec/mjpegdec.c
@@ -409,6 +409,15 @@  int ff_mjpeg_decode_sof(MJpegDecodeContext *s)
         return AVERROR_PATCHWELCOME;
     }
 
+    // If the given pixel format is Bayer, set the flag (this makes LJ92 MLV files work)
+    s->pix_desc = av_pix_fmt_desc_get(s->avctx->pix_fmt);
+    if (!s->pix_desc) {
+        av_log(s->avctx, AV_LOG_ERROR, "Could not get a pixel format descriptor.\n");
+        return AVERROR_BUG;
+    }
+    if (s->pix_desc->flags & AV_PIX_FMT_FLAG_BAYER)
+        s->bayer = 1;
+
     if (s->bayer) {
         if (nb_components == 2) {
             /* Bayer images embedded in DNGs can contain 2 interleaved components and the
@@ -718,12 +727,6 @@  int ff_mjpeg_decode_sof(MJpegDecodeContext *s)
                 s->avctx->pix_fmt = AV_PIX_FMT_GRAY16;
         }
 
-        s->pix_desc = av_pix_fmt_desc_get(s->avctx->pix_fmt);
-        if (!s->pix_desc) {
-            av_log(s->avctx, AV_LOG_ERROR, "Could not get a pixel format descriptor.\n");
-            return AVERROR_BUG;
-        }
-
         if (s->avctx->pix_fmt == s->hwaccel_sw_pix_fmt && !size_change) {
             s->avctx->pix_fmt = s->hwaccel_pix_fmt;
         } else {
-- 
2.45.2