From patchwork Wed Apr 12 07:30:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Liu X-Patchwork-Id: 41111 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4645:b0:e3:3194:9d20 with SMTP id eb5csp278358pzb; Wed, 12 Apr 2023 00:31:27 -0700 (PDT) X-Google-Smtp-Source: AKy350aOtAhxWPs63CcvC1ed0KtX8rnggEJTS76AcTgWEjzsb8yaAidrXBaQdy4OGSeXZHQG0WWp X-Received: by 2002:a17:906:2488:b0:94a:5925:56e2 with SMTP id e8-20020a170906248800b0094a592556e2mr5953559ejb.22.1681284686850; Wed, 12 Apr 2023 00:31:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681284686; cv=none; d=google.com; s=arc-20160816; b=HVKCpKguPLWWxJBwx/+nwrx0IUEtH/+SpRQjrAz8GRnVab4MPrv0p1/rDi1ulQKxCZ ejSuW4zGgz5fBSHBvXWeRBElLBRDeFoiKqOkEFJZWz2sLnLQhsRWMgvoiXOXcfM8qGWz sT4KMUZyZqo+/1ZKkOkZK74YprfTmV3cZVdAojfpt8PrdoZsX0Nm4+v7oM7E9KxgyeBN OVqBufLW/0ptz9Yf/rOSC/cNz3GM5DJDQPp9296O9brJvaKjI1mRWAccHQSigcF3hRGP FwtwfOK2DFUGIg28kR9UZwLr33X0IewsHpez4bWQJOx+prfQo5BkLXnV21yCSDy8bO28 qRZw== 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=EnY4I+tzQvvI7x7wrizyoEkH0O0tB7a0+deZ4mNEF6o=; b=VpTftAX+a9PLMrwu4nMPams1hJXZ9G2E+yhz11jDME+jzt4BSFjVC6HiOY2vWyfsIx dngnVqcXNVfOXqLo8YxjkOItaaLehO9N74wGyOn5+i1FawLS4E2qr98/NQoxUutE8mIP x+EkIjIH50GrGOX1bacL8zY1QhCossOa5Fiufynwe6sXfPIQf8QwgP80IEQWrFnUhXEW QCRiTVMZQ2tuiuCens/SCuE+C7LnWHOiZ3EZ+nsR9UxNUtjgdRHELD/+jv7wOW3ex0Vw 4Snali81H5YdXv7U55s210gUji6jExkx0wb/a0t0pCh8aA1c+xwBRZxune/faestBrbf q97A== 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 e24-20020a1709062c1800b0094a8e2d989fsi5531763ejh.90.2023.04.12.00.31.24; Wed, 12 Apr 2023 00:31:26 -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 3D65D68BA65; Wed, 12 Apr 2023 10:31:20 +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 9CF9168AF6B for ; Wed, 12 Apr 2023 10:31:11 +0300 (EEST) X-QQ-mid: bizesmtp83t1681284665tva3of45 Received: from localhost ( [103.107.217.225]) by bizesmtp.qq.com (ESMTP) with id ; Wed, 12 Apr 2023 15:31:03 +0800 (CST) X-QQ-SSF: 01100000000000Z0Z000000A0000000 X-QQ-FEAT: YHTLUubWl25oYqCF6JKySFa/WDoYB4X2hx5dWDQZlwq/NkOqiyJ7YY7w/ThDm 3nGyX4W3l4/GbpKvEqPAcT20HxLV4oCQnvtG+6s8kSll9gj5uMYuUA7SIjczhFlkF/2K1fh PpAKfDth6h9/uHscUqLL1PZ7suHzj9RfCdsEbfEqFqSDCdW19Iu0kNlnspE+2uNv0piTA8X YIDbktCLTbC123mtX0D1D5/vESbuty8d/+RWPNvO08vnUdkcCRHDWWwqEQs08W60ehOluJs LP29BfQ1WUJnDfaMm+gZWtUhJgz/8RrKasBiJnUpJBqK4KhT2Xrjw5CF9aS9Z0Jq+L6VQD9 D1+Q31ePq/JMbLgi4uyPaKXAygGPWUF19NB34ctHNKTZqJqyWFk9LJLkPN3tiTWHYZrFqyx 4o/qMcfNDX4= X-QQ-GoodBg: 0 X-BIZMAIL-ID: 2992713675309930505 From: Steven Liu To: ffmpeg-devel@ffmpeg.org Date: Wed, 12 Apr 2023 15:30:57 +0800 Message-Id: <20230412073100.53743-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: bizesmtp:chinaffmpeg.org:qybglogicsvr:qybglogicsvr2 Subject: [FFmpeg-devel] [PATCH v6 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: Kftvso6GjePG 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 | 62 +++++++++++++++++++++++++++++++++----------- 2 files changed, 63 insertions(+), 15 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..620ad08ca1 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 } }; @@ -238,16 +240,24 @@ static void put_timestamp(AVIOContext *pb, int64_t ts) { static void put_eos_tag(AVIOContext *pb, unsigned ts, enum AVCodecID codec_id) { uint32_t tag = ff_codec_get_tag(flv_video_codec_ids, codec_id); + uint32_t flvtag_size = 16; /* Size of FLV tag */ /* ub[4] FrameType = 1, ub[4] CodecId */ tag |= 1 << 4; avio_w8(pb, FLV_TAG_TYPE_VIDEO); avio_wb24(pb, 5); /* Tag Data Size */ put_timestamp(pb, ts); avio_wb24(pb, 0); /* StreamId = 0 */ - avio_w8(pb, tag); - avio_w8(pb, 2); /* AVC end of sequence */ - avio_wb24(pb, 0); /* Always 0 for AVC EOS. */ - avio_wb32(pb, 16); /* Size of FLV tag */ + if (codec_id == AV_CODEC_ID_HEVC) { + avio_w8(pb, FLV_IS_EX_HEADER | PacketTypeSequenceEnd); + avio_write(pb, "hvc1", 4); + flvtag_size = 19; + } else { + avio_w8(pb, tag); + avio_w8(pb, 2); /* AVC end of sequence */ + flvtag_size = 16; + } + avio_wb24(pb, 0); /* Always 0 for EOS. */ + avio_wb32(pb, flvtag_size); /* Size of FLV tag */ } static void put_amf_double(AVIOContext *pb, double d) @@ -492,7 +502,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 +545,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 +647,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)); @@ -785,7 +805,8 @@ end: 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)) + (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 +857,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 +883,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 +928,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 +993,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 +1012,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 07:30:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Liu X-Patchwork-Id: 41112 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4645:b0:e3:3194:9d20 with SMTP id eb5csp278424pzb; Wed, 12 Apr 2023 00:31:36 -0700 (PDT) X-Google-Smtp-Source: AKy350bJawLa1EEYifUiE0x3m+jSfDbL38BaMV1j4+5b2EXm6A907ZMEmzhvhxZySn44dSMXgeLM X-Received: by 2002:a17:906:19c4:b0:931:85f8:6d00 with SMTP id h4-20020a17090619c400b0093185f86d00mr12921867ejd.47.1681284696520; Wed, 12 Apr 2023 00:31:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681284696; cv=none; d=google.com; s=arc-20160816; b=DGH1oR6epyUf5eqh7fMzthKJnVAwoEXx0+CxjzNl+DFJ5rf241Ch9NaTZ/P70gSL8A phhd0PfGNL75hTtmXNSp7a96UxpSsVTJSDpELjVT5RQNtOdRe5tw62g3LrtEFrIWjrYI E0WrNqBy0DguuwArTAD4cKutUrGjBQpDf+5QWy2S7HzMiQ06dgGTwsK8zqtE01P5ltfS d2ZdzS+4TO4roa92JGVj+WC4ZW6hrpgccVf5TJr/jRLGv7+F42Rmb8ZmdnrDBrtXFoVg R2mdPnkcqHLtX3nw4QcdP60SSHyXESPLLph+bRWHxh+NEGdmTA3B7capXen/LuPjpAgE SMQQ== 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=tmfZBeyq7489hr+U56TOicx7C37H+1T40u1Xno8+tlRMT6f4GwoeeXfj2mER/3RGnx wcaeYT8mRHwAZPOeeHKkwOkMx9+cySgp0GKwYoL4+2PMkuBCU5zBo7hpnWwjSUCW1Jl4 2UgnswOvN0tHGiLjHh0xe23WwvQCzN55WBxshKlKteoIp3PUxj2U2l/NC/lc0o55eds/ 7akhE9xnjxRl2cj4j1XHiPhI0hJaXsx9NKl36ZJ5UJj6e75h/zwqsnowZZ/6z7fEAWaj 90412mzbTVXcSH4WreI0gG5RmGIUo3leP6OsTGUQS8JWnyV14jIH3fw7RKY7dtH2L8QA VKhQ== 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 c20-20020aa7df14000000b005048392d9e5si3539967edy.670.2023.04.12.00.31.36; Wed, 12 Apr 2023 00:31:36 -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 5846D68BB3A; Wed, 12 Apr 2023 10:31:23 +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 9092A68AA37 for ; Wed, 12 Apr 2023 10:31:16 +0300 (EEST) X-QQ-mid: bizesmtp64t1681284671tzi20nzl Received: from localhost ( [103.107.217.225]) by bizesmtp.qq.com (ESMTP) with id ; Wed, 12 Apr 2023 15:31:08 +0800 (CST) X-QQ-SSF: 01100000000000Z0Z000000A0000000 X-QQ-FEAT: k9SqnfSrLIluJX22ULLTqnRufhuHY97uwO25fvduGBTmbltDgnr8L7Ji3Dn7b rnvuHKqnEaEByDlyyqSs1UsCIYagJIAQ2KOCkNW4xTqLyZLL13SSxBXMlNQxl3LbnCDQg1v AVyupzcoVJqNAoI1J8rwZiK7UA9tuaWBNovuPwwSzgZDvCHVlnT7YbEsBBa6GaiNVSHCwEW flTMI1ph4iBIvWXHPsywkExtf8v+zlalAhWipQxobWCdFD8yaQ0THHXbUhLqsNTPE0NUOIe oArDZg51yM8+C06lW7FY6tmDswCCSnVK/kV/Id0UHEz78Y1gQvCo6CO84iTw5mUz1+RlWu/ 7wp7KnQ0+iHmqM22vR4HfrDPV7FaPYeKS3QXoJfT8V+Wet6b3CHMsdtm1D4mMbgDHKEC16I X-QQ-GoodBg: 0 X-BIZMAIL-ID: 12582661648776366992 From: Steven Liu To: ffmpeg-devel@ffmpeg.org Date: Wed, 12 Apr 2023 15:30:58 +0800 Message-Id: <20230412073100.53743-2-lq@chinaffmpeg.org> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230412073100.53743-1-lq@chinaffmpeg.org> References: <20230412073100.53743-1-lq@chinaffmpeg.org> MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:chinaffmpeg.org:qybglogicsvr:qybglogicsvr2 Subject: [FFmpeg-devel] [PATCH v6 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: AvAv+vofNW3Z 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 07:30:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Liu X-Patchwork-Id: 41113 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4645:b0:e3:3194:9d20 with SMTP id eb5csp278488pzb; Wed, 12 Apr 2023 00:31:45 -0700 (PDT) X-Google-Smtp-Source: AKy350Yx1kweL7iESpjN1HOyawpdlZ3GLEqc975tSGzEP6n+Oum1vuJ8H5pZ27lFwHDS2VEUAKzV X-Received: by 2002:aa7:d985:0:b0:504:9b7e:1e5a with SMTP id u5-20020aa7d985000000b005049b7e1e5amr4208045eds.40.1681284705438; Wed, 12 Apr 2023 00:31:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681284705; cv=none; d=google.com; s=arc-20160816; b=Sz0Gc/79X7vzdXsDnhQ/REVb/s9E4+Ddo9oT85BIwE+DX6oau6wZh2ec2DQjTpItfE 5Udi8lFSGHHaiwVYC6t8PrnzpZaMs/hcfU/9aH14+DRQIsVYKOB27YnccpINeHdfXWEH XlRI+pcV98hpJQaEYK0I2Sw9WnkvHrMn5gVh0pGbRG06+rn6JeE2ANm4Ka2FBneHVTXt HSEq4hb9rVUawnUv8zN/mHbEvuIo7GV5IQdo7mWQg81DHFfVUTjFJztj6PZOjan+aCe1 M2JxNfBIftcCSPYEbk/ENktva/aJSmUgKXOVJRyJ+Dpuh7ss2tXKQSOnf9xAuNkIYcIe JrGw== 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=xFHK+q7CsRM9eMOFR0DvWadvEoI43B9Km/87Zfav0+A=; b=QsJkjV8pUYk9Bl38p9i9cD+wW+Oh0kfJ73apmT+cUTLjFkMMXsUjkZbMxM0oi/S/QN 84MGHWE2Qe4SfPBEoXvdT/OeGD5MpuCajNOflzofKjyYjSFp2QU+BHBrE4agTzJ5PWRU F3I+PYgBYloE0fAvAxqX7ZDFr+JtHVEcUhT+ZrEO3Eu7ECudE+GZmHuFv1PcBw7x4AKW G8xQECmp7yBuRNwrJfdftL0SJ8bxpC1/5EI1yf+pmaKjfBhH5BLWb45NvYolRPd2PMrS vmCrJY/7QOqurXckmvjyAAbHBk/xTOPPFb5darW/R90/Db8ZRnK1fk+lo97FQpuc7vBX AjgA== 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 q4-20020aa7da84000000b0050504d2df36si778131eds.400.2023.04.12.00.31.45; Wed, 12 Apr 2023 00:31:45 -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 7AF7868BAEC; Wed, 12 Apr 2023 10:31:30 +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 C4DE168AF6B for ; Wed, 12 Apr 2023 10:31:22 +0300 (EEST) X-QQ-mid: bizesmtp62t1681284676tf2nywsb Received: from localhost ( [103.107.217.225]) by bizesmtp.qq.com (ESMTP) with id ; Wed, 12 Apr 2023 15:31:14 +0800 (CST) X-QQ-SSF: 01100000000000Z0Z000000A0000000 X-QQ-FEAT: XBN7tc9DADJeq5xJNeXjOmUoPojzj1yHZhRRJUFlmBARmvwu0nL/ZIgmaLF2M DqFZpgIhWwGpBzcR02RXr+QM//ONCXL6dQCHQ5hBeaQY5sFA/9kHobAsAKSKI819ubf1ZJq ifRRnPH4VaSUcr/stsCClfNZ8xuM5xj5sWasujkDTRvPHTrEA7Fs1JYidEUytveWEv46MT7 eD2SvhKMD6devuQxO5lYYjAhRhcn1Z+/kRFh3ATWY0U4ZB45qfMP0vJ1aRtBDznOwnCKOs9 q7nnmye3aqHUdnvWB7dHWen1nT6z0AVd+PNTBfp5hXz7UByqc9s/d3XVMx0tYFj73bpqrkN T56E48ikwoFgOkcj4/7kLi0SrYzcO/0Qn3Wc4zqZkoePp15ODdi7KhKFMQahw== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 18280013036996905866 From: Steven Liu To: ffmpeg-devel@ffmpeg.org Date: Wed, 12 Apr 2023 15:30:59 +0800 Message-Id: <20230412073100.53743-3-lq@chinaffmpeg.org> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230412073100.53743-1-lq@chinaffmpeg.org> References: <20230412073100.53743-1-lq@chinaffmpeg.org> MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:chinaffmpeg.org:qybglogicsvr:qybglogicsvr2 Subject: [FFmpeg-devel] [PATCH v6 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: 7WKMrBO6A2gV Signed-off-by: Steven Liu --- libavformat/flv.h | 1 + libavformat/flvenc.c | 32 ++++++++++++++++++++++++++------ 2 files changed, 27 insertions(+), 6 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/flvenc.c b/libavformat/flvenc.c index 620ad08ca1..b570fa91be 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 } }; @@ -251,6 +253,11 @@ static void put_eos_tag(AVIOContext *pb, unsigned ts, enum AVCodecID codec_id) avio_w8(pb, FLV_IS_EX_HEADER | PacketTypeSequenceEnd); avio_write(pb, "hvc1", 4); flvtag_size = 19; + } else if (codec_id == AV_CODEC_ID_AV1) { + avio_w8(pb, FLV_IS_EX_HEADER | PacketTypeSequenceEnd); + avio_write(pb, "av01", 4); + flvtag_size = 19; + } else { avio_w8(pb, tag); avio_w8(pb, 2); /* AVC end of sequence */ @@ -502,7 +509,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 ? @@ -548,6 +556,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 @@ -556,6 +567,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); } @@ -648,7 +661,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)); @@ -806,7 +820,7 @@ end: 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 || - par->codec_id == AV_CODEC_ID_HEVC)) + par->codec_id == AV_CODEC_ID_HEVC || par->codec_id == AV_CODEC_ID_AV1)) put_eos_tag(pb, sc->last_ts, par->codec_id); } } @@ -857,13 +871,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))) { @@ -883,7 +899,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); @@ -996,6 +1013,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 07:31:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Liu X-Patchwork-Id: 41114 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4645:b0:e3:3194:9d20 with SMTP id eb5csp278554pzb; Wed, 12 Apr 2023 00:31:57 -0700 (PDT) X-Google-Smtp-Source: AKy350YWOdQYSkN4WAVCv/TpmBAEymOfXbDhOWAWSb3Iq1EwJIETJj5ntocXMbO1BLm4286jm6US X-Received: by 2002:aa7:c695:0:b0:4fa:785d:121 with SMTP id n21-20020aa7c695000000b004fa785d0121mr1896814edq.16.1681284717391; Wed, 12 Apr 2023 00:31:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681284717; cv=none; d=google.com; s=arc-20160816; b=ofrvfEtH8YK8GJG3UFej7optqzZSxL0vg06iUSH7hb0FbQAlIeLBUkEZuvKGkRXI7b AWbb+tK9WLvKYVL2R31njAwrvW/CQ89ZqN9LGUoG4I50bnxgSFVw1cV1JR/JyB7S2zZ+ JHgUIc6F4nnSfhqVD2+NfLC36S0w2usToOgULyfK9DO2ZeMlHzuKVinpIgehrX17IcPf XPDAuGFWFufp+ZiNkzwqK2undHf4Qra9Z7q1ZiEfMDYwxGGMX6d3vh99hQUO67C0lyIx V4iJGututBf5u0Mjg28widJzum8cgkoFu81kTp3AkUSQOtCLzp72m5ImtU07GwJczzZx JusA== 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=vlRhLZ0vSQLXM/zLY/tHHO3kiF+QnWnfLtGdfoWbWy0=; b=H6alhc+RqQavH9OXVUKsY1DqHRiIKnug+l8odMhumpOzPsfKOLQFPY+88KPVVxX7La b/LkLQE78c/IuusnqHOBAcIGv7dq9BsLNXaff89/RRrYUmCk17XG+hUJ7Uzy2nI3M8fv 8Hb05sCvw3dk0s9BfD25fhkkwGEfl31dAiskEY93ovU8uTevZWGCF6p/F+zGpyI7ho8v CoZaQoyB3IX1CqMwRHM5ZX1rZHtN1xig/nlvH9QeoIDKbbsH6QjfH5z+L8Nty4rTJpbC Qmq0keD4xKXoDr5+7S7jFmrpgSes0Xnf2PxyT7k5gW/M22EIPoJvaC9UsvlfZLulsEiZ 2WKw== 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 x6-20020aa7d6c6000000b0050483173305si11106699edr.75.2023.04.12.00.31.54; Wed, 12 Apr 2023 00:31:57 -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 808EB689F8C; Wed, 12 Apr 2023 10:31:34 +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 66B0068AF6B for ; Wed, 12 Apr 2023 10:31:27 +0300 (EEST) X-QQ-mid: bizesmtp64t1681284682tke1snk9 Received: from localhost ( [103.107.217.225]) by bizesmtp.qq.com (ESMTP) with id ; Wed, 12 Apr 2023 15:31:20 +0800 (CST) X-QQ-SSF: 01100000000000Z0Z000000A0000000 X-QQ-FEAT: uGhnJwy6xZI8aacfjd3VBoa46VZM1PdC1uuT2QQoFN+NnO8qiQ8M0TjyUW+5g Hb3ek+4WodmpoK6hThSxICMQL6mxZ8TP5NfXjioheoZXftuSnCScSxXrmFMeBW+vCP3YC9j /p5eo7OwAq+nFZ6EgCI0kVw5+MHEIk8rmz3bZVHQwRCA/CZN3YeZjHScSCzkQxI6iBBg8Hg nHjC9g46pJ4q4jFjgd0LI+HiBBCKgQDHE3/tXBC2AyknoDhuL1h5/g4P4K5Do+0Av7P0nji 0xN8rwwO8B6dBDZEH6aKTN6UH9WW4eGL1sEzDuAK+gj2bJpgkq++hEl0byYfgMPAwMHk+Eh c43xgdlmUDkXtYlNoGUlGEZrokiu/miYa9Hvb82JvPd/sKx0Tfs+6I7L+Cey16cxL4VQTfK X-QQ-GoodBg: 0 X-BIZMAIL-ID: 16471886314569797970 From: Steven Liu To: ffmpeg-devel@ffmpeg.org Date: Wed, 12 Apr 2023 15:31:00 +0800 Message-Id: <20230412073100.53743-4-lq@chinaffmpeg.org> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230412073100.53743-1-lq@chinaffmpeg.org> References: <20230412073100.53743-1-lq@chinaffmpeg.org> MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:chinaffmpeg.org:qybglogicsvr:qybglogicsvr2 Subject: [FFmpeg-devel] [PATCH v6 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: vwJOyGgG4+D8 Signed-off-by: Steven Liu --- libavformat/flvdec.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) 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) {