1.去FFMPEG网站上下载Dev版本的库,里面有我们需要的头文件和lib文件,然后下载Shared版本的库,里面有我们需要的dll文件

记得区分32位和64位的库,这里碰到一个大坑,就是我下载的是64位的库,但是创建工程的时候选的是32位的工程,导致链接的时候一直报
无法解析的外部符号 _av_register_all。。。(这个因为以前在Linux上使用的都是自己编译出来的库,所以没注意这个坑)
最后通过这个链接解决的
 

2.把Dev库里解压出来的东西拷贝到工程中,Shared库中解压出来的东西拷贝到生成的bin文件目录(如release)

G:\source\FFmpegDemo\FFmpegDemo\ffmpeg>
├─inc
│ ├─libavcodec
│ ├─libavdevice
│ ├─libavfilter
│ ├─libavformat
│ ├─libavutil
│ ├─libpostproc
│ ├─libswresample
│ └─libswscale
└─libs
avcodec.lib
avdevice.lib
avfilter.lib
avformat.lib
avutil.lib
postproc.lib
swresample.lib
swscale.lib

3.右击工程“属性”,“C/C++”——>“附加包含目录”——>加入我们添加进来的头文件的路径

4.在源码中链接lib文件

#pragma comment(lib,"ffmpeg\\libs\\avutil.lib")
#pragma comment(lib,"ffmpeg\\libs\\avformat.lib")
#pragma comment(lib,"ffmpeg\\libs\\avcodec.lib")
#pragma comment(lib,"ffmpeg\\libs\\swscale.lib")

源码如下:

