From patchwork Wed Apr 12 04:37:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Liu X-Patchwork-Id: 41109 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4645:b0:e3:3194:9d20 with SMTP id eb5csp201526pzb; Tue, 11 Apr 2023 21:39:08 -0700 (PDT) X-Google-Smtp-Source: AKy350bEfF1mZsH2AOHYSDNVTCY0Fu9C+t07cjfnpmqXx4rraf6/tMPlwW/+gfNBM8MUUqRjtdB5 X-Received: by 2002:a17:906:4812:b0:94e:4523:b0d8 with SMTP id w18-20020a170906481200b0094e4523b0d8mr2092114ejq.73.1681274347938; Tue, 11 Apr 2023 21:39:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681274347; cv=none; d=google.com; s=arc-20160816; b=ZuyL4hRg/jeSOZh1cTlz9sE+w+afIwjwmx7e3jDKuag7UaWSAIVxmEnnaGgzjFQ8BD FbXS+KsADKXq6CifS5cOParzGudWWbLqhwInur/iWNIhAFizarzRYfLgyIck6veDw5h8 ZE1qJ0BMVvk7LvNOKuemOSFA30NRwkAXc4fu7cFI2JSM3sh0yBYqFA8m+tUw5eELZg1h lrSRFI6WhNJZFDQgQuZhLFd+hHdvQf0PKVP0K6hficlFHsA4las3Em43Y2vkran5mULT WEQZHnKldquXFOHUdVMS50wkWjY1WOQvaEuIk2lVS2PPs9qcRiBJjscASr0rHawJB++Z Bt5Q== 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=KRW8J+e35djNDS0DTiYOYNzx13UmcsVOgsjc/yr2E66RJoZcmzLWQbH+jEjrTDt6vV Otrc9xywZriIwNvAFB6DP4FoL1pUGrqYnEtIHnl/bdRmz7B0wDjYdG48plxl1zg9jIdH Iu6fksbmwC7OCYmbhk5VZ4x66aO8KsUrkw08Croe7aw4WrzKXGh8C2hljJraeuL3cowh BkWHmnfQ/Ulrc9cpqO7SGzr8vncejl1Djlz0ayfW73g7B6kk9/Z98DO0Tw77ap7WZ6n5 C3s303Zxxz21apX7hzzpz11BAPZP+aD+9bElBC9v+uX7DZu6oNKLCY6bGAapRFo03A2Y eKwg== 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 lf11-20020a170906ae4b00b0094a62ae398bsi956834ejb.477.2023.04.11.21.39.07; Tue, 11 Apr 2023 21:39:07 -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 7EDE468BD88; Wed, 12 Apr 2023 07:39:05 +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 3D490688373 for ; Wed, 12 Apr 2023 07:38:56 +0300 (EEST) X-QQ-mid: bizesmtpipv603t1681274262txw7 Received: from localhost ( [255.142.19.15]) by bizesmtp.qq.com (ESMTP) with id ; Wed, 12 Apr 2023 12:37:41 +0800 (CST) X-QQ-SSF: 01100000000000Z0Z000000A0000000 X-QQ-FEAT: G46xFj+wOV8wClRQfwFK0QYiVSJCC1Gatodc82Dpnew0hfuWXzlCQTx2wxRsy PXK2JLE2GNVWrTQMivqW+sR6PxbmTP7L/mJdS+Uzw1tYBj0y7JvGmf5cA9Ykx6z7yv6caxt w/mC+qXEvnvqFDADZOW0Dh0WS8q/Sibqry1V1zKWcd8qEvIZ+X1n6v1ifGfDO94J2iUq5qZ VOL13xJgmjxMh5GIlksHRAz021ILpwjbPJR6j+QMyNP3XviRXMW8b37c5ydl0cH5i+qlSmU cq1+MJVXGDAwh35wipxGDIk8ATWEaqPRbP7rE2G+n3XgdhFp+8at/zxwGc4sj/u7xiGhxhi QA0MNUUpCKyD/ir+/fQCkUZB50IunOXqGYmQeM2uZPw0prte8nF6bX9upD2Vg== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 18145156121578205778 From: Steven Liu To: ffmpeg-devel@ffmpeg.org Date: Wed, 12 Apr 2023 12:37:34 +0800 Message-Id: <20230412043737.8841-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 v5 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: 825/dmCq0iku 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:37:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Liu X-Patchwork-Id: 41110 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4645:b0:e3:3194:9d20 with SMTP id eb5csp201594pzb; Tue, 11 Apr 2023 21:39:15 -0700 (PDT) X-Google-Smtp-Source: AKy350ZYf1TQr3CgDhEcJJVAeRvQlV/avUoeQ44W59EqdF8CI0HQiK5vGKagW5z2npDO8coxDT+j X-Received: by 2002:aa7:d651:0:b0:4fb:59bb:ce71 with SMTP id v17-20020aa7d651000000b004fb59bbce71mr4000007edr.36.1681274355537; Tue, 11 Apr 2023 21:39:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681274355; cv=none; d=google.com; s=arc-20160816; b=TiO1KHGoSOn6Wftf6a/b5Q4VWBIYVXtrK2Gx65Zg1kqyy84cyAp1/iGobDLjDpQd9f LcUX91XmRJnSrHINBrlYR1PT2n5WLhvfhzjUNTO2k6l2O4LDRzVSbeWfCgktUpNvlAFa GNddTy3CBQBwm8yr9pazaCxSXCQsAkPPh2LU18RvuIt61osOs0onbptZHNulmFWj/fqC 6HhpwxlP9G+pS6OR9Ipnk10OeHdmveTNvxmtOpNhxC+NIsXDGvVpS69u+ca9pgrTusDG pXUkA/0DSSpd2ODW+Afy1WZlcTwPDtXQD/aelcck+MHwDBC1CJ6qHgLpof1r8uM/bk7I BbCA== 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=ipeDnuQcnIb65+eCwRkHW2nDvCx6N+lOiHCYB9k6yNmm5RHF6uvMX6GUyvlGTW/mN3 J5Kr5Z/+PlBsNTvB0S3Q0fYYZAcVak9vmmdhIObkNAYch+sMb3JP7Ls0RG47UqDyKQ/a HAdts4ihyiCCHOHCJU3HjHaKXBvj7zPNPi3vYHRtjNuyBxRdsHfKXlaQ+gDezJ5Ek1Ge 5WyfNjIrip4aO2YzL4AzDeBtctnVmb5NwjpRDxdhHUmmAv1SQNRrV8dPr9NE+iE2q0Oc 5kCrKjqxmatC0nogXaecz9brNn1y7Z360b74/NxTgR0g2K590Q9N1870klKSc7AWnTTk QS6A== 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 l4-20020aa7c3c4000000b00501c32ce664si2421435edr.325.2023.04.11.21.39.15; Tue, 11 Apr 2023 21:39:15 -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 8B01B68BDDD; Wed, 12 Apr 2023 07:39:09 +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 1B2E568BDAC for ; Wed, 12 Apr 2023 07:39:01 +0300 (EEST) X-QQ-mid: bizesmtpipv603t1681274267twar Received: from localhost ( [255.142.19.15]) by bizesmtp.qq.com (ESMTP) with id ; Wed, 12 Apr 2023 12:37:46 +0800 (CST) X-QQ-SSF: 01100000000000Z0Z000000A0000000 X-QQ-FEAT: rGm7xzoh3hlTK5dOg4EF3TwYlw6UENfSpiN6l4T3/lnmB6nqPTXkSzzGBWE9p LklnRMrpg/tclOC0tQR+trJweLAHMFPgPdB2pidLsweL07WsZ70NnoBs/F8jn1jQxlxAzPn Z/KF3xh7Xa5G8XUrCfKD7Sfx6bQuoXmXYrvY7aLS85q6zt3JxqUEJ5s9IQr78J/0rJgauMO j1/dOWlOyqriRp7ogdUN8dCra7W72wNipSsbsUQyZQvINWALxWKrr9Ps/iZxCT0IqvvqV6s B5aIrGO5wbboNbgb8lEjM+KHHWoynkGvcvVodc+Qhv0C4Yy7rkSK/34xNs/OHLsQxJanRMX U94YBUTs889Akz5FrTWSiQTFKljxfSpMqIhPEgUXwKYrw7PmLlqBgYbOgXfdw== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 5323671012326637824 From: Steven Liu To: ffmpeg-devel@ffmpeg.org Date: Wed, 12 Apr 2023 12:37:35 +0800 Message-Id: <20230412043737.8841-2-lq@chinaffmpeg.org> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230412043737.8841-1-lq@chinaffmpeg.org> References: <20230412043737.8841-1-lq@chinaffmpeg.org> MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtpipv:chinaffmpeg.org:qybglogicsvr:qybglogicsvr2 Subject: [FFmpeg-devel] [PATCH v5 2/4] avformat/flvdec: support demux HEVC in Enhancing 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: VJ1tX1WlHBTh 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:37:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Liu X-Patchwork-Id: 41107 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4645:b0:e3:3194:9d20 with SMTP id eb5csp201074pzb; Tue, 11 Apr 2023 21:38:08 -0700 (PDT) X-Google-Smtp-Source: AKy350YCtfUOeYN/C5HGnsjBY1bDrnPleda7OG99POW6FbE5GZ0NDSd4e7gElZBM3kkh/9tt1Xmi X-Received: by 2002:a17:907:c789:b0:906:4739:d73e with SMTP id tz9-20020a170907c78900b009064739d73emr1690462ejc.2.1681274288682; Tue, 11 Apr 2023 21:38:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681274288; cv=none; d=google.com; s=arc-20160816; b=Q0zwg5LKsVWS3XCTR0YvMDkx7nigjY/qS/EHmg1KohZ4Q0D7Ea99X4nugrtsLMQsiH 0CFSi8EAEanmlreXULZJxZkhW5ZE8qJx4DJd9WvWdS6QaTpQx9+DcGGZoWrp2XNfIEnW IEa2w7dC5yIJ6fHw1CVQkonSs/4m+GhKD1i4QBJZN3TT9UhFDUxXQRMv/V/bV9M8BEIS tXIDMwMqol+3SvwoC6Vgg3figYKjshgFNbfrgIoB8/1JrNFAi61U5oJDuelzsTfjW7Xl omWvy8/nNCdq/yWCDdZ8s+u7q2uAbYgU//UKN6E7NXnuBI1lELxNPs7cCTVyusoMmH45 fybQ== 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=xKdJVoBcmFoSDaJTLeiRC09AOWWeokzk6vShyZjisMU=; b=cdEhSjNPygjspC2KZtwh9fqbV6fnJwuU7uz4kKQUpFoviQMLpvWkcUO9ULRlTWWhza hmmsMy4dJmUON0EYsICBnA4qC28GPQLgOvs41+FOoXmxDdQgmZKgsHOUmVzvDc/1Teyw CMNHgGjr6m2uSP1nKMA7D50kMEUJiExIg/+QqItMzW0RqoQxkrk0PY1BSlDzkDewdfO1 PMHzLqmwc6Ng01MFmpRiQWvHeKR4gippF0nvwMYf1NoF2YmYytQ/8Sw9Rt4HAQC3lQYz s1DnCQh2DLq1bd3fDGjkXUXpQMYJGSUgfJOxZq+wmD/qUUgkC/jVYroEbdXcIMssbxkr SaRw== 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 h7-20020a170906260700b0094a9956f34csi1309037ejc.583.2023.04.11.21.38.08; Tue, 11 Apr 2023 21:38:08 -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 6691168BD38; Wed, 12 Apr 2023 07:38:05 +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 BA997689CD7 for ; Wed, 12 Apr 2023 07:37:57 +0300 (EEST) X-QQ-mid: bizesmtpipv601t1681274271tg9o Received: from localhost ( [255.142.19.15]) by bizesmtp.qq.com (ESMTP) with id ; Wed, 12 Apr 2023 12:37:50 +0800 (CST) X-QQ-SSF: 01100000000000Z0Z000000A0000000 X-QQ-FEAT: qxAR8rpszOsYKVm0B2uOYrc0ipvSm7KM7D0bsvm5ml4DW4mmOSDwIo7bNaewd CnH/Mz5sZ2z4eG6Qc41gzYbTzb2eonUx3hVeW3gy5abWfM4sh3lbxgJewVZunvozMzgocHt ijEMP192xreIWCnAVxxLx3Y2eK1xu5i296cY7x5y2W0EICDK0I04lfy5C5iGwAS73o4TsLS 3OQPuLeM1XZqnFwCsYXV4bwmiPDFVb/FumMeXHubC7pf7Of9y9w3Y/gzjG2KME202semQ8a tCOO5+6Z+7g4vkI0mETVg3bmlI0LgfvNtS1NgoRv0N6RVbW1hPFqHcFYDBMnqn89QCnb5j/ JKFJMGBY5B82knLwfx8AtzEOXtnSUkvplhYgKvG8aeuztkb77L7KenQW0vHhw== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 13949311662904589835 From: Steven Liu To: ffmpeg-devel@ffmpeg.org Date: Wed, 12 Apr 2023 12:37:36 +0800 Message-Id: <20230412043737.8841-3-lq@chinaffmpeg.org> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230412043737.8841-1-lq@chinaffmpeg.org> References: <20230412043737.8841-1-lq@chinaffmpeg.org> MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtpipv:chinaffmpeg.org:qybglogicsvr:qybglogicsvr2 Subject: [FFmpeg-devel] [PATCH v5 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: cIEKV6vlh+1v Signed-off-by: Steven Liu --- libavformat/flvenc.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/libavformat/flvenc.c b/libavformat/flvenc.c index 0f26ff99e8..3c8f6ee66f 100644 --- a/libavformat/flvenc.c +++ b/libavformat/flvenc.c @@ -28,6 +28,7 @@ #include "libavcodec/mpeg4audio.h" #include "avio.h" #include "avc.h" +#include "av1.h" #include "hevc.h" #include "avformat.h" #include "flv.h" @@ -48,6 +49,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 +496,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 +543,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 +554,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 +648,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 +860,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 +888,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 +1002,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:37:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Liu X-Patchwork-Id: 41108 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4645:b0:e3:3194:9d20 with SMTP id eb5csp201138pzb; Tue, 11 Apr 2023 21:38:16 -0700 (PDT) X-Google-Smtp-Source: AKy350ZfB8YBFzZsCXQCHfNXcfMtux/xeFqGY5+fHG5BSDpsbqC8PE/mEjLg7wEXnlvgl0wsVwXj X-Received: by 2002:a17:907:3e9b:b0:94a:9651:51f0 with SMTP id hs27-20020a1709073e9b00b0094a965151f0mr10228146ejc.58.1681274296432; Tue, 11 Apr 2023 21:38:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681274296; cv=none; d=google.com; s=arc-20160816; b=Yek5LGgmn72H7yEntKPmWiXoyX5i3WEs4z7KUq+Z0Bugo0UT1tiHOMll48yFOd7DVJ hxbSo017sZUgXWONhxgJhfewBsczcbiMHyR3MCITKjhG7siN6kXuuKbOQrh+62ncjDhE d/3NlCyS3rMM7xxtaGvOUAmpRcOq9DuUCj5bdskr8iEpHAb9tXeoT3OZGQY0vORxjTEx 5kJSWnsj/xJEG1XJ473GfF3rrR+uRH9CeMSelgiPWuH5B8ikD4OBwDsuLUU29wYFMY/D kLx3EOGRmkyFSfnb6leexClEIo0AmAPiNYkkFD98tNy3ayQ1TOZAJDBsmZkcTtc/DfPU Guxw== 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=41T8vLpmY06NNFhERB8UYjxaTIZCSeuocy2tK0kiqpU=; b=gxvUEgTUEuUI8GDwqZHG55XSdfmZ2V7IolWEF0sMrRL9qNuk1Akbf0ZGhL+EB9Ih6w bOG/oynXi38xAKKhW+Dzrti+CoZ4I3WCvsxg4rcY7VAoC16TRocbHgmPoIp56fDOpB0v IcI6z5QK6vO5hk4JmRGVhUmACkcjNJQA9oANIsneFRKiMFauIS6zMhY7sBku8Y+oBsKh owVPppz3V0RwDwtedHnfifDEtM/CnTmnhNhi73bpyvExff5vB2qNQPllWU+rQOnSp9K7 tBN/3CrRSpKfZkL7OiHqtyh77+pHdGXGcO1ThoYBNMUhVXMWnsEd3fu1/ZUn9pbKOP3c v+6Q== 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 u20-20020a1709067d1400b008e41fc88f2bsi7999221ejo.981.2023.04.11.21.38.16; Tue, 11 Apr 2023 21:38:16 -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 5A87D68BD76; Wed, 12 Apr 2023 07:38:08 +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 C6BFB68BD50 for ; Wed, 12 Apr 2023 07:38:00 +0300 (EEST) X-QQ-mid: bizesmtpipv602t1681274275t9rh Received: from localhost ( [255.142.19.15]) by bizesmtp.qq.com (ESMTP) with id ; Wed, 12 Apr 2023 12:37:54 +0800 (CST) X-QQ-SSF: 01100000000000Z0Z000000A0000000 X-QQ-FEAT: r/cTxDoDoiGQY68leTbw382nt3QBHMvljbLHzXqiG8s8hhhTVTRuQEGIZUC4o 8aMygcDTh/YBcvWy9xHCLaHxfJNn+7nnbB0KRttBvxLlv38RTQtBVutjqQ7vfPlbKYK5NMr XfALRT7WzURuNPlzZPdZ7CpCWFDMDDiZlwe+KKVkKS2yfTG8Vs4ieh0+s5em3mvm7Xnz0fl r0N3k5+4pVMa7G4SQXl6zp7hG/4qBNrWTQkLogp4bzzkP6P7iW4f6ectjIyGLSGWN1ou88x w6JXved89/FkbIwvi9bJNjUt+RCxzzlnWZEGtAsSRJAFVlbf2t6EyLWNVriuxh8BlBk2EgC 3QJT0rPkxkzqPzTcqg2Kjb7GRvXm2KMnQTtSpzo0SciAvBhHSsOT7nV5Hmprg== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 4500892356026353212 From: Steven Liu To: ffmpeg-devel@ffmpeg.org Date: Wed, 12 Apr 2023 12:37:37 +0800 Message-Id: <20230412043737.8841-4-lq@chinaffmpeg.org> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230412043737.8841-1-lq@chinaffmpeg.org> References: <20230412043737.8841-1-lq@chinaffmpeg.org> MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtpipv:chinaffmpeg.org:qybglogicsvr:qybglogicsvr2 Subject: [FFmpeg-devel] [PATCH v5 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: 5ch5+p7QFakw Signed-off-by: Steven Liu --- libavformat/flv.h | 1 + libavformat/flvdec.c | 20 ++++++++++++++++++-- 2 files changed, 19 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) {