ffmpeg各种函数详解

一、ffmpeg基本流程图

在这里插入图片描述

1.1、av_register_all()

包含头文件:#include “libavformat/avformat.h”
作用:初始化 libavformat和注册所有的muxers、demuxers和protocols。基本所有的ffmpeg第一步都是它。

1.2、avformat_open_input()

作用:打开对应的文件
原函数:avformat_open_input(AVFormatContext **ps, const char *filename,AVInputFormat *fmt, AVDictionary **options)

AVFormatContext **ps:一般是avformat_alloc_context()申请的一个空间指针地址,类似于文件描述符,然后通过操作文件描述符来操作你打开的文件。

const char *filename:就是你要打开的文件名。

AVInputFormat *fmt:一般都写成NULL.

AVDictionary **options:附加选项写为NULL.

使用方法:

if (avformat_open_input(&pFormatCtx,url,NULL,NULL)!=0){
		printf("Couldn't open input stream.\n");
		return -1;
	}

1.3、int avformat_find_stream_info()

作用: 寻找对应的流信息。
原函数:
int avformat_find_stream_info(AVFormatContext *ic, AVDictionary ** options)

AVFormatContext *ic: 文件描述符

AVDictionary **options : 附加选项写为NULL.

使用方法:

	if(av_find_stream_info(pFormatCtx)<0){
		printf("Couldn't find stream information.\n");
		return -1;
	}

1.4 avcodec_find_decoder()

作用: 查找解码器。
原函数: AVCodec *avcodec_find_decoder(enum AVCodecID id);

enum AVCodecID id : 你的解码器ID
使用方法:

pCodec = avcodec_find_decoder(pCodecCtx->codec_id);
	if (pCodec == NULL) {
		printf("Codec not found.\n");
		return -1;
	}
	

1.5avcodec_open2()

作用: 该函数用于初始化一个视音频编解码器的AVCodecContext。
原函数:
int avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options);

AVCodecContext *avctx: 获取指向音频流的编解码器上下文的指针
const AVCodec *codec: 编码器名称
AVDictionary **options:附加选项写为NULL.

使用方法:

if (avcodec_open2(pCodecCtx, pCodec, NULL) < 0) {
		printf("Could not open codec.\n");
		return -1;
	}

1.6 av_read_frame()

作用: 获取视频的帧数据。
原函数:
int av_read_frame(AVFormatContext *s, AVPacket *pkt);

AVFormatContext *s:文件描述符
AVFormatContext *s:一个输出空间不能为NULL,帧率

使用方法:

while (av_read_frame(pFormatCtx, packet) >= 0)
 {

}

1.7avcodec_decode_video2()

作用: 该函数的作用是实现压缩视频的解码。
原函数:
int avcodec_decode_video2(AVCodecContext *avctx, AVFrame *picture, int *got_picture_ptr, const AVPacket *avpkt);

AVCodecContext *avctx:文件描述符
AVFrame *picture:输出参数
int *got_picture_ptr:该值为0表明没有图像可以解码,否则表明有图像可以解码
const AVPacket *avpkt:输入参数,包含待解码数据。

  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

永不秃头的程序员

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值