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.
Sample LJ92 MLV file: https://0x0.st/XlFm.mlv FATE tests pass locally. It was not obvious from the Developer guide how to get this working. The claim is "Running ’make fate’ accomplishes [running local FATE tests]", but this of course does not work until you rsync the samples, build FATE etc, which is not mentioned: https://www.ffmpeg.org/developer.html#Regression-tests-1 I suggest adding something like "but WILL NOT work until it is configured", before "please see fate.html for details". This would make it clearer that you NEED to follow the link, rather than it existing as reference material should you want it in the future. Simply running "make fate" fails, but in a way that looked like a normal test failure to me; I assumed upstream was broken since the failure was repeatable and occured without my changes. There is a long comment in patch 0001 that I don't expect to survive review, but provides context for the code change. As an ffmpeg noob I can't make a good judgement on what level of commenting is appropriate. For reference, attempt 1 can be seen in the archives, here: https://ffmpeg.org//pipermail/ffmpeg-devel/2024-October/335245.html
From f61171a37c81bc5b7f7ba6075b38e96df2cdd371 Mon Sep 17 00:00:00 2001 From: stephen-e <33672591+reticulatedpi...@users.noreply.github.com> Date: Thu, 24 Oct 2024 18:16:18 +0100 Subject: [PATCH 1/2] avcodec/mjpegdec: set bayer earlier if possible Use av_pix_fmt_desc_get() earlier, to set Bayer flag during mjpeg decoding, earlier than before. dng_decode_jpeg() does this directly in tiff.c, this change allows signalling via the pixel format from a demuxer (to support LJ92 compressed raw video in MLV containers, which is the next commit). --- libavcodec/mjpegdec.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c index 86ec58713c..442a9878e1 100644 --- a/libavcodec/mjpegdec.c +++ b/libavcodec/mjpegdec.c @@ -508,6 +508,20 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s) } } + // Not all files can give us this pix_fmt info at this point. + // For those that can, we can set Bayer flag early. + // Without this, at least LJ92 compressed MLV files fail to parse further down, + // because they're Bayer but the flag isn't set at time of check. + // Possibly I'm supposed to extend the above wall of flag checks and bit ops, + // which has no comments on intent or purpose? Instead, I call + // av_pix_fmt_desc_get(), but notably, this is called again further down. + // Moving it up here makes FATE fail because the switch below this point changes + // s->avctx->pix_fmt used in the call. Duplicating it here works, although this + // feels ugly. + s->pix_desc = av_pix_fmt_desc_get(s->avctx->pix_fmt); + if (s->pix_desc && (s->pix_desc->flags & AV_PIX_FMT_FLAG_BAYER)) + s->bayer = 1; + if (s->bayer) { if (pix_fmt_id != 0x11110000 && pix_fmt_id != 0x11000000) goto unk_pixfmt; -- 2.45.2
From db0f076e8f724deee604af7a1a85c1d130f1f87d Mon Sep 17 00:00:00 2001 From: stephen-e <33672591+reticulatedpi...@users.noreply.github.com> Date: Mon, 21 Oct 2024 16:35:49 +0100 Subject: [PATCH 2/2] avformat/mlvdec: add LJ92 support MLV files can contain LJ92 compressed raw video data. MJPEG codec can be used to handle these. --- libavformat/mlvdec.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/libavformat/mlvdec.c b/libavformat/mlvdec.c index 1a6d38f37c..2eb21a3aab 100644 --- a/libavformat/mlvdec.c +++ b/libavformat/mlvdec.c @@ -44,8 +44,9 @@ #define MLV_AUDIO_CLASS_WAV 1 -#define MLV_CLASS_FLAG_DELTA 0x40 #define MLV_CLASS_FLAG_LZMA 0x80 +#define MLV_CLASS_FLAG_DELTA 0x40 +#define MLV_CLASS_FLAG_LJ92 0x20 typedef struct { AVIOContext *pb[101]; @@ -298,9 +299,12 @@ static int read_header(AVFormatContext *avctx) if ((mlv->class[0] & (MLV_CLASS_FLAG_DELTA|MLV_CLASS_FLAG_LZMA))) avpriv_request_sample(avctx, "compression"); vst->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; - switch (mlv->class[0] & ~(MLV_CLASS_FLAG_DELTA|MLV_CLASS_FLAG_LZMA)) { + switch (mlv->class[0] & ~(MLV_CLASS_FLAG_DELTA|MLV_CLASS_FLAG_LZMA|MLV_CLASS_FLAG_LJ92)) { case MLV_VIDEO_CLASS_RAW: - vst->codecpar->codec_id = AV_CODEC_ID_RAWVIDEO; + if (mlv->class[0] & MLV_CLASS_FLAG_LJ92) + vst->codecpar->codec_id = AV_CODEC_ID_MJPEG; + else + vst->codecpar->codec_id = AV_CODEC_ID_RAWVIDEO; break; case MLV_VIDEO_CLASS_YUV: vst->codecpar->format = AV_PIX_FMT_YUV420P; -- 2.45.2
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".