[FFmpeg-devel] [PATCH 06/14] avformat/flvenc: refactor fourcc writing
Timo Rothenpieler
timo at rothenpieler.org
Wed Dec 18 00:23:39 EET 2024
On 15.12.2024 23:41, Michael Niedermayer wrote:
> Hi Timo
>
> On Thu, Dec 12, 2024 at 08:55:31PM +0100, Timo Rothenpieler wrote:
>> ---
>> libavformat/flvenc.c | 96 ++++++++++++++++++++++----------------------
>> 1 file changed, 47 insertions(+), 49 deletions(-)
>>
>> diff --git a/libavformat/flvenc.c b/libavformat/flvenc.c
>> index 21e2bca5be..fbe5416353 100644
>> --- a/libavformat/flvenc.c
>> +++ b/libavformat/flvenc.c
>> @@ -493,6 +493,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);
>> + }
>> +}
>
> from the commit message i would have thought i would see something
> similar to ff_codec_bmp_tags[]
>
> such a table is more compact and can be used in both directions
I implemented it like this since it's in the hot path of the muxer, and
iterating over an array seems a bit unnecessary there.
More information about the ffmpeg-devel
mailing list