avformat_open_input()函数的第二个参数是输入流的格式。可以通过AVInputFormat结构和av_find_input_format()函数来指定格式。以下是一个示例:
AVFormatContext *format_context = NULL;
AVInputFormat *input_format = NULL;
// 打开文件并获取格式上下文
if (avformat_open_input(&format_context, "input.mp4", input_format, NULL) < 0) {
// 异常处理
}
// 指定格式
input_format = av_find_input_format("mp4");
// 打开文件并获取格式上下文
if (avformat_open_input(&format_context, "input.mp4", input_format, NULL) < 0) {
// 异常处理
}
// 释放格式上下文
avformat_close_input(&format_context);
在上面的示例中,参数input_format被指定为“mp4”。这可以确保avformat_open_input()能够正确地打开文件并获取格式上下文。