diff mbox series

[FFmpeg-devel,v6,3/9] avformat: add vvc raw demux

Message ID 20210217015146.19724-4-nuomi2021@gmail.com
State Superseded
Headers show
Series add vvc raw demuxer, muxer, parser, metadata bsf
Related show

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Nuo Mi Feb. 17, 2021, 1:51 a.m. UTC
---
 libavformat/Makefile     |  1 +
 libavformat/allformats.c |  1 +
 libavformat/vvcdec.c     | 61 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 63 insertions(+)
 create mode 100644 libavformat/vvcdec.c

Comments

Mark Thompson Feb. 17, 2021, 10:51 p.m. UTC | #1
On 17/02/2021 01:51, Nuo Mi wrote:
> ---
>   libavformat/Makefile     |  1 +
>   libavformat/allformats.c |  1 +
>   libavformat/vvcdec.c     | 61 ++++++++++++++++++++++++++++++++++++++++
>   3 files changed, 63 insertions(+)
>   create mode 100644 libavformat/vvcdec.c
> 
> diff --git a/libavformat/Makefile b/libavformat/Makefile
> index 10fee749c8..2b9d0eee7f 100644
> --- a/libavformat/Makefile
> +++ b/libavformat/Makefile
> @@ -564,6 +564,7 @@ OBJS-$(CONFIG_VOC_MUXER)                 += vocenc.o voc.o
>   OBJS-$(CONFIG_VPK_DEMUXER)               += vpk.o
>   OBJS-$(CONFIG_VPLAYER_DEMUXER)           += vplayerdec.o subtitles.o
>   OBJS-$(CONFIG_VQF_DEMUXER)               += vqf.o
> +OBJS-$(CONFIG_VVC_DEMUXER)               += vvcdec.o rawdec.o
>   OBJS-$(CONFIG_W64_DEMUXER)               += wavdec.o w64.o pcm.o
>   OBJS-$(CONFIG_W64_MUXER)                 += wavenc.o w64.o
>   OBJS-$(CONFIG_WAV_DEMUXER)               += wavdec.o pcm.o
> diff --git a/libavformat/allformats.c b/libavformat/allformats.c
> index f837ddabc8..fb06723fb9 100644
> --- a/libavformat/allformats.c
> +++ b/libavformat/allformats.c
> @@ -463,6 +463,7 @@ extern AVOutputFormat ff_voc_muxer;
>   extern AVInputFormat  ff_vpk_demuxer;
>   extern AVInputFormat  ff_vplayer_demuxer;
>   extern AVInputFormat  ff_vqf_demuxer;
> +extern AVInputFormat  ff_vvc_demuxer;
>   extern AVInputFormat  ff_w64_demuxer;
>   extern AVOutputFormat ff_w64_muxer;
>   extern AVInputFormat  ff_wav_demuxer;
> diff --git a/libavformat/vvcdec.c b/libavformat/vvcdec.c
> new file mode 100644
> index 0000000000..149f39f28e
> --- /dev/null
> +++ b/libavformat/vvcdec.c
> @@ -0,0 +1,61 @@
> +/*
> + * RAW VVC video demuxer
> + * Copyright (c) 2020 Nuo Mi <nuomi2021@gmail.com>
> + *
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with FFmpeg; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
> + */
> +
> +#include "libavcodec/vvc.h"
> +
> +#include "avformat.h"
> +#include "rawdec.h"
> +
> +static int vvc_probe(const AVProbeData *p)
> +{
> +    uint32_t code = -1;
> +    int sps = 0, pps = 0, irap = 0;
> +    int i;
> +
> +    for (i = 0; i < p->buf_size - 1; i++) {
> +        code = (code << 8) + p->buf[i];
> +        if ((code & 0xffffff00) == 0x100) {
> +            uint8_t nal2 = p->buf[i + 1];
> +            int type = (nal2 & 0xF8) >> 3;
> +
> +            if (code & 0xc0) // forbidden_zero_bit and nuh_reserved_zero_bit
> +                return 0;
> +
> +            if ((nal2 & 0x7) == 0) // nuh_temporal_id_plus1
> +                return 0;
> +
> +            switch (type) {
> +            case VVC_SPS_NUT:       sps++;  break;
> +            case VVC_PPS_NUT:       pps++;  break;
> +            case VVC_IDR_N_LP:
> +            case VVC_IDR_W_RADL:
> +            case VVC_CRA_NUT:
> +            case VVC_GDR_NUT:       irap++; break;
> +            }
> +        }
> +    }
> +
> +    if (sps && pps && irap)
> +        return AVPROBE_SCORE_EXTENSION + 1; // 1 more than .mpg

How well does this test fully distinguish from previous standards using the same start code style?

(Can I have an H.264 or H.265 raw stream which passes this test?  Can an H.266 stream ever pass the test for those codecs, implying we need to update them?)

> +    return 0;
> +}
> +
> +FF_DEF_RAWVIDEO_DEMUXER(vvc, "raw VVC video", vvc_probe, "h266,266,vvc", AV_CODEC_ID_VVC)
> 

