From patchwork Fri May 12 03:59: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: 41594 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:dca6:b0:f3:34fa:f187 with SMTP id ky38csp5097386pzb; Thu, 11 May 2023 21:00:11 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7LBZzQt8yBwKehhxLAIAqhoUfk4HDGkDPOcXfD4x6Nl1UIuRjVOaS+jC9NxkZ3LnRF9GDz X-Received: by 2002:a17:907:728d:b0:96a:5bdd:7557 with SMTP id dt13-20020a170907728d00b0096a5bdd7557mr4517085ejc.70.1683864011547; Thu, 11 May 2023 21:00:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683864011; cv=none; d=google.com; s=arc-20160816; b=KRPUMVLmY2XRV0CqXOwxNlSiSDdxHvBGxSMDSB2I9DvHsabgaCPQBruBhVX1u3Yn3k fZTikvg0VEiYIer4Wa39+KrcNbw8Sw/xDKymIqhkYcEnogM99ZwZHYkd1TxU1mHskeof AaCT690enyjcaIz3Qsn6Y5d8QUVn9M1PJPaDv8wgKmaqXQk5gQ3RIgMNHAWGaAi/u6Ez tnG7898Gg4W58BT2aipZhGDLkpcEojizlhNUuvXUDICvnRL8g8TdtR+Oat3FHRm9y20f nO6vZSBLcVlN+j89Zcn9VNcMamBQigmsjzZn140aEUey6VG/qzd/vYyno8+JTpTL/tEb YZvA== 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=b1Sp5oqZAMwakI7a3Zvw4MdnKPyomZo8cXqDnyJamjg=; b=H/kHd38yyf0k3SIqhQCue3GsJVhcusJQfI0amPCOvPoOJTW3vd8HV6rmx2nSLcTMPu sc7WbA4ZXVQEsNbkHLOw6PWo9nLHaE17Hht/fmvTgp2baamUX+MUjUSDSqzRj1qpCW07 yttphrdzKWdLCO6uc6wdobCuRnyxn0dV6tYYVYZ+6J2EjqimowO0fLElZ6QACw/UpDPl mIzHGmdrSLebimF8G5/eQc1Q4D7BEl85FBNgmxelXsDNjlWSAMdtDLbkb8rCtDVE8wjK eHgwouAPb+ZYXEcM7gESms1GFRzVQpnd9r1rSCGC3al3ah4+CjMc3ElNu70yvot/ZjCL gntw== 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 n24-20020aa7d058000000b0050bf58b1f99si4727204edo.587.2023.05.11.21.00.11; Thu, 11 May 2023 21:00:11 -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 23FE568C1A6; Fri, 12 May 2023 06:59: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.155.67.158]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DEE0468C180 for ; Fri, 12 May 2023 06:59:46 +0300 (EEST) X-QQ-mid: bizesmtp76t1683863981tuj557jd Received: from localhost ( [103.102.203.204]) by bizesmtp.qq.com (ESMTP) with id ; Fri, 12 May 2023 11:59:39 +0800 (CST) X-QQ-SSF: 01100000000000Z0Z000000A0000000 X-QQ-FEAT: zT6n3Y95oi2crBROMop/6RJiK1eBM6z24efmuJaaCx3o2hRj/O9tAS9YJ/rcB MorC9io+e45PAeT67Nla9wDk7skR+SpGmdHi3vABZ7LQTuoNzSTF5sImVHqSLlHa+uhhv2j Ul+MQqZUL9ZXOW8vhE1orrvWrn/lrTjA0vY6egwBeSRb9Zh/BMuTbMFGR++voL5BwqVCnW9 uLKMpr5UIPLJfEMMnGQpRFqdDU4R1wQcmyvKsh1um+eO++IK0k8zA/GYWpzI+2ywDCx5GM0 eNW7QDfVXqAbjXFrSZCWpnvnjgxtpyEuIkQnHhem/8iWPmFvyIVntqC4SBPUt4C20Mp1I/g YAcLkF2oNJ32MCtLnA91j9cm0sgSo8BrdlYsWyFS0bOuj/4Sko= X-QQ-GoodBg: 0 X-BIZMAIL-ID: 3224015177392742705 From: Steven Liu To: ffmpeg-devel@ffmpeg.org Date: Fri, 12 May 2023 11:59:00 +0800 Message-Id: <20230512035901.22731-6-lq@chinaffmpeg.org> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230512035901.22731-1-lq@chinaffmpeg.org> References: <20230512035901.22731-1-lq@chinaffmpeg.org> MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:chinaffmpeg.org:qybglogicsvrsz:qybglogicsvrsz3a-3 Subject: [FFmpeg-devel] [PATCH v9 5/6] avformat/flvenc: support mux vp9 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: FsJlXZXDPBNG Signed-off-by: Steven Liu --- libavformat/Makefile | 2 +- libavformat/flvenc.c | 22 ++++++++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/libavformat/Makefile b/libavformat/Makefile index c868e1626c..16cfe107ea 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -214,7 +214,7 @@ OBJS-$(CONFIG_FLAC_MUXER) += flacenc.o flacenc_header.o \ OBJS-$(CONFIG_FLIC_DEMUXER) += flic.o OBJS-$(CONFIG_FLV_DEMUXER) += flvdec.o OBJS-$(CONFIG_LIVE_FLV_DEMUXER) += flvdec.o -OBJS-$(CONFIG_FLV_MUXER) += flvenc.o avc.o hevc.o av1.o +OBJS-$(CONFIG_FLV_MUXER) += flvenc.o avc.o hevc.o av1.o vpcc.o OBJS-$(CONFIG_FOURXM_DEMUXER) += 4xm.o OBJS-$(CONFIG_FRAMECRC_MUXER) += framecrcenc.o framehash.o OBJS-$(CONFIG_FRAMEHASH_MUXER) += hashenc.o framehash.o diff --git a/libavformat/flvenc.c b/libavformat/flvenc.c index c1784b332d..475dd0bf44 100644 --- a/libavformat/flvenc.c +++ b/libavformat/flvenc.c @@ -29,6 +29,7 @@ #include "avio.h" #include "avc.h" #include "av1.h" +#include "vpcc.h" #include "hevc.h" #include "avformat.h" #include "flv.h" @@ -50,6 +51,7 @@ static const AVCodecTag flv_video_codec_ids[] = { { AV_CODEC_ID_H264, FLV_CODECID_H264 }, { AV_CODEC_ID_HEVC, MKBETAG('h', 'v', 'c', '1') }, { AV_CODEC_ID_AV1, MKBETAG('a', 'v', '0', '1') }, + { AV_CODEC_ID_VP9, MKBETAG('v', 'p', '0', '9') }, { AV_CODEC_ID_NONE, 0 } }; @@ -494,7 +496,7 @@ static void flv_write_codec_header(AVFormatContext* s, AVCodecParameters* par, i 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_AV1) { + || par->codec_id == AV_CODEC_ID_AV1 || par->codec_id == AV_CODEC_ID_VP9) { int64_t pos; avio_w8(pb, par->codec_type == AVMEDIA_TYPE_VIDEO ? @@ -540,9 +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) { + } else if (par->codec_id == AV_CODEC_ID_AV1 || par->codec_id == AV_CODEC_ID_VP9) { avio_w8(pb, FLV_IS_EX_HEADER | PacketTypeSequenceStart); - avio_write(pb, "av01", 4); + avio_write(pb, par->codec_id == AV_CODEC_ID_AV1 ? "av01" : "vp09", 4); } else { avio_w8(pb, par->codec_tag | FLV_FRAME_KEY); // flags avio_w8(pb, 0); // AVC sequence header @@ -553,6 +555,8 @@ static void flv_write_codec_header(AVFormatContext* s, AVCodecParameters* par, i 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 if (par->codec_id == AV_CODEC_ID_VP9) + ff_isom_write_vpcc(s, pb, par->extradata, par->extradata_size, par); else ff_isom_write_avcc(pb, par->extradata, par->extradata_size); } @@ -852,14 +856,15 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt) 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 || par->codec_id == AV_CODEC_ID_AV1) + par->codec_id == AV_CODEC_ID_HEVC || par->codec_id == AV_CODEC_ID_AV1 || + par->codec_id == AV_CODEC_ID_VP9) 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_AV1) { + || par->codec_id == AV_CODEC_ID_AV1 || par->codec_id == AV_CODEC_ID_VP9) { 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))) { @@ -880,7 +885,8 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt) 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 || par->codec_id == AV_CODEC_ID_AV1) { + par->codec_id == AV_CODEC_ID_HEVC || par->codec_id == AV_CODEC_ID_AV1 || + par->codec_id == AV_CODEC_ID_VP9) { if (pkt->pts == AV_NOPTS_VALUE) { av_log(s, AV_LOG_ERROR, "Packet is missing PTS\n"); return AVERROR(EINVAL); @@ -993,9 +999,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 | PacketTypeCodedFramesX); // ExVideoTagHeader mode with PacketTypeCodedFramesX avio_write(pb, "hvc1", 4); - } else if (par->codec_id == AV_CODEC_ID_AV1) { + } else if (par->codec_id == AV_CODEC_ID_AV1 || par->codec_id == AV_CODEC_ID_VP9) { avio_w8(pb, FLV_IS_EX_HEADER | PacketTypeCodedFrames); - avio_write(pb, "av01", 4); + avio_write(pb, par->codec_id == AV_CODEC_ID_AV1 ? "av01" : "vp09", 4); } else { avio_w8(pb, flags); }