summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Siedel <thomas.ff@spin-digital.com>2023-03-21 16:01:19 +0100
committerJames Almer <jamrial@gmail.com>2023-06-29 14:12:50 -0300
commitac2b25f4e5ad0f03cf2a17c82defe2b1ba7a02b1 (patch)
tree6319fdf6319577d28f9133a50b07bb88e135a9c1
parent86796f1f0ef7d18395943f4cf5b3afbac87e4d65 (diff)
avformat: add demuxer and probe support for H266/VVC
Add demuxer to probe raw vvc and parse vvcc byte stream format. Co-authored-by: Nuo Mi <nuomi2021@gmail.com> Signed-off-by: James Almer <jamrial@gmail.com>
-rw-r--r--Changelog2
-rw-r--r--libavformat/Makefile1
-rw-r--r--libavformat/allformats.c1
-rw-r--r--libavformat/demux.c7
-rw-r--r--libavformat/vvcdec.c61
5 files changed, 69 insertions, 3 deletions
diff --git a/Changelog b/Changelog
index 1e85826c66..9a05ebe016 100644
--- a/Changelog
+++ b/Changelog
@@ -22,7 +22,7 @@ version <next>:
- bwdif_cuda filter
- Microsoft RLE video encoder
- Raw AC-4 muxer and demuxer
-- Raw VVC bitstream parser
+- Raw VVC bitstream parser and demuxer
- Bitstream filter for editing metadata in VVC streams
- Bitstream filter for converting VVC from MP4 to Annex B
diff --git a/libavformat/Makefile b/libavformat/Makefile
index 2b90b788c0..239b779d1e 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -603,6 +603,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_WADY_DEMUXER) += wady.o pcm.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index f64b0870aa..05c4e47a63 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -486,6 +486,7 @@ extern const FFOutputFormat ff_voc_muxer;
extern const AVInputFormat ff_vpk_demuxer;
extern const AVInputFormat ff_vplayer_demuxer;
extern const AVInputFormat ff_vqf_demuxer;
+extern const AVInputFormat ff_vvc_demuxer;
extern const AVInputFormat ff_w64_demuxer;
extern const FFOutputFormat ff_w64_muxer;
extern const AVInputFormat ff_wady_demuxer;
diff --git a/libavformat/demux.c b/libavformat/demux.c
index 1b21b8440c..1ef297d5e7 100644
--- a/libavformat/demux.c
+++ b/libavformat/demux.c
@@ -121,6 +121,7 @@ static int set_codec_from_probe_data(AVFormatContext *s, AVStream *st,
{ "mpegvideo", AV_CODEC_ID_MPEG2VIDEO, AVMEDIA_TYPE_VIDEO },
{ "truehd", AV_CODEC_ID_TRUEHD, AVMEDIA_TYPE_AUDIO },
{ "evc", AV_CODEC_ID_EVC, AVMEDIA_TYPE_VIDEO },
+ { "vvc", AV_CODEC_ID_VVC, AVMEDIA_TYPE_VIDEO },
{ 0 }
};
int score;
@@ -753,7 +754,8 @@ static int64_t select_from_pts_buffer(AVStream *st, int64_t *pts_buffer, int64_t
{
FFStream *const sti = ffstream(st);
int onein_oneout = st->codecpar->codec_id != AV_CODEC_ID_H264 &&
- st->codecpar->codec_id != AV_CODEC_ID_HEVC;
+ st->codecpar->codec_id != AV_CODEC_ID_HEVC &&
+ st->codecpar->codec_id != AV_CODEC_ID_VVC;
if (!onein_oneout) {
int delay = sti->avctx->has_b_frames;
@@ -943,7 +945,8 @@ static void compute_pkt_fields(AVFormatContext *s, AVStream *st,
int64_t offset;
AVRational duration;
int onein_oneout = st->codecpar->codec_id != AV_CODEC_ID_H264 &&
- st->codecpar->codec_id != AV_CODEC_ID_HEVC;
+ st->codecpar->codec_id != AV_CODEC_ID_HEVC &&
+ st->codecpar->codec_id != AV_CODEC_ID_VVC;
if (s->flags & AVFMT_FLAG_NOFILLIN)
return;
diff --git a/libavformat/vvcdec.c b/libavformat/vvcdec.c
new file mode 100644
index 0000000000..31c5ae1f14
--- /dev/null
+++ b/libavformat/vvcdec.c
@@ -0,0 +1,61 @@
+/*
+ * RAW H.266 / 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 & 0x80) // forbidden_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 H.266/VVC video", vvc_probe, "h266,266,vvc", AV_CODEC_ID_VVC)