- Mark
Nuo Mi Feb. 18, 2021, 8:47 a.m. UTC | #2
On Thu, Feb 18, 2021 at 6:52 AM Mark Thompson <sw@jkqxz.net> wrote:

> On 17/02/2021 01:51, Nuo Mi wrote:
>
> > +    for (i = 0; i < p->buf_size - 1; i++) {
> > +        code = (code << 8) + p->buf[i];
> > +        if ((code & 0xffffff00) == 0x100) {
> > +            uint8_t nal2 = p->buf[i + 1];
> > +            int type = (nal2 & 0xF8) >> 3;
> > +
> > +            if (code & 0xc0) // forbidden_zero_bit and
> nuh_reserved_zero_bit
> > +                return 0;
> > +
> > +            if ((nal2 & 0x7) == 0) // nuh_temporal_id_plus1
> > +                return 0;
> > +
> > +            switch (type) {
> > +            case VVC_SPS_NUT:       sps++;  break;
> > +            case VVC_PPS_NUT:       pps++;  break;
> > +            case VVC_IDR_N_LP:
> > +            case VVC_IDR_W_RADL:
> > +            case VVC_CRA_NUT:
> > +            case VVC_GDR_NUT:       irap++; break;
> > +            }
> > +        }
> > +    }
> > +
> > +    if (sps && pps && irap)
> > +        return AVPROBE_SCORE_EXTENSION + 1; // 1 more than .mpg
>
> How well does this test fully distinguish from previous standards using
> the same start code style?
>
> (Can I have an H.264 or H.265 raw stream which passes this test?  Can an
> H.266 stream ever pass the test for those codecs, implying we need to
> update them?)
>
The nal_unit_type located in a different byte. When a H.265 bitstream
has nuh_layer_ids equal to  VVC_SPS_NUT,  VVC_PPS_NUT and  VVC_IDR_N_LP,
can pass the test. Vice versa
All h266 conformance test clips will not detect as other formats. But if
you have a well-designed clip, it may be. This is normal case for a raw
bytestream detector.

>
> > +    return 0;
> > +}
> > +
> > +FF_DEF_RAWVIDEO_DEMUXER(vvc, "raw VVC video", vvc_probe,
> "h266,266,vvc", AV_CODEC_ID_VVC)
> >
>
> - Mark
> _______________________________________________
> 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".
Mark Thompson Feb. 18, 2021, 10:03 p.m. UTC | #3
On 18/02/2021 08:47, Nuo Mi wrote:
> On Thu, Feb 18, 2021 at 6:52 AM Mark Thompson <sw@jkqxz.net> wrote:
>> On 17/02/2021 01:51, Nuo Mi wrote:
>>
>>> +    for (i = 0; i < p->buf_size - 1; i++) {
>>> +        code = (code << 8) + p->buf[i];
>>> +        if ((code & 0xffffff00) == 0x100) {
>>> +            uint8_t nal2 = p->buf[i + 1];
>>> +            int type = (nal2 & 0xF8) >> 3;
>>> +
>>> +            if (code & 0xc0) // forbidden_zero_bit and
>> nuh_reserved_zero_bit
>>> +                return 0;
>>> +
>>> +            if ((nal2 & 0x7) == 0) // nuh_temporal_id_plus1
>>> +                return 0;
>>> +
>>> +            switch (type) {
>>> +            case VVC_SPS_NUT:       sps++;  break;
>>> +            case VVC_PPS_NUT:       pps++;  break;
>>> +            case VVC_IDR_N_LP:
>>> +            case VVC_IDR_W_RADL:
>>> +            case VVC_CRA_NUT:
>>> +            case VVC_GDR_NUT:       irap++; break;
>>> +            }
>>> +        }
>>> +    }
>>> +
>>> +    if (sps && pps && irap)
>>> +        return AVPROBE_SCORE_EXTENSION + 1; // 1 more than .mpg
>>
>> How well does this test fully distinguish from previous standards using
>> the same start code style?
>>
>> (Can I have an H.264 or H.265 raw stream which passes this test?  Can an
>> H.266 stream ever pass the test for those codecs, implying we need to
>> update them?)
>>
> The nal_unit_type located in a different byte. When a H.265 bitstream
> has nuh_layer_ids equal to  VVC_SPS_NUT,  VVC_PPS_NUT and  VVC_IDR_N_LP,
> can pass the test. Vice versa
> All h266 conformance test clips will not detect as other formats. But if
> you have a well-designed clip, it may be. This is normal case for a raw
> bytestream detector.

