AVFormatContext是API中直接接触到的结构体,位于avformat.h中,结构体描述了一个多媒体文件或流的构成和基本信息。,是FFmpeg中最为基本的一个结构体。贯穿了ffmpeg使用的整个流程。
可以说是ffmpeg中最顶端的一个结构体。
头文件
举个例子(转封装格式,doc/examples/remux.c)
int main(int argc, char **argv)
{
const AVOutputFormat *ofmt = NULL;
AVFormatContext *ifmt_ctx = NULL, *ofmt_ctx = NULL;
AVPacket *pkt = NULL;
const char *in_filename, *out_filename;
int ret, i;
int stream_index = 0;
int *stream_mapping = NULL;
int stream_mapping_size = 0;
// 检查命令行参数是否足够
if (argc < 3) {
printf("usage: %s input output\n"
"API example program to remux a media file with libavformat and libavcodec.\n"
"The output format is guessed according to the file extension.\n"
"\n", argv[0]);
return 1;
}
// 获取输入和输出文件名
in_filename = argv[1];
out_filename = argv[2];
// 分配一个AVPacket结构体
pkt = av_packet_alloc();
if (!pkt) {
fprintf(stderr, "Could not allocate AVPacket\n");
return 1;
}
// 打开输入文件并读取其头信息
if ((ret = avformat_open_input(&ifmt_ctx, in_filename, 0, 0)) < 0) {
fprintf(stderr, "Could not open input file '%s'", in_filename);
goto end;
}
// 查找流信息,此时可能会预解析一些数据
if ((ret = avformat_find_stream_info(ifmt_ctx, 0)) < 0) {
fprintf(stderr, "Failed to retrieve input stream information");
goto end;
}
// 打印输入文件的格式信息
av_dump_format(ifmt_ctx, 0, in_filename, 0);
// 分配输出格式上下文
avformat_alloc_output_context2(

最低0.47元/天 解锁文章
508

被折叠的 条评论
为什么被折叠?



