[Libav-user] How to modify the codec of a muxer correctly in ffmpeg6.0

hhhhao 2755942193 at qq.com
Thu Nov 9 15:53:01 EET 2023


I find a problem in the example file mux.c, and I need some help about how to modify the codec of a muxer
 // The filename is xxx.flv // The default codec for flv is AV_CODEC_ID_ADPCM_SWF and AV_CODEC_ID_FLV1 // If I want to modify the codec I need to copy the entire value of return pointer of av_guess_format() like this, since it returns a const pointer I can not modify it directly // It will cause a segmentation fault when I call avformat_write_header(), because it didn't copy the write_header function pointer in private fileds AVOutputFormat av_flv_format; av_flv_format = *(AVOutputFormat*)av_guess_format(NULL, filename, NULL); av_flv_format.audio_codec = AV_CODEC_ID_AAC; av_flv_format.video_codec = AV_CODEC_ID_H264; // Then I try to copy the whole FFOutputFormat to modify the codec // Because I can't include the mux.h file so I need to copy the definition of FFOutputFormat FFOutputFormat ff_flv_format; ff_flv_format = *(FFOutputFormat*)av_guess_format(NULL, filename, NULL); ff_flv_format.p.audio_codec = AV_CODEC_ID_AAC; ff_flv_format.p.video_codec = AV_CODEC_ID_H264; // At this time, it works avformat_alloc_output_context2(&oc,&ff_flv_format, NULL, filename);   
What should I do if I want to modify the codec?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://ffmpeg.org/pipermail/libav-user/attachments/20231109/c8fa623d/attachment.htm>


More information about the Libav-user mailing list