[Libav-user] Change the default audio and video codec loaded by avformat_alloc_output_context2

Mythili Vishalini Anbazhagan manbazhagan27 at gmail.com
Tue Jun 8 09:09:35 EEST 2021

I'm using ffmpeg libav library for live streaming via RTMP. I want to know
how to give my choice of audio and video codec for the particular format in

In Detail:
The following command works perfectly for me.
ffmpeg -re -stream_loop -1 -i ~/Downloads/Microsoft_Surface.mp4 -vcodec
copy -c:a aac -b:a 160k -ar 44100 -strict -2 -f flv -flvflags
no_duration_filesize rtmp://
In the output, I have set my audio codec to be aac and copied the video
codec from input, which is H264.
I want to emulate this in the library, but don't know how to.
avformat_alloc_output_context2, with parameter format name as "flv", sets
oformat audio codec to ADPCM_SWF and video codec to FLV1. How to change
that to AAC and H264 ?

So far, used av_guess_format to construct AVOutputFormat. It accepts only
format as input. And I don't know where to mention audio and video codec.
Also tried giving filename to avformat_alloc_output_context2 with the rest
of the parameters NULL. The file has AAC audio and H264 video. But still
ffmpeg loads oformat with ADPCM_SWF audio and FLV1 video codecs.

Any hint/guidance is hugely appreciated. Thank you.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://ffmpeg.org/pipermail/libav-user/attachments/20210608/d7933554/attachment.htm>

More information about the Libav-user mailing list