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. javascript 中的原型继承

    javascript圆形变成的基本规则: 所有数据都是对象: 要得到一个对象,不是通过实例化类,而是找到一个对象作为原型并克隆它: 对象会记住它的原型: 如果对象无法响应某个请求,它会把这个请求委托给 ...

  2. Python面面面

    1:Python有哪些特点和优点? 作为一门编程入门语言,Python主要有以下特点和优点: 可解释 具有动态特性 面向对象 简明简单 开源 具有强大的社区支持 当然,实际上Python的优点远不止如 ...

  3. logback-MDC日志唯一标识

    自定义LogbackFilter: import org.slf4j.MDC; import javax.servlet.*; import javax.servlet.annotation.WebF ...

  4. 关于toLocaleDateString的坑

    https://segmentfault.com/a/1190000009391790

  5. 小程序——如何引入外部js

    当写小程序需要引入一些额外的js文件时,可以这样: 一.先把外部js用一个函数封闭起来: test.js function myfunc() { console.log("myfunc... ...

  6. 配置DTP

    拓扑一  结果:NO 默认auto(被动)模式 Switch>show interfaces fastEthernet / switchPort Name: Fa0/ Switchport: E ...

  7. CentOS无法使用ifconfig和root密码修改

    初学Linux,总是有许多问题,这次就遇到了这个问题: 想使用ifconfig命令查看一下虚拟机的ip地址,结果发现ifconfig命令无法使用,总是显示找不到ifconfig这个命令. 上网查询帮助 ...

  8. python笔记-数学、元组、日期、文件

    python在很多地方和C++相似,比如都会有关系.逻辑等运算符,但也有不同的地方,比如:#Python Number 类型转换int(x [,base ]) 将x转换为一个整数 long(x [,b ...

  9. flask 图文混排的简单操作

    1.引入js 包<script type="text/javascript" src="../../static/news/js/jquery-1.12.4.min ...

  10. mysql_函数

    MySQL 函数 (http://www.cnblogs.com/chenpi/p/5137178.html) 1.什么是函数 mysql中的函数与存储过程类似,都是一组SQL集: 2.与存储过程的区 ...