FFmpeg AVFormatContext 的使用

1. 说明:

  对于AVFormatContext的使用,主要就是读视频和写视频,下面是基本的流程

2. 读视频流程:

1.创建avformat上下文
AVFormatContext *ifmt_ctx = avformat_alloc_context()

2.打开视频文件
avformat_open_input(&ifmt_ctx, in_filename, 0, 0)

3.持续读取视频帧
while(...) {
av_read_frame(ifmt_ctx, &pkt)
}

4.关闭avformat上下文
avformat_close_input(&ifmt_ctx)

3. 写视频流程:

1.创建输出上下文
avformat_alloc_output_context2(&ofmt_ctx, NULL, NULL, out_filename)

2.写格式头部
avformat_write_header(ofmt_ctx, NULL)

3.持续输出帧
while(...) {
av_interleaved_write_frame(ofmt_ctx, &pkt)
}

4.写格式尾部
av_write_trailer(ofmt_ctx)

5.关闭上下文
avformat_free_context(ofmt_ctx)

猜你喜欢

转载自blog.csdn.net/u011193452/article/details/130561477