Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Timo Rothenpieler <timo@rothenpieler.org>
To: ffmpeg-devel@ffmpeg.org
Cc: Timo Rothenpieler <timo@rothenpieler.org>
Subject: [FFmpeg-devel] [PATCH 06/13] avformat/flvenc: refactor fourcc writing
Date: Tue, 21 May 2024 11:02:15 +0200
Message-ID: <20240521090316.782-7-timo@rothenpieler.org> (raw)
In-Reply-To: <20240521090316.782-1-timo@rothenpieler.org>

---
 libavformat/flvenc.c | 96 ++++++++++++++++++++++----------------------
 1 file changed, 47 insertions(+), 49 deletions(-)

diff --git a/libavformat/flvenc.c b/libavformat/flvenc.c
index 13e06aedbb..94d633fbca 100644
--- a/libavformat/flvenc.c
+++ b/libavformat/flvenc.c
@@ -492,6 +492,45 @@ static void write_metadata(AVFormatContext *s, unsigned int ts)
     avio_wb32(pb, flv->metadata_totalsize + 11);
 }
 
+static void write_codec_fourcc(AVIOContext *pb, enum AVCodecID codec_id)
+{
+    switch (codec_id) {
+    case AV_CODEC_ID_AAC:
+        avio_write(pb, "mp4a", 4);
+        return;
+    case AV_CODEC_ID_OPUS:
+        avio_write(pb, "Opus", 4);
+        return;
+    case AV_CODEC_ID_FLAC:
+        avio_write(pb, "fLaC", 4);
+        return;
+    case AV_CODEC_ID_MP3:
+        avio_write(pb, ".mp3", 4);
+        return;
+    case AV_CODEC_ID_AC3:
+        avio_write(pb, "ac-3", 4);
+        return;
+    case AV_CODEC_ID_EAC3:
+        avio_write(pb, "ec-3", 4);
+        return;
+    case AV_CODEC_ID_H264:
+        avio_write(pb, "avc1", 4);
+        return;
+    case AV_CODEC_ID_HEVC:
+        avio_write(pb, "hvc1", 4);
+        return;
+    case AV_CODEC_ID_AV1:
+        avio_write(pb, "av01", 4);
+        return;
+    case AV_CODEC_ID_VP9:
+        avio_write(pb, "vp09", 4);
+        return;
+    default:
+        av_log(NULL, AV_LOG_ERROR, "Invalid codec FourCC write requested.\n");
+        av_assert0(0);
+    }
+}
+
 static void flv_write_metadata_packet(AVFormatContext *s, AVCodecParameters *par, unsigned int ts, int stream_idx)
 {
     AVIOContext *pb = s->pb;
@@ -528,13 +567,8 @@ static void flv_write_metadata_packet(AVFormatContext *s, AVCodecParameters *par
         put_timestamp(pb, ts); //ts = pkt->dts, gen
         avio_wb24(pb, flv->reserved);
 
-        if (par->codec_id == AV_CODEC_ID_HEVC) {
-            avio_w8(pb, FLV_IS_EX_HEADER | PacketTypeMetadata| FLV_FRAME_VIDEO_INFO_CMD); // ExVideoTagHeader mode with PacketTypeMetadata
-            avio_write(pb, "hvc1", 4);
-        } else if (par->codec_id == AV_CODEC_ID_AV1 || par->codec_id == AV_CODEC_ID_VP9) {
-            avio_w8(pb, FLV_IS_EX_HEADER | PacketTypeMetadata| FLV_FRAME_VIDEO_INFO_CMD);
-            avio_write(pb, par->codec_id == AV_CODEC_ID_AV1 ? "av01" : "vp09", 4);
-        }
+        avio_w8(pb, FLV_IS_EX_HEADER | PacketTypeMetadata | FLV_FRAME_VIDEO_INFO_CMD); // ExVideoTagHeader mode with PacketTypeMetadata
+        write_codec_fourcc(pb, par->codec_id);
 
         avio_w8(pb, AMF_DATA_TYPE_STRING);
         put_amf_string(pb, "colorInfo");
@@ -703,24 +737,14 @@ static void flv_write_codec_header(AVFormatContext* s, AVCodecParameters* par, i
 
             if (extended_flv) {
                 avio_w8(pb, FLV_CODECID_EX_HEADER | AudioPacketTypeSequenceStart);
+                write_codec_fourcc(pb, par->codec_id);
 
                 if (par->codec_id == AV_CODEC_ID_AAC) {
-                    avio_write(pb, "mp4a", 4);
                     flv_write_aac_header(s, par);
-                } else if (par->codec_id == AV_CODEC_ID_OPUS) {
-                    avio_write(pb, "Opus", 4);
+                } else if (par->codec_id == AV_CODEC_ID_OPUS || par->codec_id == AV_CODEC_ID_FLAC) {
                     av_assert0(par->extradata_size);
                     avio_write(pb, par->extradata, par->extradata_size);
-                } else if (par->codec_id == AV_CODEC_ID_FLAC) {
-                    avio_write(pb, "fLaC", 4);
-                    av_assert0(par->extradata_size);
-                    avio_write(pb, par->extradata, par->extradata_size);
-                } else if (par->codec_id == AV_CODEC_ID_MP3)
-                    avio_write(pb, ".mp3", 4);
-                else if (par->codec_id == AV_CODEC_ID_AC3)
-                    avio_write(pb, "ac-3", 4);
-                else if (par->codec_id == AV_CODEC_ID_EAC3)
-                    avio_write(pb, "ec-3", 4);
+                }
             } else if (par->codec_id == AV_CODEC_ID_AAC) {
                 avio_w8(pb, get_audio_flags(s, par));
                 avio_w8(pb, 0); // AAC sequence header
@@ -743,14 +767,7 @@ static void flv_write_codec_header(AVFormatContext* s, AVCodecParameters* par, i
                     avio_w8(pb, FLV_IS_EX_HEADER | PacketTypeSequenceStart | FLV_FRAME_KEY);
                 }
 
-                if (par->codec_id == AV_CODEC_ID_H264)
-                    avio_write(pb, "avc1", 4);
-                else if (par->codec_id == AV_CODEC_ID_HEVC)
-                    avio_write(pb, "hvc1", 4);
-                else if (par->codec_id == AV_CODEC_ID_AV1)
-                    avio_write(pb, "av01", 4);
-                else if (par->codec_id == AV_CODEC_ID_VP9)
-                    avio_write(pb, "vp09", 4);
+                write_codec_fourcc(pb, par->codec_id);
 
                 if (track_idx)
                     avio_w8(pb, track_idx);
@@ -1240,14 +1257,7 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt)
                 avio_w8(pb, FLV_IS_EX_HEADER | pkttype | frametype);
             }
 
-            if (par->codec_id == AV_CODEC_ID_H264)
-                avio_write(pb, "avc1", 4);
-            else if (par->codec_id == AV_CODEC_ID_HEVC)
-                avio_write(pb, "hvc1", 4);
-            else if (par->codec_id == AV_CODEC_ID_AV1)
-                avio_write(pb, "av01", 4);
-            else if (par->codec_id == AV_CODEC_ID_VP9)
-                avio_write(pb, "vp09", 4);
+            write_codec_fourcc(pb, par->codec_id);
 
             if (track_idx)
                 avio_w8(pb, track_idx);
@@ -1255,19 +1265,7 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt)
                 avio_wb24(pb, pkt->pts - pkt->dts);
         } else if (extended_audio) {
             avio_w8(pb, FLV_CODECID_EX_HEADER | AudioPacketTypeCodedFrames);
-
-            if (par->codec_id == AV_CODEC_ID_AAC)
-                avio_write(pb, "mp4a", 4);
-            else if (par->codec_id == AV_CODEC_ID_OPUS)
-                avio_write(pb, "Opus", 4);
-            else if (par->codec_id == AV_CODEC_ID_FLAC)
-                avio_write(pb, "fLaC", 4);
-            else if (par->codec_id == AV_CODEC_ID_MP3)
-                avio_write(pb, ".mp3", 4);
-            else if (par->codec_id == AV_CODEC_ID_AC3)
-                avio_write(pb, "ac-3", 4);
-            else if (par->codec_id == AV_CODEC_ID_EAC3)
-                avio_write(pb, "ec-3", 4);
+            write_codec_fourcc(pb, par->codec_id);
         } else {
             av_assert1(flags>=0);
             avio_w8(pb, flags);
-- 
2.43.2

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

  parent reply	other threads:[~2024-05-21  9:05 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-21  9:02 [FFmpeg-devel] [RFC 00/13] flvdec/flvenc: add support for enhanced rtmp codecs and multitrack/multichannel Timo Rothenpieler
2024-05-21  9:02 ` [FFmpeg-devel] [PATCH 01/13] avformat/flvenc: Implement support for multi-track video Timo Rothenpieler
2024-05-21 18:48   ` Dennis Sädtler via ffmpeg-devel
2024-05-21 18:50     ` Timo Rothenpieler
     [not found]     ` <98D1BB90-39C6-413B-A158-8ADA201155BC@cosmin.at>
2024-05-21 18:54       ` Cosmin Stejerean via ffmpeg-devel
     [not found]         ` <7F89B9B2-FBC2-49E7-AC4F-68E41B584E1A@cosmin.at>
2024-05-21 18:56           ` Cosmin Stejerean via ffmpeg-devel
2024-05-21 18:56           ` Cosmin Stejerean via ffmpeg-devel
2024-05-21  9:02 ` [FFmpeg-devel] [PATCH 02/13] avformat/flvdec: Add support for demuxing multi-track FLV Timo Rothenpieler
2024-05-21  9:02 ` [FFmpeg-devel] [PATCH 03/13] avformat/flvenc: add enhanced audio codecs Timo Rothenpieler
2024-05-21  9:02 ` [FFmpeg-devel] [PATCH 04/13] avformat/flvenc: remove !size check for audio packets Timo Rothenpieler
2024-05-21  9:02 ` [FFmpeg-devel] [PATCH 05/13] avformat/flvdec: add enhanced audio codecs Timo Rothenpieler
2024-05-21  9:02 ` Timo Rothenpieler [this message]
2024-05-21  9:02 ` [FFmpeg-devel] [PATCH 07/13] avformat/flvenc: write enhanced rtmp multichannel info for audio with more than two channels Timo Rothenpieler
2024-05-21  9:02 ` [FFmpeg-devel] [PATCH 08/13] avformat/flvdec: parse enhanced rtmp multichannel info Timo Rothenpieler
2024-05-21  9:02 ` [FFmpeg-devel] [PATCH 09/13] avformat/flvenc: add support for writing multi track audio Timo Rothenpieler
2024-05-21  9:02 ` [FFmpeg-devel] [PATCH 10/13] avformat/flvdec: add support for reading " Timo Rothenpieler
2024-05-21  9:02 ` [FFmpeg-devel] [PATCH 11/13] avformat/rtmpproto: add more enhanced rtmp codecs Timo Rothenpieler
2024-05-21  9:02 ` [FFmpeg-devel] [PATCH 12/13] avformat/flvdec: stop shadowing local variables Timo Rothenpieler
2024-05-21  9:02 ` [FFmpeg-devel] [PATCH 13/13] avformat/flvdec: support all multi-track modes Timo Rothenpieler
2024-05-22  0:02   ` Michael Niedermayer
2024-05-22 18:26     ` Timo Rothenpieler
2024-05-22 18:27   ` [FFmpeg-devel] [PATCH v2 " Timo Rothenpieler
2024-05-23  1:57 ` [FFmpeg-devel] [RFC 00/13] flvdec/flvenc: add support for enhanced rtmp codecs and multitrack/multichannel Steven Liu
2024-05-28 15:14 ` Andrew Sayers
2024-05-28 17:11   ` Timo Rothenpieler

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240521090316.782-7-timo@rothenpieler.org \
    --to=timo@rothenpieler.org \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git