avformat_alloc_output_context2(&ofmt_ctx, NULL, NULL, filename);
avformat_alloc_output_context2 is responsible for allocating the output AVFormatContext.
ffmpeg has a variety of Context, its function is to manage a variety of modules.
For example, there is an output file: test.mp4. Use the avformat_alloc_output_context2 function to allocate a suitable AVFormatContext management structure based on the file name.