[FFmpeg-devel] [PATCH 06/14] avformat/flvenc: refactor fourcc writing

Michael Niedermayer michael at niedermayer.cc
Fri Dec 20 00:27:54 EET 2024


Hi

On Tue, Dec 17, 2024 at 11:23:39PM +0100, Timo Rothenpieler wrote:
> 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.

hmm
doing
streamcontext->fourcc = write_codec_fourcc()
once and then reusing context->fourcc
is faster, if we write large quantities of fourccs

thx

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Give a rich man 100$ and he will turn it into 1000$.
Give a poor man 1000$ and he will spend it.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20241219/68fb1c27/attachment.sig>


More information about the ffmpeg-devel mailing list