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>
This commit is contained in:
Thomas Siedel 2023-03-21 16:01:19 +01:00 committed by James Almer
parent 86796f1f0e
commit ac2b25f4e5
5 changed files with 69 additions and 3 deletions

View File

@ -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

View File

@ -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

View File

@ -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;

View File

@ -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;

61
libavformat/vvcdec.c Normal file
View File

@ -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)