#include <stdio.h>
#include <stdlib.h>
extern "C" {
#include "libavcodec/avcodec.h"
//封装格式处理
#include "libavformat/avformat.h"
//像素处理
#include "libswscale/swscale.h"
#include "libavutil/imgutils.h"
};
//编码
//#pragma warning(disable : 4996)
int main()
{
//获取输入输出文件名
const char *input = "zzz.mp4";
const char *output = "zzz.yuv";
const char *output1 = "zzz.h264";
//1.注册所有组件
av_register_all();
//封装格式上下文,统领全局的结构体,保存了视频文件封装格式的相关信息
AVFormatContext *pFormatCtx = avformat_alloc_context();
//2.打开输入视频文件
if (avformat_open_input(&pFormatCtx, input, NULL, NULL) != 0)
{
printf("%s", "无法打开输入视频文件");
return 0;
}
//3.获取视频文件信息
if (avformat_find_stream_info(pFormatCtx, NULL) < 0)
{
printf("%s", "无法获取视频文件信息");
return 0;
}
//获取视频流的索引位置
//遍历所有类型的流(音频流、视频流、字幕流),找到视频流
int v_stre
输入视频文件,输出YUV文件和H264文件
最新推荐文章于 2022-07-02 22:40:37 发布
该博客介绍了一个C++程序,它利用ffmpeg库将.mp4视频文件转换为.YUV和.H264格式。程序首先打开输入文件,获取视频流信息,然后找到视频流并打开解码器。解码每一帧后,将其转换为YUV格式并写入文件,同时将原始H264数据写入另一个文件。
摘要由CSDN通过智能技术生成