diff mbox

[FFmpeg-devel] libavf: Auto-detect mjpeg 2000 in mpeg-ts

Message ID 20161013144100.GB75318@putsch.kolbu.ws
State Accepted
Headers show

Commit Message

Ståle kristoffersen Oct. 13, 2016, 2:41 p.m. UTC
On 2016-10-12 at 13:57, Carl Eugen Hoyos wrote:
> 2016-10-11 16:27 GMT+02:00 Michael Niedermayer <michael@niedermayer.cc>:
> 
> > also the img2 demuxer for mjpeg2000 from img2dec.c does not work
> > for this ?
> 
> We separated the jpg from the mjpeg probe, jpg makes sure that the
> sample starts like a jpg image and contains an end marker and can
> be decoded, mjpeg probe is less strict but requires more than one
> frame.
> Same could be argued for j2k or was our reasoning bad?

Since nobody chimed in on this, I have created two new patches, one
containing a separate mjpeg 2000 probe
(0001-libavf-Auto-detect-mjpeg-2000-in-mpeg-ts2.patch), and one that
incorporates it into the img2dec jpeg 2000 probe
(0001-libavf-Make-jpeg-2000-probe-work-for-mjpeg-2000.patch).

I think it is best to have them separated, as that matches the mjpeg
behaviour.

Comments

Michael Niedermayer Oct. 13, 2016, 11:31 p.m. UTC | #1
On Thu, Oct 13, 2016 at 04:41:00PM +0200, Ståle Kristoffersen wrote:
> On 2016-10-12 at 13:57, Carl Eugen Hoyos wrote:
> > 2016-10-11 16:27 GMT+02:00 Michael Niedermayer <michael@niedermayer.cc>:
> > 
> > > also the img2 demuxer for mjpeg2000 from img2dec.c does not work
> > > for this ?
> > 
> > We separated the jpg from the mjpeg probe, jpg makes sure that the
> > sample starts like a jpg image and contains an end marker and can
> > be decoded, mjpeg probe is less strict but requires more than one
> > frame.
> > Same could be argued for j2k or was our reasoning bad?
> 
> Since nobody chimed in on this, I have created two new patches, one
> containing a separate mjpeg 2000 probe
> (0001-libavf-Auto-detect-mjpeg-2000-in-mpeg-ts2.patch), and one that
> incorporates it into the img2dec jpeg 2000 probe
> (0001-libavf-Make-jpeg-2000-probe-work-for-mjpeg-2000.patch).
> 

> I think it is best to have them separated, as that matches the mjpeg
> behaviour.

have you tested the demuxer ?
i dont think it works outside probing for mpegts
i think for j2k codestream support a jpeg2000 parser is needed first
same as we have for mjpeg

that said i have no preferrance for which way its done but i think
were not all aware that adding a identical mjpeg style demuxer was
only part of the stuff needed ...

[...]
Michael Niedermayer Dec. 17, 2016, 11:14 p.m. UTC | #2
On Fri, Oct 14, 2016 at 01:31:12AM +0200, Michael Niedermayer wrote:
> On Thu, Oct 13, 2016 at 04:41:00PM +0200, Ståle Kristoffersen wrote:
> > On 2016-10-12 at 13:57, Carl Eugen Hoyos wrote:
> > > 2016-10-11 16:27 GMT+02:00 Michael Niedermayer <michael@niedermayer.cc>:
> > > 
> > > > also the img2 demuxer for mjpeg2000 from img2dec.c does not work
> > > > for this ?
> > > 
> > > We separated the jpg from the mjpeg probe, jpg makes sure that the
> > > sample starts like a jpg image and contains an end marker and can
> > > be decoded, mjpeg probe is less strict but requires more than one
> > > frame.
> > > Same could be argued for j2k or was our reasoning bad?
> > 
> > Since nobody chimed in on this, I have created two new patches, one
> > containing a separate mjpeg 2000 probe
> > (0001-libavf-Auto-detect-mjpeg-2000-in-mpeg-ts2.patch), and one that
> > incorporates it into the img2dec jpeg 2000 probe
> > (0001-libavf-Make-jpeg-2000-probe-work-for-mjpeg-2000.patch).
> > 
> 
> > I think it is best to have them separated, as that matches the mjpeg
> > behaviour.
> 
> have you tested the demuxer ?
> i dont think it works outside probing for mpegts
> i think for j2k codestream support a jpeg2000 parser is needed first
> same as we have for mjpeg

theres actually a j2k parser patch on the ML
so applied this one here

thx

[...]
diff mbox

Patch

From 8e6aa5935e33f1f8dd747ce4d9e785bd0dcc1e15 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A5le=20Kristoffersen?= <staalebk@ifi.uio.no>
Date: Thu, 13 Oct 2016 15:55:35 +0200
Subject: [PATCH] libavf: Make jpeg 2000 probe work for mjpeg 2000
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This makes it possible to decode motion jpeg 2000
encoded in a transport stream without a correct PMT/PAT.

Signed-off-by: Ståle Kristoffersen <staalebk@ifi.uio.no>
---
 libavformat/img2dec.c | 20 ++++++++++++++++++++
 libavformat/utils.c   |  1 +
 2 files changed, 21 insertions(+)

diff --git a/libavformat/img2dec.c b/libavformat/img2dec.c
index a920f46..bb22302 100644
--- a/libavformat/img2dec.c
+++ b/libavformat/img2dec.c
@@ -678,10 +678,30 @@  static int exr_probe(AVProbeData *p)
 static int j2k_probe(AVProbeData *p)
 {
     const uint8_t *b = p->buf;
+    int i, marker, marker_size;
+    int frames = 0, invalid = 0;
 
     if (AV_RB64(b) == 0x0000000c6a502020 ||
         AV_RB32(b) == 0xff4fff51)
         return AVPROBE_SCORE_EXTENSION + 1;
+    for (i = 0; i < p->buf_size - 5; i++) {
+        if (AV_RB32(b) == 0xff4fff51){
+            marker_size = AV_RB16(b+4);
+            if (marker_size + i < p->buf_size - 4) {
+                marker = AV_RB8(b+4+marker_size);
+                if (marker == 0xff)
+                    frames++;
+                else
+                    invalid++;
+            }
+        }
+        b += 1;
+    }
+    if (invalid*4 + 1 < frames) {
+        if (invalid == 0 && frames > 2)
+            return AVPROBE_SCORE_EXTENSION / 2;
+        return AVPROBE_SCORE_EXTENSION / 4;
+    }
     return 0;
 }
 
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 8a51aea..5070935 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -328,6 +328,7 @@  static int set_codec_from_probe_data(AVFormatContext *s, AVStream *st,
         { "hevc",      AV_CODEC_ID_HEVC,       AVMEDIA_TYPE_VIDEO },
         { "loas",      AV_CODEC_ID_AAC_LATM,   AVMEDIA_TYPE_AUDIO },
         { "m4v",       AV_CODEC_ID_MPEG4,      AVMEDIA_TYPE_VIDEO },
+        { "j2k_pipe",  AV_CODEC_ID_JPEG2000,   AVMEDIA_TYPE_VIDEO },
         { "mp3",       AV_CODEC_ID_MP3,        AVMEDIA_TYPE_AUDIO },
         { "mpegvideo", AV_CODEC_ID_MPEG2VIDEO, AVMEDIA_TYPE_VIDEO },
         { "truehd",    AV_CODEC_ID_TRUEHD,     AVMEDIA_TYPE_AUDIO },
-- 
2.1.4