//main.cpp
#include <stdio.h>
#include <stdlib.h> #pragma comment(lib,"ffmpeg\\libs\\avutil.lib")
#pragma comment(lib,"ffmpeg\\libs\\avformat.lib")
#pragma comment(lib,"ffmpeg\\libs\\avcodec.lib")
#pragma comment(lib,"ffmpeg\\libs\\swscale.lib") extern "C"
{ //编码
#include "libavcodec/avcodec.h"
//封装格式处理
#include "libavformat/avformat.h"
//像素处理
#include "libswscale/swscale.h"
}; int main(int argc, char* argv[])
{
//获取输入输出文件名
const char *input = "test.mp4";
const char *output = "test.yuv"; //1.注册所有组件
av_register_all(); //封装格式上下文,统领全局的结构体,保存了视频文件封装格式的相关信息
AVFormatContext *pFormatCtx = avformat_alloc_context(); //2.打开输入视频文件
if (avformat_open_input(&pFormatCtx, input, NULL, NULL) != 0)
{
printf("%s", "无法打开输入视频文件");
return -1;
} //3.获取视频文件信息
if (avformat_find_stream_info(pFormatCtx, NULL) < 0)
{
printf("%s", "无法获取视频文件信息");
return -1;
} //获取视频流的索引位置
//遍历所有类型的流(音频流、视频流、字幕流),找到视频流
int v_stream_idx = -1;
int i = 0;
//number of streams
for (; i < pFormatCtx->nb_streams; i++)
{
//流的类型
if (pFormatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO)
{
v_stream_idx = i;
break;
}
} if (v_stream_idx == -1)
{
printf("%s", "找不到视频流\n");
return -1;
} //只有知道视频的编码方式,才能够根据编码方式去找到解码器
//获取视频流中的编解码上下文
AVCodecContext *pCodecCtx = pFormatCtx->streams[v_stream_idx]->codec;
//4.根据编解码上下文中的编码id查找对应的解码
AVCodec *pCodec = avcodec_find_decoder(pCodecCtx->codec_id);
if (pCodec == NULL)
{
printf("%s", "找不到解码器\n");
return -1;
} //5.打开解码器
if (avcodec_open2(pCodecCtx, pCodec, NULL) < 0)
{
printf("%s", "解码器无法打开\n");
return -1;
} //输出视频信息
printf("视频的文件格式:%s", pFormatCtx->iformat->name);
printf("视频时长:%d", (pFormatCtx->duration) / 1000000);
printf("视频的宽高:%d,%d", pCodecCtx->width, pCodecCtx->height);
printf("解码器的名称:%s", pCodec->name); //准备读取
//AVPacket用于存储一帧一帧的压缩数据(H264)
//缓冲区,开辟空间
AVPacket *packet = (AVPacket*)av_malloc(sizeof(AVPacket)); //AVFrame用于存储解码后的像素数据(YUV)
//内存分配
AVFrame *pFrame = av_frame_alloc();
//YUV420
AVFrame *pFrameYUV = av_frame_alloc();
//只有指定了AVFrame的像素格式、画面大小才能真正分配内存
//缓冲区分配内存
uint8_t *out_buffer = (uint8_t *)av_malloc(avpicture_get_size(AV_PIX_FMT_YUV420P, pCodecCtx->width, pCodecCtx->height));
//初始化缓冲区
avpicture_fill((AVPicture *)pFrameYUV, out_buffer, AV_PIX_FMT_YUV420P, pCodecCtx->width, pCodecCtx->height); //用于转码(缩放)的参数,转之前的宽高,转之后的宽高,格式等
struct SwsContext *sws_ctx = sws_getContext(pCodecCtx->width, pCodecCtx->height, pCodecCtx->pix_fmt,
pCodecCtx->width, pCodecCtx->height, AV_PIX_FMT_YUV420P,
SWS_BICUBIC, NULL, NULL, NULL);
int got_picture, ret; FILE *fp_yuv = fopen(output, "wb+"); int frame_count = 0; //6.一帧一帧的读取压缩数据
while (av_read_frame(pFormatCtx, packet) >= 0)
{
//只要视频压缩数据(根据流的索引位置判断)
if (packet->stream_index == v_stream_idx)
{
//7.解码一帧视频压缩数据,得到视频像素数据
ret = avcodec_decode_video2(pCodecCtx, pFrame, &got_picture, packet);
if (ret < 0)
{
printf("%s", "解码错误");
return -1;
} //为0说明解码完成,非0正在解码
if (got_picture)
{
//AVFrame转为像素格式YUV420,宽高
//2 6输入、输出数据
//3 7输入、输出画面一行的数据的大小 AVFrame 转换是一行一行转换的
//4 输入数据第一列要转码的位置 从0开始
//5 输入画面的高度
sws_scale(sws_ctx, pFrame->data, pFrame->linesize, 0, pCodecCtx->height,
pFrameYUV->data, pFrameYUV->linesize); //输出到YUV文件
//AVFrame像素帧写入文件
//data解码后的图像像素数据(音频采样数据)
//Y 亮度 UV 色度(压缩了) 人对亮度更加敏感
//U V 个数是Y的1/4
int y_size = pCodecCtx->width * pCodecCtx->height;
fwrite(pFrameYUV->data[0], 1, y_size, fp_yuv);
fwrite(pFrameYUV->data[1], 1, y_size / 4, fp_yuv);
fwrite(pFrameYUV->data[2], 1, y_size / 4, fp_yuv); frame_count++;
printf("解码第%d帧\n", frame_count);
}
} //释放资源
av_free_packet(packet);
} fclose(fp_yuv); av_frame_free(&pFrame); avcodec_close(pCodecCtx); avformat_free_context(pFormatCtx); return 0;
}

