From patchwork Wed Apr 12 04:27:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Liu X-Patchwork-Id: 41103 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4645:b0:e3:3194:9d20 with SMTP id eb5csp197206pzb; Tue, 11 Apr 2023 21:27:44 -0700 (PDT) X-Google-Smtp-Source: AKy350bYGCdv+iiwlWJJM4nsdBXk/7a5HQo89u7ISjhpEsL75rUQCLjnZuzFMFs1b0hzr7lz69Tv X-Received: by 2002:a17:906:988e:b0:930:e9ee:c474 with SMTP id zc14-20020a170906988e00b00930e9eec474mr4953702ejb.54.1681273664014; Tue, 11 Apr 2023 21:27:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681273664; cv=none; d=google.com; s=arc-20160816; b=FtJXtsjwneh3OnKwG4OTfbKnzBfYuDU6hwZJBMyIwCsXeXoahRt+Vz567IWlCzn2t8 GGGCb2aCHvwfJXkF2CkjacAvQdJ5RQRSeU4KlSeFg/5CzO7hUO2y+6tiHnpzLD9lLVWP q8L6LmrnN+uGowsmMvGvuHBOG9uj5q9en8nFvLFDgDwHDnPfeneiOiol0hnqur3J3EWT PzykrE6xwGbceZlPamsEHbpRHwXoV7iQb6TthziZewvHhlBG5rdVCIS4QnKVnCTankRA WuAjb4AzuR+Buh1pKCXXPPJn6o6/ZzWuUQ+mjgof3Zn5I0FU02KrAlR+m1t/z6ZfkRay GXMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:feedback-id:mime-version:references :in-reply-to:message-id:date:to:from:delivered-to; bh=YioaGeoWSJQZiby+yIpiB7jHaeq70CJqapu6n3k2TIM=; b=A1DRZ5jgBB8N5j1LFlptXYVUT+/6bmcIIUlrtm7SN/UWTqcKcd+Y7XKhAkunJmGtay PWtLJiF/vG6VDLmiK14550KAE7JyCzmuTQhXxqIM+tcSSfubri30hN0wmwffAgnBkBfW T/y2qm+yuBS1+0b0ZAU0526qasl4HB49rKF9MaJsWJlCUnpdazHGyPd+IkX4P2o4tYpf oyFigvT6pVZMP1gMeVl+alitH49dfTO6InZgs/DkL9CbVyMt7A2uxmA/txTyQfKduPfO arEDqjhwmzI6h+sFjDaMKCJhIZaSg7xm4Z8XZlEQCeFvZrHgvwYK6tvJWEP22qTXUnHY c8UQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id gn33-20020a1709070d2100b0094d69b1176csi889544ejc.968.2023.04.11.21.27.43; Tue, 11 Apr 2023 21:27:43 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 27D6368BCA9; Wed, 12 Apr 2023 07:27:39 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.221.58]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6EDB968093C for ; Wed, 12 Apr 2023 07:27:30 +0300 (EEST) X-QQ-mid: bizesmtpipv603t1681273643t1vq Received: from localhost ( [255.142.19.15]) by bizesmtp.qq.com (ESMTP) with id ; Wed, 12 Apr 2023 12:27:22 +0800 (CST) X-QQ-SSF: 01100000000000Z0Z000000A0000000 X-QQ-FEAT: dFVR8TEWHmtIwh8+uUJHhEDqAuYCTJXU/MsparXRwNEzG18U/bluRT5k5yK73 LBNNPyJ9CaZONnOxbkai1zJ+7BfFXmOUCTkB/oZ6OkzNcmhhlRDrzqW/EZUxQsShDxJ4Xwx SHmoAI8ckqNUcB9JJ/tIz4Xz6+5ERdMjjaf29JNm+wHz0chjtr6Pm1dOUTl+88W0IBSJXFc kaHg8Oy3bnd1vvC3D/b4bY/+frkzNW3Fm0LLiD0YfOZdgtTKt3YLj5mm5Ij+paCw6j1OxGz 2kmQaVTdqYRRqoYKEti0VO4tWE7HTUlKjpyATatvQF77jepKwtdeprvL2rrJ2MeaiKNTsYG IqdWF7LboAJ13GyAt37IJpP8znqqQ== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 18285327595202144294 From: Steven Liu To: ffmpeg-devel@ffmpeg.org Date: Wed, 12 Apr 2023 12:27:16 +0800 Message-Id: <20230412042719.6173-1-lq@chinaffmpeg.org> X-Mailer: git-send-email 2.40.0 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtpipv:chinaffmpeg.org:qybglogicsvr:qybglogicsvr2 Subject: [FFmpeg-devel] [PATCH v4 1/4] avformat/flvenc: Add support for HEVC over flv in muxer 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 Cc: Steven Liu Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: Ss9IPH5umgpT Implements HEVC according to Enhanced FLV spec found at https://github.com/veovera/enhanced-rtmp And it has beed supported by OBS, Simple Realtime Server, mpegts.js. And the enhanced FLV documentation contributors include Jean-Baptiste Kempf (FFmpeg, VideoLAN). So this should be support by ffmpeg too. Signed-off-by: Steven Liu --- libavformat/flv.h | 16 ++++++++++++++ libavformat/flvenc.c | 50 +++++++++++++++++++++++++++++++++----------- 2 files changed, 54 insertions(+), 12 deletions(-) diff --git a/libavformat/flv.h b/libavformat/flv.h index 3571b90279..44d3b04ff9 100644 --- a/libavformat/flv.h +++ b/libavformat/flv.h @@ -35,6 +35,12 @@ #define FLV_VIDEO_FRAMETYPE_OFFSET 4 +/* Extended VideoTagHeader + * defined in reference link: + * https://github.com/veovera/enhanced-rtmp/blob/main/enhanced-rtmp-v1.pdf + * */ +#define FLV_IS_EX_HEADER 0x80 + /* bitmasks to isolate specific values */ #define FLV_AUDIO_CHANNEL_MASK 0x01 #define FLV_AUDIO_SAMPLESIZE_MASK 0x02 @@ -110,6 +116,16 @@ enum { FLV_CODECID_H264 = 7, FLV_CODECID_REALH263= 8, FLV_CODECID_MPEG4 = 9, + FLV_CODECID_HEVC = 10, +}; + +enum { + PacketTypeSequenceStart = 0, + PacketTypeCodedFrames = 1, + PacketTypeSequenceEnd = 2, + PacketTypeCodedFramesX = 3, + PacketTypeMetadata = 4, + PacketTypeMPEG2TSSequenceStart = 5, }; enum { diff --git a/libavformat/flvenc.c b/libavformat/flvenc.c index fbf7eabaf8..0f26ff99e8 100644 --- a/libavformat/flvenc.c +++ b/libavformat/flvenc.c @@ -28,6 +28,7 @@ #include "libavcodec/mpeg4audio.h" #include "avio.h" #include "avc.h" +#include "hevc.h" #include "avformat.h" #include "flv.h" #include "internal.h" @@ -46,6 +47,7 @@ static const AVCodecTag flv_video_codec_ids[] = { { AV_CODEC_ID_VP6, FLV_CODECID_VP6 }, { AV_CODEC_ID_VP6A, FLV_CODECID_VP6A }, { AV_CODEC_ID_H264, FLV_CODECID_H264 }, + { AV_CODEC_ID_HEVC, FLV_CODECID_HEVC }, { AV_CODEC_ID_NONE, 0 } }; @@ -492,7 +494,7 @@ static void flv_write_codec_header(AVFormatContext* s, AVCodecParameters* par, i FLVContext *flv = s->priv_data; if (par->codec_id == AV_CODEC_ID_AAC || par->codec_id == AV_CODEC_ID_H264 - || par->codec_id == AV_CODEC_ID_MPEG4) { + || par->codec_id == AV_CODEC_ID_MPEG4 || par->codec_id == AV_CODEC_ID_HEVC) { int64_t pos; avio_w8(pb, par->codec_type == AVMEDIA_TYPE_VIDEO ? @@ -535,10 +537,19 @@ static void flv_write_codec_header(AVFormatContext* s, AVCodecParameters* par, i } avio_write(pb, par->extradata, par->extradata_size); } else { - avio_w8(pb, par->codec_tag | FLV_FRAME_KEY); // flags - avio_w8(pb, 0); // AVC sequence header - avio_wb24(pb, 0); // composition time - ff_isom_write_avcc(pb, par->extradata, par->extradata_size); + if (par->codec_id == AV_CODEC_ID_HEVC) { + avio_w8(pb, FLV_IS_EX_HEADER | PacketTypeSequenceStart); // ExVideoTagHeader mode with PacketTypeSequenceStart + avio_write(pb, "hvc1", 4); + } else { + avio_w8(pb, par->codec_tag | FLV_FRAME_KEY); // flags + avio_w8(pb, 0); // AVC sequence header + avio_wb24(pb, 0); // composition time + } + + if (par->codec_id == AV_CODEC_ID_HEVC) + ff_isom_write_hvcc(pb, par->extradata, par->extradata_size, 0); + else + ff_isom_write_avcc(pb, par->extradata, par->extradata_size); } data_size = avio_tell(pb) - pos; avio_seek(pb, -data_size - 10, SEEK_CUR); @@ -628,7 +639,8 @@ static int flv_init(struct AVFormatContext *s) return unsupported_codec(s, "Video", par->codec_id); if (par->codec_id == AV_CODEC_ID_MPEG4 || - par->codec_id == AV_CODEC_ID_H263) { + par->codec_id == AV_CODEC_ID_H263 || + par->codec_id == AV_CODEC_ID_HEVC) { int error = s->strict_std_compliance > FF_COMPLIANCE_UNOFFICIAL; av_log(s, error ? AV_LOG_ERROR : AV_LOG_WARNING, "Codec %s is not supported in the official FLV specification,\n", avcodec_get_name(par->codec_id)); @@ -784,8 +796,11 @@ end: for (i = 0; i < s->nb_streams; i++) { AVCodecParameters *par = s->streams[i]->codecpar; FLVStreamContext *sc = s->streams[i]->priv_data; - if (par->codec_type == AVMEDIA_TYPE_VIDEO && - (par->codec_id == AV_CODEC_ID_H264 || par->codec_id == AV_CODEC_ID_MPEG4)) + if (par->codec_id == AV_CODEC_ID_HEVC) { + avio_w8(pb, 0x82); + avio_write(pb, "hvc1", 4); + } else if (par->codec_type == AVMEDIA_TYPE_VIDEO && + (par->codec_id == AV_CODEC_ID_H264 || par->codec_id == AV_CODEC_ID_MPEG4 || par->codec_id == AV_CODEC_ID_HEVC)) put_eos_tag(pb, sc->last_ts, par->codec_id); } } @@ -836,13 +851,13 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt) if (par->codec_id == AV_CODEC_ID_VP6F || par->codec_id == AV_CODEC_ID_VP6A || par->codec_id == AV_CODEC_ID_VP6 || par->codec_id == AV_CODEC_ID_AAC) flags_size = 2; - else if (par->codec_id == AV_CODEC_ID_H264 || par->codec_id == AV_CODEC_ID_MPEG4) + else if (par->codec_id == AV_CODEC_ID_H264 || par->codec_id == AV_CODEC_ID_MPEG4 || par->codec_id == AV_CODEC_ID_HEVC) flags_size = 5; else flags_size = 1; if (par->codec_id == AV_CODEC_ID_AAC || par->codec_id == AV_CODEC_ID_H264 - || par->codec_id == AV_CODEC_ID_MPEG4) { + || par->codec_id == AV_CODEC_ID_MPEG4 || par->codec_id == AV_CODEC_ID_HEVC) { size_t side_size; uint8_t *side = av_packet_get_side_data(pkt, AV_PKT_DATA_NEW_EXTRADATA, &side_size); if (side && side_size > 0 && (side_size != par->extradata_size || memcmp(side, par->extradata, side_size))) { @@ -862,7 +877,7 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt) "Packets are not in the proper order with respect to DTS\n"); return AVERROR(EINVAL); } - if (par->codec_id == AV_CODEC_ID_H264 || par->codec_id == AV_CODEC_ID_MPEG4) { + if (par->codec_id == AV_CODEC_ID_H264 || par->codec_id == AV_CODEC_ID_MPEG4 || par->codec_id == AV_CODEC_ID_HEVC) { if (pkt->pts == AV_NOPTS_VALUE) { av_log(s, AV_LOG_ERROR, "Packet is missing PTS\n"); return AVERROR(EINVAL); @@ -907,6 +922,10 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt) if (par->extradata_size > 0 && *(uint8_t*)par->extradata != 1) if ((ret = ff_avc_parse_nal_units_buf(pkt->data, &data, &size)) < 0) return ret; + } else if (par->codec_id == AV_CODEC_ID_HEVC) { + if (par->extradata_size > 0 && *(uint8_t*)par->extradata != 1) + if ((ret = ff_hevc_annexb2mp4_buf(pkt->data, &data, &size, 0, NULL)) < 0) + return ret; } else if (par->codec_id == AV_CODEC_ID_AAC && pkt->size > 2 && (AV_RB16(pkt->data) & 0xfff0) == 0xfff0) { if (!s->streams[pkt->stream_index]->nb_frames) { @@ -968,7 +987,12 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt) avio_wb32(pb, data_size + 11); } else { av_assert1(flags>=0); - avio_w8(pb,flags); + if (par->codec_id == AV_CODEC_ID_HEVC) { + avio_w8(pb, FLV_IS_EX_HEADER | PacketTypeCodedFrames); // ExVideoTagHeader mode with PacketTypeCodedFrames + avio_write(pb, "hvc1", 4); + } else { + avio_w8(pb, flags); + } if (par->codec_id == AV_CODEC_ID_VP6) avio_w8(pb,0); if (par->codec_id == AV_CODEC_ID_VP6F || par->codec_id == AV_CODEC_ID_VP6A) { @@ -982,6 +1006,8 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt) else if (par->codec_id == AV_CODEC_ID_H264 || par->codec_id == AV_CODEC_ID_MPEG4) { avio_w8(pb, 1); // AVC NALU avio_wb24(pb, pkt->pts - pkt->dts); + } else if (par->codec_id == AV_CODEC_ID_HEVC) { + avio_wb24(pb, pkt->pts - pkt->dts); } avio_write(pb, data ? data : pkt->data, size); From patchwork Wed Apr 12 04:27:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Liu X-Patchwork-Id: 41104 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4645:b0:e3:3194:9d20 with SMTP id eb5csp197274pzb; Tue, 11 Apr 2023 21:27:54 -0700 (PDT) X-Google-Smtp-Source: AKy350ZFlIVIxlMagiHGa5jqMHHCET/Y0eog9dWhQ8N+YnjHrJRNiLRfMzkdbCZ6N1v3UpLvuRD4 X-Received: by 2002:aa7:d358:0:b0:4ac:b687:f57e with SMTP id m24-20020aa7d358000000b004acb687f57emr3943369edr.1.1681273674334; Tue, 11 Apr 2023 21:27:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681273674; cv=none; d=google.com; s=arc-20160816; b=beZ2dYcRocdxXbXTW8+m5NVX5W95sqkJj0W9grFr0TL7zS1ySY9U6YVEizT326htgO SIOfapfgNA2jgyQnmpujwPfvWEJTQWWwpNtcnbxOVhrXNUZHQrOwZycWw8UZhUDzCfeR aquRIt2iwFBFFxapEbv7WQXs+Vo2YH1ECOVKH18/Lf6pp8xi78DIYPtgDpKUVLfZwgsF 3mWm5WJtFyQgfmD9Vny806LcQlSp5hFMikG0Rhugwu8r6V8WKRrUkI3Uynd+eCIroUae 5hOdl8yFjqNtYOHJeoHiXk5rCWGOykK4TC91VqDJQL6gm9sBlWrX+b9LFUbZku3zLV0w 80QA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:feedback-id:mime-version:references :in-reply-to:message-id:date:to:from:delivered-to; bh=Tn7xMgXeuKhjNdReSXJTNPJHk19dWAU19HhdR/f4/Hw=; b=Kil4BfybQ2GmAER3L9BJHPz6n4zYkxanJ3Dded//J8FJuKf8eMQfPpaGuoYdT+JQFb BFPGSnw3BPKI53y8ywUI/72L2HJK2srWkUTrTK/ecmeYL0UNk4c7DNIUdbGmGnmIbbU3 Oz8vD4qEJtJ8fTAuXHhqUdYPF1ocVoXJ5xOrflGXqxmC6vvjqlqbm7dJLtwizKH51EDN g7XEp5gjcj8/GFd0ouDOP4mKYwNWyBlnl3pAd38HZSWNGLUV5LCQRZCrIktNTu9IwTH7 NqG+XldZKnAz93m9hsUsYo97MimSwdjF3VSvWPx8OQzOYhwA78xQJsX47ivyMYWPmiKF noZw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id u10-20020a50eaca000000b004fbf06895ffsi464966edp.329.2023.04.11.21.27.53; Tue, 11 Apr 2023 21:27:54 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6044B68BCC3; Wed, 12 Apr 2023 07:27:45 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.155.67.158]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 318D768093C for ; Wed, 12 Apr 2023 07:27:36 +0300 (EEST) X-QQ-mid: bizesmtpipv601t1681273651t1o4 Received: from localhost ( [255.142.19.15]) by bizesmtp.qq.com (ESMTP) with id ; Wed, 12 Apr 2023 12:27:30 +0800 (CST) X-QQ-SSF: 01100000000000Z0Z000000A0000000 X-QQ-FEAT: OXH3MF60TyXmil6DfMEm4lu6NSUgvGt+AuMpvIu9khorJHhKtn4O5A37ArHah Fk63ATWrVoiROM6JfaDWmGju2Zh6k0mOi0E894NNRs72itqqutKJEEwj4dfzPeq7wWo0+hG sgPnELKJqTSDSGvZ5o6Cz6MlHOdtHQ2rPsK4IJ0jOcUzHWTa6eMeky4naQ2SbqRv6OXaH1D Jp1AzrfiAVrFfeVDWUfzWlxBTBHGGhb8RL63yYMEr0sMeN6TbFEt5m4B//agIpzJE6KFr/6 6Co1X5isAC3KXDxFhGkHW2WeaR0Ij3ZV/56jNJTfmS2UbKuqzJYMH1GCA+oNZqQJ4FlCJwv 43eURSg/i/i33BNDV1Tgzx0gT5Kym8kKmeO5y108TrnLT5YosldyDR2H/0G0Q== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 8761823023550366336 From: Steven Liu To: ffmpeg-devel@ffmpeg.org Date: Wed, 12 Apr 2023 12:27:17 +0800 Message-Id: <20230412042719.6173-2-lq@chinaffmpeg.org> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230412042719.6173-1-lq@chinaffmpeg.org> References: <20230412042719.6173-1-lq@chinaffmpeg.org> MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtpipv:chinaffmpeg.org:qybglogicsvr:qybglogicsvr2 Subject: [FFmpeg-devel] [PATCH v4 2/4] avformat/flvdec: support demux HEVC in Enhanced FLV 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 Cc: Steven Liu Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: dV9iO3Jb8HRh Signed-off-by: Steven Liu --- libavformat/flvdec.c | 63 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 56 insertions(+), 7 deletions(-) diff --git a/libavformat/flvdec.c b/libavformat/flvdec.c index d83edff727..8060c43772 100644 --- a/libavformat/flvdec.c +++ b/libavformat/flvdec.c @@ -79,6 +79,8 @@ typedef struct FLVContext { int64_t last_ts; int64_t time_offset; int64_t time_pos; + + uint8_t exheader; } FLVContext; /* AMF date type */ @@ -302,13 +304,26 @@ static void flv_set_audio_codec(AVFormatContext *s, AVStream *astream, } } -static int flv_same_video_codec(AVCodecParameters *vpar, int flags) +static int flv_same_video_codec(AVFormatContext *s, AVCodecParameters *vpar, int flags) { int flv_codecid = flags & FLV_VIDEO_CODECID_MASK; + FLVContext *flv = s->priv_data; if (!vpar->codec_id && !vpar->codec_tag) return 1; + if (flv->exheader) { + uint8_t *codec_id_str = (uint8_t *)s->pb->buf_ptr; + uint32_t codec_id = codec_id_str[3] | codec_id_str[2] << 8 | codec_id_str[1] << 16 | codec_id_str[0] << 24; + switch(codec_id) { + case MKBETAG('h', 'v', 'c', '1'): + flv_codecid = FLV_CODECID_HEVC; + break; + default: + break; + } + } + switch (flv_codecid) { case FLV_CODECID_H263: return vpar->codec_id == AV_CODEC_ID_FLV1; @@ -322,6 +337,8 @@ static int flv_same_video_codec(AVCodecParameters *vpar, int flags) return vpar->codec_id == AV_CODEC_ID_VP6A; case FLV_CODECID_H264: return vpar->codec_id == AV_CODEC_ID_H264; + case FLV_CODECID_HEVC: + return vpar->codec_id == AV_CODEC_ID_HEVC; default: return vpar->codec_tag == flv_codecid; } @@ -331,9 +348,23 @@ static int flv_set_video_codec(AVFormatContext *s, AVStream *vstream, int flv_codecid, int read) { FFStream *const vstreami = ffstream(vstream); + FLVContext *flv = s->priv_data; int ret = 0; AVCodecParameters *par = vstream->codecpar; enum AVCodecID old_codec_id = vstream->codecpar->codec_id; + flv_codecid &= FLV_VIDEO_CODECID_MASK; + + if (flv->exheader) { + uint32_t codec_id = avio_rb32(s->pb); + + switch(codec_id) { + case MKBETAG('h', 'v', 'c', '1'): + flv_codecid = FLV_CODECID_HEVC; + break; + default: + break; + } + } switch (flv_codecid) { case FLV_CODECID_H263: par->codec_id = AV_CODEC_ID_FLV1; @@ -372,6 +403,11 @@ static int flv_set_video_codec(AVFormatContext *s, AVStream *vstream, par->codec_id = AV_CODEC_ID_MPEG4; ret = 3; break; + case FLV_CODECID_HEVC: + par->codec_id = AV_CODEC_ID_HEVC; + vstreami->need_parsing = AVSTREAM_PARSE_HEADERS; + ret = 3; + break; default: avpriv_request_sample(s, "Video codec (%x)", flv_codecid); par->codec_tag = flv_codecid; @@ -796,6 +832,7 @@ static int flv_read_header(AVFormatContext *s) s->start_time = 0; flv->sum_flv_tag_size = 0; flv->last_keyframe_stream_index = -1; + flv->exheader = 0; return 0; } @@ -1071,6 +1108,11 @@ retry: } else if (type == FLV_TAG_TYPE_VIDEO) { stream_type = FLV_STREAM_TYPE_VIDEO; flags = avio_r8(s->pb); + /* + * Reference Enhancing FLV 2023-03-v1.0.0-B.8 + * https://github.com/veovera/enhanced-rtmp/blob/main/enhanced-rtmp-v1.pdf + * */ + flv->exheader = (flags >> 7) & 1; size--; if ((flags & FLV_VIDEO_FRAMETYPE_MASK) == FLV_FRAME_VIDEO_INFO_CMD) goto skip; @@ -1129,7 +1171,7 @@ skip: break; } else if (stream_type == FLV_STREAM_TYPE_VIDEO) { if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && - (s->video_codec_id || flv_same_video_codec(st->codecpar, flags))) + (s->video_codec_id || flv_same_video_codec(s, st->codecpar, flags))) break; } else if (stream_type == FLV_STREAM_TYPE_SUBTITLE) { if (st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) @@ -1230,7 +1272,7 @@ retry_duration: avcodec_parameters_free(&par); } } else if (stream_type == FLV_STREAM_TYPE_VIDEO) { - int ret = flv_set_video_codec(s, st, flags & FLV_VIDEO_CODECID_MASK, 1); + int ret = flv_set_video_codec(s, st, flags, 1); if (ret < 0) return ret; size -= ret; @@ -1242,8 +1284,14 @@ retry_duration: if (st->codecpar->codec_id == AV_CODEC_ID_AAC || st->codecpar->codec_id == AV_CODEC_ID_H264 || - st->codecpar->codec_id == AV_CODEC_ID_MPEG4) { - int type = avio_r8(s->pb); + st->codecpar->codec_id == AV_CODEC_ID_MPEG4 || + st->codecpar->codec_id == AV_CODEC_ID_HEVC) { + int type = 0; + if (flv->exheader) { + type = flags & 0x0F; + } else { + type = avio_r8(s->pb); + } size--; if (size < 0) { @@ -1251,7 +1299,8 @@ retry_duration: goto leave; } - if (st->codecpar->codec_id == AV_CODEC_ID_H264 || st->codecpar->codec_id == AV_CODEC_ID_MPEG4) { + if (st->codecpar->codec_id == AV_CODEC_ID_H264 || st->codecpar->codec_id == AV_CODEC_ID_MPEG4 + || (st->codecpar->codec_id == AV_CODEC_ID_HEVC && (flags & 0x0F))) { // sign extension int32_t cts = (avio_rb24(s->pb) + 0xff800000) ^ 0xff800000; pts = av_sat_add64(dts, cts); @@ -1267,7 +1316,7 @@ retry_duration: } } if (type == 0 && (!st->codecpar->extradata || st->codecpar->codec_id == AV_CODEC_ID_AAC || - st->codecpar->codec_id == AV_CODEC_ID_H264)) { + st->codecpar->codec_id == AV_CODEC_ID_H264 || st->codecpar->codec_id == AV_CODEC_ID_HEVC)) { AVDictionaryEntry *t; if (st->codecpar->extradata) { From patchwork Wed Apr 12 04:27:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Liu X-Patchwork-Id: 41105 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4645:b0:e3:3194:9d20 with SMTP id eb5csp197325pzb; Tue, 11 Apr 2023 21:28:03 -0700 (PDT) X-Google-Smtp-Source: AKy350avcODv9SoXBBNlmfe8ytJNa2hTuxcTFc2PhnzcnVE1SMiJ3v2GrM7pHFgmy9X4jQj0u+3Q X-Received: by 2002:a17:906:5ad5:b0:930:8fd7:789f with SMTP id x21-20020a1709065ad500b009308fd7789fmr4560121ejs.38.1681273682907; Tue, 11 Apr 2023 21:28:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681273682; cv=none; d=google.com; s=arc-20160816; b=vMRfDE7SdmJtU6hBx+aZ+6VQwZnx0yr1da6KwiJhdIT305+hFBsV/fHHgxVpOJq42W p8GuUXsj1c9h0k1ydxNk8/T+c9ddHJB/zXTODX5i8LrM3ZSOfGNNT0bo4hqhiwvXVf2t TY5WZu8hfkOzxRkgwqWidnySW0uwGloL+TmUwyxvw5x4Wnkc2anhxHtMB41QnFC4rrjD 020YJmcezZlmcEygNLzsQeWZ+9vqAM6CxGH6AaXpjg5ZweN4dON80i5dQoHnr9J/ba1P yf2Phvkj74TgV/phbAjGx7mARbbs3cDmJ3SnN0y5jTYdgWfhVhf7eakR4p493YBYZDwm MVCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:feedback-id:mime-version:references :in-reply-to:message-id:date:to:from:delivered-to; bh=TI1hnutsB2SASEaAPS4RHEORchQvr07bX5O2003DCmk=; b=d8gTVVRkY5QHGSMMtjcUN3KVy/C9Qc4z3zUkaqlPWNfe/7nXEg57XtfTUo1A0xdzAD uRd117yPMRuMpvs2Nr7l3WOj2DMX5iFq5Rwv3X3ev//+0p0EUA/cCkVvhTHaqYcjWKUO lP2ebyJkYRAb7YUyIyNASj2G2Dh6hqu0xE0RTXrPcQ8JdTFKzDohcWlKfSsKl6QRSzcz fgdjGqBX+0qCXAkR8vtDapqLs1kZ0U9XkninJWJUDK44XP73vu5jCwIUSMO/wzM+GKkZ wEOPEWfE0wiWhxB8sYGhjPygQ/mORMs4wzu45HNrHGh6Fe2qZj6cGA6oFaRbQ9cPL4oR dXBA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id b17-20020a1709063f9100b0094a561510c3si7329163ejj.532.2023.04.11.21.28.01; Tue, 11 Apr 2023 21:28:02 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9A10968BD00; Wed, 12 Apr 2023 07:27:52 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.221.58]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B73E768ADF2 for ; Wed, 12 Apr 2023 07:27:44 +0300 (EEST) X-QQ-mid: bizesmtpipv601t1681273659tkyc Received: from localhost ( [255.142.19.15]) by bizesmtp.qq.com (ESMTP) with id ; Wed, 12 Apr 2023 12:27:38 +0800 (CST) X-QQ-SSF: 01100000000000Z0Z000000A0000000 X-QQ-FEAT: o+V1LJLjbvzZ/gR4rgWaVPZv1B40mhJqJDK4RYGNcjC/cYm4j+pvoDmrzTuA4 yOKhhVudNVCCPEd8BHKI4b7EJo0Lp8iZ7DxPv3LLgg7387vmqG42h8cEJsqWpFG1yJ8xyHL bnxqxwymvKtUyAK980RjS5K5Bym7gp4qUYhZT90vxCy1pDUVCANRRT2w+WeDKpd3gih4CqQ yW1JJpM6bf+gdSHybZszwDJrKOYdtOK/nyeJgu2sI6UcLkrA6Pm1U/cH4ryIbjIhOWK6vG/ QBwXhS61sKz/x9ZuiL/NLN6re8n8avb4j11OxalsI3AAWCpcZrupVp+1y+gnb4liDU72bM3 YCFaDQo3GTlaehtzxzCfTDGMbZG/H4NiL+XUjxGJdLFjzkQw9s= X-QQ-GoodBg: 0 X-BIZMAIL-ID: 6674292787497040049 From: Steven Liu To: ffmpeg-devel@ffmpeg.org Date: Wed, 12 Apr 2023 12:27:18 +0800 Message-Id: <20230412042719.6173-3-lq@chinaffmpeg.org> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230412042719.6173-1-lq@chinaffmpeg.org> References: <20230412042719.6173-1-lq@chinaffmpeg.org> MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtpipv:chinaffmpeg.org:qybglogicsvr:qybglogicsvr2 Subject: [FFmpeg-devel] [PATCH v4 3/4] avformat/flvenc: support mux av1 in Enhanced FLV 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 Cc: Steven Liu Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: twy7whAAO5Mv Signed-off-by: Steven Liu --- libavformat/flvenc.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/libavformat/flvenc.c b/libavformat/flvenc.c index 0f26ff99e8..f58ab7a3b0 100644 --- a/libavformat/flvenc.c +++ b/libavformat/flvenc.c @@ -48,6 +48,7 @@ static const AVCodecTag flv_video_codec_ids[] = { { AV_CODEC_ID_VP6A, FLV_CODECID_VP6A }, { AV_CODEC_ID_H264, FLV_CODECID_H264 }, { AV_CODEC_ID_HEVC, FLV_CODECID_HEVC }, + { AV_CODEC_ID_AV1, FLV_CODECID_AV1 }, { AV_CODEC_ID_NONE, 0 } }; @@ -494,7 +495,8 @@ static void flv_write_codec_header(AVFormatContext* s, AVCodecParameters* par, i FLVContext *flv = s->priv_data; if (par->codec_id == AV_CODEC_ID_AAC || par->codec_id == AV_CODEC_ID_H264 - || par->codec_id == AV_CODEC_ID_MPEG4 || par->codec_id == AV_CODEC_ID_HEVC) { + || par->codec_id == AV_CODEC_ID_MPEG4 || par->codec_id == AV_CODEC_ID_HEVC + || par->codec_id == AV_CODEC_ID_AV1) { int64_t pos; avio_w8(pb, par->codec_type == AVMEDIA_TYPE_VIDEO ? @@ -540,6 +542,9 @@ static void flv_write_codec_header(AVFormatContext* s, AVCodecParameters* par, i if (par->codec_id == AV_CODEC_ID_HEVC) { avio_w8(pb, FLV_IS_EX_HEADER | PacketTypeSequenceStart); // ExVideoTagHeader mode with PacketTypeSequenceStart avio_write(pb, "hvc1", 4); + } else if (par->codec_id == AV_CODEC_ID_AV1) { + avio_w8(pb, FLV_IS_EX_HEADER | PacketTypeSequenceStart); + avio_write(pb, "av01", 4); } else { avio_w8(pb, par->codec_tag | FLV_FRAME_KEY); // flags avio_w8(pb, 0); // AVC sequence header @@ -548,6 +553,8 @@ static void flv_write_codec_header(AVFormatContext* s, AVCodecParameters* par, i if (par->codec_id == AV_CODEC_ID_HEVC) ff_isom_write_hvcc(pb, par->extradata, par->extradata_size, 0); + else if (par->codec_id == AV_CODEC_ID_AV1) + ff_isom_write_av1c(pb, par->extradata, par->extradata_size, 1); else ff_isom_write_avcc(pb, par->extradata, par->extradata_size); } @@ -640,7 +647,8 @@ static int flv_init(struct AVFormatContext *s) if (par->codec_id == AV_CODEC_ID_MPEG4 || par->codec_id == AV_CODEC_ID_H263 || - par->codec_id == AV_CODEC_ID_HEVC) { + par->codec_id == AV_CODEC_ID_HEVC || + par->codec_id == AV_CODEC_ID_AV1) { int error = s->strict_std_compliance > FF_COMPLIANCE_UNOFFICIAL; av_log(s, error ? AV_LOG_ERROR : AV_LOG_WARNING, "Codec %s is not supported in the official FLV specification,\n", avcodec_get_name(par->codec_id)); @@ -851,13 +859,15 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt) if (par->codec_id == AV_CODEC_ID_VP6F || par->codec_id == AV_CODEC_ID_VP6A || par->codec_id == AV_CODEC_ID_VP6 || par->codec_id == AV_CODEC_ID_AAC) flags_size = 2; - else if (par->codec_id == AV_CODEC_ID_H264 || par->codec_id == AV_CODEC_ID_MPEG4 || par->codec_id == AV_CODEC_ID_HEVC) + else if (par->codec_id == AV_CODEC_ID_H264 || par->codec_id == AV_CODEC_ID_MPEG4 || + par->codec_id == AV_CODEC_ID_HEVC || par->codec_id == AV_CODEC_ID_AV1) flags_size = 5; else flags_size = 1; if (par->codec_id == AV_CODEC_ID_AAC || par->codec_id == AV_CODEC_ID_H264 - || par->codec_id == AV_CODEC_ID_MPEG4 || par->codec_id == AV_CODEC_ID_HEVC) { + || par->codec_id == AV_CODEC_ID_MPEG4 || par->codec_id == AV_CODEC_ID_HEVC + || par->codec_id == AV_CODEC_ID_AV1) { size_t side_size; uint8_t *side = av_packet_get_side_data(pkt, AV_PKT_DATA_NEW_EXTRADATA, &side_size); if (side && side_size > 0 && (side_size != par->extradata_size || memcmp(side, par->extradata, side_size))) { @@ -877,7 +887,8 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt) "Packets are not in the proper order with respect to DTS\n"); return AVERROR(EINVAL); } - if (par->codec_id == AV_CODEC_ID_H264 || par->codec_id == AV_CODEC_ID_MPEG4 || par->codec_id == AV_CODEC_ID_HEVC) { + if (par->codec_id == AV_CODEC_ID_H264 || par->codec_id == AV_CODEC_ID_MPEG4 || + par->codec_id == AV_CODEC_ID_HEVC || par->codec_id == AV_CODEC_ID_AV1) { if (pkt->pts == AV_NOPTS_VALUE) { av_log(s, AV_LOG_ERROR, "Packet is missing PTS\n"); return AVERROR(EINVAL); @@ -990,6 +1001,9 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt) if (par->codec_id == AV_CODEC_ID_HEVC) { avio_w8(pb, FLV_IS_EX_HEADER | PacketTypeCodedFrames); // ExVideoTagHeader mode with PacketTypeCodedFrames avio_write(pb, "hvc1", 4); + } else if (par->codec_id == AV_CODEC_ID_AV1) { + avio_w8(pb, FLV_IS_EX_HEADER | PacketTypeCodedFrames); + avio_write(pb, "av01", 4); } else { avio_w8(pb, flags); } From patchwork Wed Apr 12 04:27:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Liu X-Patchwork-Id: 41106 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4645:b0:e3:3194:9d20 with SMTP id eb5csp197384pzb; Tue, 11 Apr 2023 21:28:11 -0700 (PDT) X-Google-Smtp-Source: AKy350a1SUJR3nji9rDbEcbJ8s9My6G19a1Qc0g1dHrsIxC90w4HnBJvL3xnGl6L5XeGcgaMMyHc X-Received: by 2002:a17:906:6447:b0:930:f953:9608 with SMTP id l7-20020a170906644700b00930f9539608mr15057534ejn.0.1681273690839; Tue, 11 Apr 2023 21:28:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681273690; cv=none; d=google.com; s=arc-20160816; b=TjVhdMCv5/KrscgaZ0eT6p0IfSieciiRt9Q9ELeqm7lHR1sD0YI9fJT70qkIKF8vHh caDS1OzCp3Q26kqpt6xBVk97Ypncf4mV0d2pcxIcaTsR3PnFIGuo7eu0hdQ7Hzb3EWMt 3d3cmwCNdTjGJbDiaAQPSRHyHdxFKWBxWD+NW6JzczfhhO/yM4Zk+RjQO6HxUtnC9XjO H5oC2lxqLTCPoCwB9DyqTurxcmXT6fsmIki6UoQ/NwI2/DoNWFMZJx0RbH2jL6c7KK/i WyfQHFkYSv4KIwU2k1ZMrFMhkpFcAmc3n0zIEuqZCXgwz+Q2HG6tfI++2+aZjZPkaqbg pH6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:feedback-id:mime-version:references :in-reply-to:message-id:date:to:from:delivered-to; bh=wScHIIf8zoc/7GQsrPMIVOtsE4Ba/K5DqFZtmfQtXzM=; b=LU+bdwevGOOYWcvAXHb+6oIYkYBh0vxyxGa0IoQcNqPh48B9Wbq5rrZSOTamYCMbcY k2/5yWvBBVO0kXQXERejeRaf1eCZ02h8Z51agpXn+RjOaQKPw8PNOu+0XrmGEekY+pEC eb66xvr7VtsJlaBdwAEt65mBuAS6az1/vd1vsTPJA4KmFrqjf9kcnpg09fHHW3n34qAt HadG6wabbsf+Jx+6Ccf9mf86oJriD+quUKeHz3hbdGU7UwK6YCoBtcNENW38o/GtBiO6 8aXZLT2pO6QdYrMFuySRplEOqM5MV4qoGTA0er7++dLw6Dg4kDTV46oIwAOlBsF0KCr8 6x7g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id o6-20020a1709064f8600b009263490cbeasi3534799eju.92.2023.04.11.21.28.10; Tue, 11 Apr 2023 21:28:10 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id AF10C68BD38; Wed, 12 Apr 2023 07:27:58 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.155.67.158]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9A78C68BCE3 for ; Wed, 12 Apr 2023 07:27:50 +0300 (EEST) X-QQ-mid: bizesmtpipv602t1681273665tua6 Received: from localhost ( [255.142.19.15]) by bizesmtp.qq.com (ESMTP) with id ; Wed, 12 Apr 2023 12:27:44 +0800 (CST) X-QQ-SSF: 01100000000000Z0Z000000A0000000 X-QQ-FEAT: 83ShfzFP0oCyhCLRBYrIO3Ak6qmlXDRPm2Q9ouOjDT8zLVStYCtj8FMBNavxj 2FtVdUEc+S/sWbxthn/YuR4+7qxUEZ23/blcbLivRwPe84B80p5c4+Z9DsUYGGjXhZuKAXn qN9MPRZ5oMf3pwNiXKbpsNze0Ls6QKOqex6eIJb0DE/UOqwddyK77BP8DRDzuNX7t7P6Ykf 44dVzJgp1QbWXDRrY+7rfuxv5qFI3HfR7Ex3zyvujo5qGXDkuH1QP7Osrj3MsxiHpyhN7bi hnX2n34/fw4UulC+/WDMK+Q5BdWTar1Eoy5gXFa1jebRlS7/LB/7TlX5kH0rc90nIGlxNgv hJGySj3da4Cpq1HAoumDlPKQlCAN8bmUzRvKvfjv3OBWzqHQag= X-QQ-GoodBg: 0 X-BIZMAIL-ID: 1807543429436310198 From: Steven Liu To: ffmpeg-devel@ffmpeg.org Date: Wed, 12 Apr 2023 12:27:19 +0800 Message-Id: <20230412042719.6173-4-lq@chinaffmpeg.org> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230412042719.6173-1-lq@chinaffmpeg.org> References: <20230412042719.6173-1-lq@chinaffmpeg.org> MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtpipv:chinaffmpeg.org:qybglogicsvr:qybglogicsvr2 Subject: [FFmpeg-devel] [PATCH v4 4/4] avformat/flvdec: support demux av1 in Enhanced FLV 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 Cc: Steven Liu Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: tCQlO6Q4RDl+ Signed-off-by: Steven Liu --- libavformat/flv.h | 1 + libavformat/flvdec.c | 20 ++++++++++++++++++-- libavformat/flvenc.c | 1 + 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/libavformat/flv.h b/libavformat/flv.h index 44d3b04ff9..398a958e60 100644 --- a/libavformat/flv.h +++ b/libavformat/flv.h @@ -117,6 +117,7 @@ enum { FLV_CODECID_REALH263= 8, FLV_CODECID_MPEG4 = 9, FLV_CODECID_HEVC = 10, + FLV_CODECID_AV1 = 11, }; enum { diff --git a/libavformat/flvdec.c b/libavformat/flvdec.c index 8060c43772..525c5b2e97 100644 --- a/libavformat/flvdec.c +++ b/libavformat/flvdec.c @@ -319,6 +319,9 @@ static int flv_same_video_codec(AVFormatContext *s, AVCodecParameters *vpar, int case MKBETAG('h', 'v', 'c', '1'): flv_codecid = FLV_CODECID_HEVC; break; + case MKBETAG('a', 'v', '0', '1'): + flv_codecid = FLV_CODECID_AV1; + break; default: break; } @@ -339,6 +342,8 @@ static int flv_same_video_codec(AVFormatContext *s, AVCodecParameters *vpar, int return vpar->codec_id == AV_CODEC_ID_H264; case FLV_CODECID_HEVC: return vpar->codec_id == AV_CODEC_ID_HEVC; + case FLV_CODECID_AV1: + return vpar->codec_id == AV_CODEC_ID_AV1; default: return vpar->codec_tag == flv_codecid; } @@ -361,6 +366,9 @@ static int flv_set_video_codec(AVFormatContext *s, AVStream *vstream, case MKBETAG('h', 'v', 'c', '1'): flv_codecid = FLV_CODECID_HEVC; break; + case MKBETAG('a', 'v', '0', '1'): + flv_codecid = FLV_CODECID_AV1; + break; default: break; } @@ -408,6 +416,12 @@ static int flv_set_video_codec(AVFormatContext *s, AVStream *vstream, vstreami->need_parsing = AVSTREAM_PARSE_HEADERS; ret = 3; break; + case FLV_CODECID_AV1: + par->codec_id = AV_CODEC_ID_AV1; + vstreami->need_parsing = AVSTREAM_PARSE_HEADERS; + ret = 3; + break; + default: avpriv_request_sample(s, "Video codec (%x)", flv_codecid); par->codec_tag = flv_codecid; @@ -1285,7 +1299,8 @@ retry_duration: if (st->codecpar->codec_id == AV_CODEC_ID_AAC || st->codecpar->codec_id == AV_CODEC_ID_H264 || st->codecpar->codec_id == AV_CODEC_ID_MPEG4 || - st->codecpar->codec_id == AV_CODEC_ID_HEVC) { + st->codecpar->codec_id == AV_CODEC_ID_HEVC || + st->codecpar->codec_id == AV_CODEC_ID_AV1) { int type = 0; if (flv->exheader) { type = flags & 0x0F; @@ -1316,7 +1331,8 @@ retry_duration: } } if (type == 0 && (!st->codecpar->extradata || st->codecpar->codec_id == AV_CODEC_ID_AAC || - st->codecpar->codec_id == AV_CODEC_ID_H264 || st->codecpar->codec_id == AV_CODEC_ID_HEVC)) { + st->codecpar->codec_id == AV_CODEC_ID_H264 || st->codecpar->codec_id == AV_CODEC_ID_HEVC || + st->codecpar->codec_id == AV_CODEC_ID_AV1)) { AVDictionaryEntry *t; if (st->codecpar->extradata) { diff --git a/libavformat/flvenc.c b/libavformat/flvenc.c index f58ab7a3b0..36ed55d231 100644 --- a/libavformat/flvenc.c +++ b/libavformat/flvenc.c @@ -29,6 +29,7 @@ #include "avio.h" #include "avc.h" #include "hevc.h" +#include "av1.h" #include "avformat.h" #include "flv.h" #include "internal.h"