跟着雷神学FFmpeg(二)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Osean_li/article/details/83956062

引言

在前面已经扫盲式的恶补了相关的音视频的知识点,下面将根据雷神的思路写一些demo

书写第一个FFmpeg控制台程序

// FFmpegLen2.cpp : 定义控制台应用程序的入口点。
//
//

#include "stdafx.h"
#include <stdio.h>

//下面是为了兼容调用FFmpeg
#define __STDC_CONSTANT_MACROS

#ifdef _WIN32
//Windows,告诉调用的是C语言
extern "C"
{
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
};
#else
//Linux...
#ifdef __cplusplus
extern "C"
{
#endif
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#ifdef __cplusplus
};
#endif
#endif
int _tmain(int argc, _TCHAR* argv[])
{
	//用于测试FFmpeg是否加载成功,打印出FFmpeg的配置信息,运行无误说明配置成功了
	printf("%s",avcodec_configuration());
	system("pause");
	return 0;
}


在这里插入图片描述

  • 在调用的时候,需要简单的配置
  • 在项目的属性中,C/C++ 常规添加头文件
  • 链接中添加lib和依赖项

FFmpeg的解码函数

在这里插入图片描述

  • av_register_all() 注册所有组件
  • avformat_open_input() 打开输入视频文件
  • avformat_find_stream_info() 获取视频文件信息
  • avcodec_find_decoder() 查找编码器
  • avcodec_open2() 打开编码器
  • av_read_frame() 从输入文件读取一帧压缩数据
  • AVPacket
  • avcodec_decode_video2() 解码一阵压缩数据
  • AVFrame
  • avcodec_close() 关闭解码器
  • avformat_close_input() 关闭输入视频文件

#FFmpeg解码的数据结构

在这里插入图片描述

AVFormatContext 要申请AVFormatContext 作为操作上下的线索是核心内容
AVFormatContext 包含了

  • AVInputFortmat 文件的封装格式
  • AVStream 是个数组,一般视频就是两个,视频流和音频流,AVStream[0]视频流,AVStream[1]音频流
  • AVCodecContext 处理编解码,分装格式在编解码之上
  • AVCodec 每个解码器都会拥有一个自己的静态对像,每种音视频对应一个结构体
  • AVPacket 存储一帧压缩编码数据
  • AVFrame 存储一帧解码后像素(采样)数据

猜你喜欢

转载自blog.csdn.net/Osean_li/article/details/83956062
今日推荐