Windows FFMPEG开发环境配置的更多相关文章

  1. windows phone7开发环境配置错误

    遇到下面这样一个问题:在配置windows phoe7开发环境的时候出现如下错误,以及相应的解决方案,希望对大家有所帮助. 装完环境后出现下面错误: [caption id="attachm ...

  2. QT creator+OpenCV2.4.2+MinGW 在windows下开发环境配置

    由于项目开发的原因,需要配置QT creator+OpenCV2.4.2+MinGW开发环境,现对配置方法做如下总结: 1.  下载必备软件 QT SDK for Open Source C++ de ...

  3. Windows高效开发环境配置(一)

    更多精彩内容,欢迎关注公众号:逻魔代码 前言 用了多年的 MacOS 做开发,一系列诸如 Alfred.Item2.Oh-my-zsh 之类的工具,大大地提升了工作的效率和使用舒适度.新工作不给配 M ...

  4. wxWidgets 在 Windows 下开发环境配置

    本文基于 CodeBlocks (16.01) 和 wxWidgets (3.0.2) 搭建 Windows 环境下 GUI 开发环境. 1.  CodeBlocks 官网,下载最新版安装包 code ...

  5. VS2013 FFmpeg开发环境配置

    1.下载ffmpeg包(dll.include.lib)   https://ffmpeg.zeranoe.com/builds/         有3个版本:Static.Shared和Dev St ...

  6. Python在Windows下开发环境配置汇总

    最近比较关注学习Python方面的资料和课程,由于Python本身基本都是在Linux下开发,本人windows用习惯了初用Linux各种别扭啊. 下面将我在配置Windows环境下的禁言写出来,与大 ...

  7. (OpenCV) VS2013 + opencv-2.4.10.exe + Windows 10 开发环境配置

    主要配置2点: - Windows 环境变量. - VC++ 配置. STEP BY STEP: 1. 双击 ”opencv-2.4.10.exe“,解压到本地文件夹 “C:\ ". 2. ...

  8. OpenCV 学习笔记(7)vs2015+ffmpeg开发环境配置

    参考教程 https://blog.csdn.net/HUSTLX/article/details/51014307 1.在http://ffmpeg.zeranoe.com/builds/  下载最 ...

  9. vs2015+ffmpeg开发环境配置【转】

    本文转载自:http://blog.csdn.net/hustlx/article/details/51014307 1.在http://ffmpeg.zeranoe.com/builds/ 下载最新 ...

随机推荐

  1. 洛谷P1966 【火柴排队】

    题解 P1966 [火柴排队] 说明: 在数学中有个公式: (a1-b1)^2+(a2-b2)^2<(a2-b1)^2+(a1-b2)^2 (你可以自己试着证一下) 两列火柴对应的两根火柴在各列 ...

  2. wpf 依赖属性介绍

    微软在wpf中推出le 附加属性 这个新概念 简单来说,本来自己这个类是不具备该行为,但是在特殊情况下需要用到该属性 比如在 TextBox 本来是不具备,几行几列 跨行等 行为 ,但是如果  把他放 ...

  3. 【EMV L2】2CS.001.00 ~ 2CS.007.00

    测试case要求,对于T=0和T=1卡,命令中是否存在Le是有差异的: - Select: Mandatory Command00 A4 04 00 Lc Command Data LeLc = 05 ...

  4. Spark 灰度发布在十万级节点上的成功实践 CI CD

    原创文章,转载请务必将下面这段话置于文章开头处. 本文转发自技术世界,原文链接 http://www.jasongj.com/spark/ci_cd/ 本文所述内容基于某顶级互联网公司数万节点下 Sp ...

  5. shell脚本-1

    http://www.runoob.com/w3cnote/shell-scripting.html filename = "/home/........."错误!不能有空格 -- ...

  6. kylin cubing algorithm(算法)

    看到这一块的视频,结合光方博客的一些文档及自己的一点理解,记个笔记,以备不时之需. by layer cubing 1.on MR  这个算法的对cube的计算就像它的名字一样是按player进行的. ...

  7. [经验分享] MySQL Innodb表导致死锁日志情况分析与归纳【转,纯学习】

    在定时脚本运行过程中,发现当备份表格的sql语句与删除该表部分数据的sql语句同时运行时,mysql会检测出死锁,并打印出日志. 两个sql语句如下: (1)insert into backup_ta ...

  8. MySQL Sending data导致查询很慢的问题详细分析【转载】

    转自http://blog.csdn.net/yunhua_lee/article/details/8573621 [问题现象] 使用sphinx支持倒排索引,但sphinx从mysql查询源数据的时 ...

  9. C++中const的用法

    1.const修饰普通变量和指针 (1).const修饰普通变量 其写法有2种:a.const type value;   b.type const value; 这两种写法本质上是一样的.其含义是: ...

  10. LibreOffice字体问题解决;从window复制到Ubuntu

    拷贝或下载windows系统的Fonts字体集到对应的linux系统下;以ubuntu16.04系统为例. 1.进入windows系统,到C:WindowsFonts目录,复制拷贝自己需要的字体(也可 ...