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

Guangyu Sun gsun at roblox.com
Tue Jun 8 20:48:49 EEST 2021


This might be what you are looking for:
AVStream *avformat_new_stream(AVFormatContext *s, const AVCodec *c);

Specify the correct codec when adding streams to the AVFormatContext
created by avformat_alloc_output_context2().

On Mon, Jun 7, 2021 at 11:39 PM Mythili Vishalini Anbazhagan <
manbazhagan27 at gmail.com> wrote:

> Hi,
> 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
> avformat_alloc_output_context2.
>
> 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://192.168.1.7/live/surface
> 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.
>
> _______________________________________________
> Libav-user mailing list
> Libav-user at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/libav-user
>
> To unsubscribe, visit link above, or email
> libav-user-request at ffmpeg.org with subject "unsubscribe".
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://ffmpeg.org/pipermail/libav-user/attachments/20210608/3fa44420/attachment.htm>


More information about the Libav-user mailing list