[FFmpeg-devel] [PATCH 3/6] avformat: add h266 raw demux

Nuo Mi nuomi2021 at gmail.com
Mon Dec 21 08:07:07 EET 2020


---
 libavformat/Makefile     |  1 +
 libavformat/allformats.c |  1 +
 libavformat/h266dec.c    | 61 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 63 insertions(+)
 create mode 100644 libavformat/h266dec.c

diff --git a/libavformat/Makefile b/libavformat/Makefile
index 97d868081b..c685aad66e 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -231,6 +231,7 @@ OBJS-$(CONFIG_H263_DEMUXER)              += h263dec.o rawdec.o
 OBJS-$(CONFIG_H263_MUXER)                += rawenc.o
 OBJS-$(CONFIG_H264_DEMUXER)              += h264dec.o rawdec.o
 OBJS-$(CONFIG_H264_MUXER)                += rawenc.o
+OBJS-$(CONFIG_H266_DEMUXER)              += h266dec.o rawdec.o
 OBJS-$(CONFIG_HASH_MUXER)                += hashenc.o
 OBJS-$(CONFIG_HCA_DEMUXER)               += hca.o
 OBJS-$(CONFIG_HCOM_DEMUXER)              += hcom.o pcm.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index 0e0caaad39..8b64b4eb4b 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -189,6 +189,7 @@ extern AVInputFormat  ff_h263_demuxer;
 extern AVOutputFormat ff_h263_muxer;
 extern AVInputFormat  ff_h264_demuxer;
 extern AVOutputFormat ff_h264_muxer;
+extern AVInputFormat  ff_h266_demuxer;
 extern AVOutputFormat ff_hash_muxer;
 extern AVInputFormat  ff_hca_demuxer;
 extern AVInputFormat  ff_hcom_demuxer;
diff --git a/libavformat/h266dec.c b/libavformat/h266dec.c
new file mode 100644
index 0000000000..bf0de5b829
--- /dev/null
+++ b/libavformat/h266dec.c
@@ -0,0 +1,61 @@
+/*
+ * RAW H266 video demuxer
+ * Copyright (c) 2020 Nuo Mi <nuomi2021 at 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/h266.h"
+
+#include "avformat.h"
+#include "rawdec.h"
+
+static int h266_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 H266_NAL_SPS:       sps++;  break;
+            case H266_NAL_PPS:       pps++;  break;
+            case H266_NAL_IDR_N_LP:
+            case H266_NAL_IDR_W_RADL:
+            case H266_NAL_CRA_NUT:
+            case H266_NAL_GDR_NUT:   irap++; break;
+            }
+        }
+    }
+
+    if (sps && pps && irap)
+        return AVPROBE_SCORE_EXTENSION + 1; // 1 more than .mpg
+    return 0;
+}
+
+FF_DEF_RAWVIDEO_DEMUXER(h266, "raw H266 video", h266_probe, "h266,266,vvc", AV_CODEC_ID_H266)
-- 
2.25.1



More information about the ffmpeg-devel mailing list