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); }