From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 88C31420A1 for ; Fri, 26 Aug 2022 19:44:43 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3575368B9D2; Fri, 26 Aug 2022 22:44:40 +0300 (EEST) Received: from relay10.mail.gandi.net (relay10.mail.gandi.net [217.70.178.230]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7712568B84E for ; Fri, 26 Aug 2022 22:44:33 +0300 (EEST) Received: (Authenticated sender: michael@niedermayer.cc) by mail.gandi.net (Postfix) with ESMTPSA id 8A7CE240007 for ; Fri, 26 Aug 2022 19:44:32 +0000 (UTC) Date: Fri, 26 Aug 2022 21:44:30 +0200 From: Michael Niedermayer To: FFmpeg development discussions and patches Message-ID: <20220826194430.GW2088045@pb2> References: <014b01d8b887$80de7cf0$829b76d0$@samsung.com> MIME-Version: 1.0 In-Reply-To: <014b01d8b887$80de7cf0$829b76d0$@samsung.com> Subject: Re: [FFmpeg-devel] [FFmpeg-devel v10 4/9] Added demuxer to handle reading EVC video files X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Content-Type: multipart/mixed; boundary="===============8676976476864986171==" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: --===============8676976476864986171== Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="tnSXTZOLuLJuusSZ" Content-Disposition: inline --tnSXTZOLuLJuusSZ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Aug 25, 2022 at 03:35:12PM +0200, Dawid Kozinski wrote: > - Provided AVInputFormat structure describing EVC input format (ff_evc_de= muxer) >=20 > Signed-off-by: Dawid Kozinski > --- > libavformat/Makefile | 1 + > libavformat/allformats.c | 1 + > libavformat/evcdec.c | 142 +++++++++++++++++++++++++++++++++++++++ > 3 files changed, 144 insertions(+) > create mode 100644 libavformat/evcdec.c >=20 > diff --git a/libavformat/Makefile b/libavformat/Makefile > index 7e3f0e6794..a320cac22b 100644 > --- a/libavformat/Makefile > +++ b/libavformat/Makefile > @@ -249,6 +249,7 @@ OBJS-$(CONFIG_HCOM_DEMUXER) +=3D hcom.o = pcm.o > OBJS-$(CONFIG_HDS_MUXER) +=3D hdsenc.o > OBJS-$(CONFIG_HEVC_DEMUXER) +=3D hevcdec.o rawdec.o > OBJS-$(CONFIG_HEVC_MUXER) +=3D rawenc.o > +OBJS-$(CONFIG_EVC_DEMUXER) +=3D evcdec.o rawdec.o > OBJS-$(CONFIG_EVC_MUXER) +=3D rawenc.o > OBJS-$(CONFIG_HLS_DEMUXER) +=3D hls.o hls_sample_encryptio= n.o > OBJS-$(CONFIG_HLS_MUXER) +=3D hlsenc.o hlsplaylist.o avc= =2Eo > diff --git a/libavformat/allformats.c b/libavformat/allformats.c > index 31508b69f0..dfce49d149 100644 > --- a/libavformat/allformats.c > +++ b/libavformat/allformats.c > @@ -148,6 +148,7 @@ extern const AVInputFormat ff_ea_cdata_demuxer; > extern const AVInputFormat ff_eac3_demuxer; > extern const AVOutputFormat ff_eac3_muxer; > extern const AVInputFormat ff_epaf_demuxer; > +extern const AVInputFormat ff_evc_demuxer; > extern const AVOutputFormat ff_evc_muxer; > extern const AVOutputFormat ff_f4v_muxer; > extern const AVInputFormat ff_ffmetadata_demuxer; > diff --git a/libavformat/evcdec.c b/libavformat/evcdec.c > new file mode 100644 > index 0000000000..58dc671d24 > --- /dev/null > +++ b/libavformat/evcdec.c > @@ -0,0 +1,142 @@ > +/* > + * RAW EVC video demuxer > + * > + * Copyright (c) 2021 Dawid Kozinski > + * > + * 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-1= 301 USA > + */ > + > +#include "libavcodec/get_bits.h" > +#include "libavcodec/golomb.h" > +#include "libavcodec/internal.h" > + > +#include "rawdec.h" > +#include "avformat.h" > + > +// The length field that indicates the length in bytes of the following = NAL unit is configured to be of 4 bytes > +#define EVC_NAL_UNIT_LENGTH_BYTE (4) /* byte */ > + > +#define EVC_NAL_HEADER_SIZE (2) /* byte */ > +#define MAX_SPS_CNT (16) /* defined value in EVC sta= ndard */ > + > +// NALU types > +// @see ISO_IEC_23094-1_2020 7.4.2.2 NAL unit header semantics > +// > +#define EVC_NUT_NONIDR (0) /* Coded slice of a non-IDR= picture */ > +#define EVC_NUT_IDR (1) /* Coded slice of an IDR pi= cture */ > +#define EVC_NUT_SPS (24) /* Sequence parameter set */ > +#define EVC_NUT_PPS (25) /* Picture paremeter set */ > +#define EVC_NUT_APS (26) /* Adaptation parameter set= */ > +#define EVC_NUT_FD (27) /* Filler data */ > +#define EVC_NUT_SEI (28) /* Supplemental enhancement= information */ > + > +typedef struct EVCParserContext { > + int got_sps; > + int got_pps; > + int got_idr; > + int got_nonidr; > +} EVCParserContext; > + > +static int get_nalu_type(const uint8_t *bits, int bits_size) > +{ > + int unit_type_plus1 =3D 0; > + > + if(bits_size >=3D EVC_NAL_HEADER_SIZE) { > + unsigned char *p =3D (unsigned char *)bits; > + // forbidden_zero_bit > + if ((p[0] & 0x80) !=3D 0) { > + av_log(NULL, AV_LOG_ERROR, "Cannot get bitstream information= =2E Malformed bitstream.\n"); > + return -1; > + } > + > + // nal_unit_type > + unit_type_plus1 =3D (p[0] >> 1) & 0x3F; > + } > + > + return unit_type_plus1 - 1; > +} > + > +static uint32_t read_nal_unit_length(const uint8_t *bits, int bits_size) > +{ > + uint32_t nalu_len =3D 0; > + > + if(bits_size >=3D EVC_NAL_UNIT_LENGTH_BYTE) { > + > + int t =3D 0; > + unsigned char *p =3D (unsigned char *)bits; > + > + for(int i=3D0; i + t =3D (t << 8) | p[i]; > + } > + > + nalu_len =3D t; > + if(nalu_len =3D=3D 0) { > + av_log(NULL, AV_LOG_ERROR, "Invalid bitstream size!\n"); > + return 0; > + } > + } > + > + return nalu_len; > +} > + > +static int parse_nal_units(const AVProbeData *p, EVCParserContext *ev) > +{ > + int nalu_type; > + size_t nalu_size; > + unsigned char *bits =3D (unsigned char *)p->buf; > + int bytes_to_read =3D p->buf_size; > + > + while(bytes_to_read > EVC_NAL_UNIT_LENGTH_BYTE) { > + > + nalu_size =3D read_nal_unit_length(bits, EVC_NAL_UNIT_LENGTH_BYT= E); > + if(nalu_size =3D=3D 0) break; > + > + bits +=3D EVC_NAL_UNIT_LENGTH_BYTE; > + bytes_to_read -=3D EVC_NAL_UNIT_LENGTH_BYTE; > + > + if(bytes_to_read < nalu_size) break; > + > + nalu_type =3D get_nalu_type(bits, bytes_to_read); > + > + bits +=3D nalu_size; > + bytes_to_read -=3D nalu_size; > + > + if (nalu_type =3D=3D EVC_NUT_SPS) > + ev->got_sps++; > + else if (nalu_type =3D=3D EVC_NUT_PPS) > + ev->got_pps++; > + else if (nalu_type =3D=3D EVC_NUT_IDR ) > + ev->got_idr++; > + else if (nalu_type =3D=3D EVC_NUT_NONIDR) > + ev->got_nonidr++; > + } > + > + return 0; > +} > + > +static int evc_probe(const AVProbeData *p) > +{ > + EVCParserContext ev =3D {0}; > + int ret =3D parse_nal_units(p, &ev); > + > + if (ret =3D=3D 0 && ev.got_sps && ev.got_pps && (ev.got_idr || ev.go= t_nonidr > 3)) > + return AVPROBE_SCORE_EXTENSION + 1; // 1 more than .mpg > + > + return 0; > +} This function is very noisy Try make -j32 tools/probetest && tools/probetest 256 4096 there are pages of: Invalid bitstream size! Cannot get bitstream information. Malformed bitstream. Invalid bitstream size! Invalid bitstream size! This is a problem because programs must probe their input and it is not always every format so formats must be silent when data is not correct during probing Thanks [...] --=20 Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB I know you won't believe me, but the highest form of Human Excellence is to question oneself and others. -- Socrates --tnSXTZOLuLJuusSZ Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iF0EABEIAB0WIQSf8hKLFH72cwut8TNhHseHBAsPqwUCYwkimgAKCRBhHseHBAsP q9AEAJ0V7BRoULMUVWZwxoK4gmI9qu9wSACcCkCq3yfPwaW8AF+/muxhf4odTfw= =PQRo -----END PGP SIGNATURE----- --tnSXTZOLuLJuusSZ-- --===============8676976476864986171== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ 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". --===============8676976476864986171==--