I'm mainly asking because the H.264 probe function does check some PS IDs to have a bit more confidence that it is looking at an H.264 stream.

If the collision cases are rare such that they will never overlap except with crafted streams then this is probably fine.

- Mark
Nuo Mi Feb. 19, 2021, 4:59 a.m. UTC | #4
>
>
>
> > All h266 conformance test clips will not detect as other formats. But if
> > you have a well-designed clip, it may be. This is normal case for a raw
> > bytestream detector.
>
> I'm mainly asking because the H.264 probe function does check some PS IDs
> to have a bit more confidence that it is looking at an H.264 stream.
>
> If the collision cases are rare such that they will never overlap except
> with crafted streams then this is probably fine.
>
H.264 and H.265's seq_parameter_set_id are ue(v). So you can check the max
value.
But for H.266, the sps_seq_parameter_set_id is u(4). and the range is 0 to
15. It's no way to check it's valid or not.
We can check sps_pic_width_max_in_luma_samples
and sps_pic_height_max_in_luma_samples, but it's not so meanful.


> - Mark
> _______________________________________________
> 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".
diff mbox series

Patch

diff --git a/libavformat/Makefile b/libavformat/Makefile
index 10fee749c8..2b9d0eee7f 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -564,6 +564,7 @@  OBJS-$(CONFIG_VOC_MUXER)                 += vocenc.o voc.o
 OBJS-$(CONFIG_VPK_DEMUXER)               += vpk.o
 OBJS-$(CONFIG_VPLAYER_DEMUXER)           += vplayerdec.o subtitles.o
 OBJS-$(CONFIG_VQF_DEMUXER)               += vqf.o
+OBJS-$(CONFIG_VVC_DEMUXER)               += vvcdec.o rawdec.o
 OBJS-$(CONFIG_W64_DEMUXER)               += wavdec.o w64.o pcm.o
 OBJS-$(CONFIG_W64_MUXER)                 += wavenc.o w64.o
 OBJS-$(CONFIG_WAV_DEMUXER)               += wavdec.o pcm.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index f837ddabc8..fb06723fb9 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -463,6 +463,7 @@  extern AVOutputFormat ff_voc_muxer;
 extern AVInputFormat  ff_vpk_demuxer;
 extern AVInputFormat  ff_vplayer_demuxer;
 extern AVInputFormat  ff_vqf_demuxer;
+extern AVInputFormat  ff_vvc_demuxer;
 extern AVInputFormat  ff_w64_demuxer;
 extern AVOutputFormat ff_w64_muxer;
 extern AVInputFormat  ff_wav_demuxer;
diff --git a/libavformat/vvcdec.c b/libavformat/vvcdec.c
new file mode 100644
index 0000000000..149f39f28e
--- /dev/null
+++ b/libavformat/vvcdec.c
@@ -0,0 +1,61 @@ 
+/*
+ * RAW VVC video demuxer
+ * Copyright (c) 2020 Nuo Mi <nuomi2021@gmail.com>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavcodec/vvc.h"
+
+#include "avformat.h"
+#include "rawdec.h"
+
+static int vvc_probe(const AVProbeData *p)
+{
+    uint32_t code = -1;
+    int sps = 0, pps = 0, irap = 0;
+    int i;
+
+    for (i = 0; i < p->buf_size - 1; i++) {
+        code = (code << 8) + p->buf[i];
+        if ((code & 0xffffff00) == 0x100) {
+            uint8_t nal2 = p->buf[i + 1];
+            int type = (nal2 & 0xF8) >> 3;
+
+            if (code & 0xc0) // forbidden_zero_bit and nuh_reserved_zero_bit
+                return 0;
+
+            if ((nal2 & 0x7) == 0) // nuh_temporal_id_plus1
+                return 0;
+
+            switch (type) {
+            case VVC_SPS_NUT:       sps++;  break;
+            case VVC_PPS_NUT:       pps++;  break;
+            case VVC_IDR_N_LP:
+            case VVC_IDR_W_RADL:
+            case VVC_CRA_NUT:
+            case VVC_GDR_NUT:       irap++; break;
+            }
+        }
+    }
+
+    if (sps && pps && irap)
+        return AVPROBE_SCORE_EXTENSION + 1; // 1 more than .mpg
+    return 0;
+}
+
+FF_DEF_RAWVIDEO_DEMUXER(vvc, "raw VVC video", vvc_probe, "h266,266,vvc", AV_CODEC_ID_VVC)