本教程只针对windows64/32+vs2013环境配置
第一步 :配环境
1.打开ffmpeg官网中编译好的windows版本http://ffmpeg.zeranoe.com/builds/
64位windows系统和32位系统各有三个版本分别为Static版本,Share版本,Dev版本;
在这里建议无论是32位还是64位系统都直接配置32位的ffmpeg版本,除非你vs2013选择的是x64编译器。

将32位版本Share版本和Dev下载,解压。
在Dev里面主要是一些头文件和lib,在share版本里主要是dll文件。

2.打开vs2013,新建一个win32控制台程序。
选择项目-》属性-》c++目录,分别在包含目录和库目录中打开dev版本中的include和lib(指的是你解压dev保存的位置,在里面找到include和lib)

3项目-》属性-》链接器-》输入-》依赖项中填写

avcodec.lib
avformat.lib
avutil.lib
avdevice.lib
avfilter.lib
postproc.lib
swresample.lib
swscale.lib
保存即可。

第二步:视频解码,此处是一个完整的视频解码工程,从解码到存储,在vs2013上可以运行,如果编译不成功,可考虑是否是环境配错了。注意关闭防火墙。

// ConsoleApplication9.cpp : 定义控制台应用程序的入口点。
// #include "stdafx.h"
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#pragma once
#pragma warning(disable:4996) extern "C"
{
#include <libavcodec/avcodec.h>
#include <libavdevice/avdevice.h>
#include<libavfilter/avfilter.h>
#include <libswscale/swscale.h>
#include <libswresample/swresample.h>
#include <libavformat/avformat.h>
#include <libavutil/avutil.h>
}; //定义BMP文件头
#ifndef _WINGDI_
#define _WINGDI_
typedef struct tagBITMAPFILEHEADER {
WORD bfType;
DWORD bfSize;
WORD bfReserved1;
WORD bfReserved2;
DWORD bfOffBits;
} BITMAPFILEHEADER, FAR *LPBITMAPFILEHEADER, *PBITMAPFILEHEADER; typedef struct tagBITMAPINFOHEADER{
DWORD biSize;
LONG biWidth;
LONG biHeight;
WORD biPlanes;
WORD biBitCount;
DWORD biCompression;
DWORD biSizeImage;
LONG biXPelsPerMeter;
LONG biYPelsPerMeter;
DWORD biClrUsed;
DWORD biClrImportant;
} BITMAPINFOHEADER, FAR *LPBITMAPINFOHEADER, *PBITMAPINFOHEADER; #endif //保存BMP文件的函数
void SaveAsBMP(AVFrame *pFrameRGB, int width, int height, int index, int bpp)
{
char buf[] = { };
//bmp头
BITMAPFILEHEADER bmpheader;
BITMAPINFOHEADER bmpinfo;
FILE *fp;
char *filename = new char[];
//文件存放路径,根据自己的修改
sprintf_s(filename, , "%s_%d.bmp", "D:\\", index);
if ((fp = fopen(filename, "wb+")) == NULL)
{
printf("open file failed!\n");
return;
} bmpheader.bfType = 0x4d42;
bmpheader.bfReserved1 = ;
bmpheader.bfReserved2 = ;
bmpheader.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
bmpheader.bfSize = bmpheader.bfOffBits + width*height*bpp / ; bmpinfo.biSize = sizeof(BITMAPINFOHEADER);
bmpinfo.biWidth = width;
bmpinfo.biHeight = height;
bmpinfo.biPlanes = ;
bmpinfo.biBitCount = bpp;
bmpinfo.biCompression = BI_RGB;
bmpinfo.biSizeImage = (width*bpp + ) / * * height;
bmpinfo.biXPelsPerMeter = ;
bmpinfo.biYPelsPerMeter = ;
bmpinfo.biClrUsed = ;
bmpinfo.biClrImportant = ; fwrite(&bmpheader, sizeof(bmpheader), , fp);
fwrite(&bmpinfo, sizeof(bmpinfo), , fp);
fwrite(pFrameRGB->data[], width*height*bpp / , , fp); fclose(fp);
} //主函数
int main(void)
{
unsigned int i = , videoStream = -;
AVCodecContext *pCodecCtx;
AVFormatContext *pFormatCtx;
AVCodec *pCodec;
AVFrame *pFrame, *pFrameRGB;
struct SwsContext *pSwsCtx;
const char *filename = "E:\\123.avi";//rtsp://192.168.2.214:554/bs0
AVPacket packet;
int frameFinished;
int PictureSize;
uint8_t *buf;
//注册编解码器
av_register_all();
avformat_network_init();
pFormatCtx = avformat_alloc_context();
//打开视频文件
if (avformat_open_input(&pFormatCtx, filename, NULL, NULL) != )
{
printf("av open input file failed!\n");
exit();
}
//获取流信息
if (avformat_find_stream_info(pFormatCtx, NULL) < )
{
printf("av find stream info failed!\n");
exit();
}
//获取视频流
for (i = ; i<pFormatCtx->nb_streams; i++)
if (pFormatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO)
{
videoStream = i;
break;
} if (videoStream == -)
{
printf("find video stream failed!\n");
exit();
} pCodecCtx = pFormatCtx->streams[videoStream]->codec; pCodec = avcodec_find_decoder(pCodecCtx->codec_id); if (pCodec == NULL)
{
printf("avcode find decoder failed!\n");
exit();
}
//打开解码器
if (avcodec_open2(pCodecCtx, pCodec, NULL)<)
{
printf("avcode open failed!\n");
exit();
} //为每帧图像分配内存
pFrame = av_frame_alloc();
pFrameRGB = av_frame_alloc(); if ((pFrame == NULL) || (pFrameRGB == NULL))
{
printf("avcodec alloc frame failed!\n");
exit();
}
//获得帧图大小
PictureSize = avpicture_get_size(AV_PIX_FMT_BGR24, pCodecCtx->width, pCodecCtx->height);
buf = (uint8_t*)av_malloc(PictureSize); if (buf == NULL)
{
printf("av malloc failed!\n");
exit();
}
avpicture_fill((AVPicture *)pFrameRGB, buf, AV_PIX_FMT_BGR24, pCodecCtx->width, pCodecCtx->height); //设置图像转换上下文
pSwsCtx = sws_getContext(pCodecCtx->width,
pCodecCtx->height,
pCodecCtx->pix_fmt,
pCodecCtx->width,
pCodecCtx->height,
AV_PIX_FMT_BGR24,
SWS_BICUBIC,
NULL, NULL, NULL);
i = ;
while (av_read_frame(pFormatCtx, &packet) >= )
{
if (packet.stream_index == videoStream)
{
//真正解码
avcodec_decode_video2(pCodecCtx, pFrame, &frameFinished, &packet);
if (frameFinished)
{
//反转图像 ,否则生成的图像是上下调到的
pFrame->data[] += pFrame->linesize[] * (pCodecCtx->height - );
pFrame->linesize[] *= -;
pFrame->data[] += pFrame->linesize[] * (pCodecCtx->height / - );
pFrame->linesize[] *= -;
pFrame->data[] += pFrame->linesize[] * (pCodecCtx->height / - );
pFrame->linesize[] *= -;
//转换图像格式,将解压出来的YUV420P的图像转换为BRG24的图像
sws_scale(pSwsCtx, pFrame->data, pFrame->linesize, , pCodecCtx->height, pFrameRGB->data, pFrameRGB->linesize);
//保存为bmp图
SaveAsBMP(pFrameRGB, pCodecCtx->width, pCodecCtx->height, i, );
i++;
}
av_free_packet(&packet);
}
}
sws_freeContext(pSwsCtx);
av_free(pFrame);
av_free(pFrameRGB);
avcodec_close(pCodecCtx);
avformat_close_input(&pFormatCtx); return ;
}

ffmpeg这样连接了后会花屏,解决方式如下(换成TCP连接方式):

AVDictionary* options = NULL;
av_dict_set(&options, "rtsp_transport", "tcp", );
if(avformat_open_input(&pFormatCtx,"rtsp://192.168.2.214:554/bs0",NULL,&options)!=){
printf("Couldn't open input stream.\n");
return -;
}
这样连接了不会花屏,但是延时会越来越长

c++ 配置ffmpeg的更多相关文章

  1. Visual Studio 开发(二):VS 2017配置FFmpeg开发环境

    在上篇文章Visual Studio 开发(一):安装配置Visual Studio Code 中,我们讲了一下如何配置VS CODE,来编写和调试C的代码.如果你已经使用VS Code回顾和复习好C ...

  2. Windows配置ffmpeg

    一.ffmpeg简介 ffmpeg是一套可以用来记录.转换数字音频.视频,并能将其转化为流的开源计算机程序.采用LGPL或GPL许可证.它提供了录制.转换以及流化音视频的完整解决方案. 支持操作系统: ...

  3. [转载]Windows x64下配置ffmpeg的方法

    ffmpeg简介 FFmpeg 是一款跨平台的,对视频.音频进行录制.转换.播放的命令行形式软件,它使用的是 libavcodec 编解码器.FFmpeg 官方网站是 http://ffmpeg.or ...

  4. FFmpeg + SoundTouch实现音频的变调变速

    本文使用FFmpeg + SoundTouch实现将音频解码后,进行变调变速处理,并将处理后的结果保存为WAV文件. 主要有以下内容: 实现一个FFmpeg的工具类,保存多媒体文件所需的解码信息 将解 ...

  5. iOS编译FFmpeg、kxmovie实现视频播放 (转载)

    由于FFmpeg开源框架的功能非常强大,可以播放的视频种类很多,同时添加第三方库kxmovie,实现视频播放,真的是爽爆了,因此今天来说一下关于FFmpeg在iOS手机上的一些配置过程,配置工具,还有 ...

  6. FFMPEG在嵌入式硬件上应用之 —— 基本环境搭建及编译

    前段时间在翻看电脑里面资料时,发现了以前做的在嵌入式硬件上面运行以ffmepg为基础,以嵌入式硬件解码的多媒体播放工作,发现都快忘记完了.今日得闲整理温习了一下ffmpeg在嵌入式上的运用,这里给大家 ...

  7. 【FFmpeg】Windows下FFmpeg调试

    为了深入了解ffmpeg的工作原理,需要阅读源代码,调试源代码.在Windows下调试ffmpeg源码,一种方法是在MinGW+Msys环境下,利用GDB进行调试:另一种是借助Eclipse进调试,其 ...

  8. 在Windows下利用Eclipse调试FFmpeg

    目录 [隐藏]  1 环境与软件 2 第一步:安装MinGW 3 第二步:配置编译环境 4 第三步:配置SDL 5 第四步:编译 5.1 编译faac 5.2 编译fdk-aac 5.3 编译x264 ...

  9. 在CentOS下利用Eclipse调试FFmpeg

    所需软件 64位软件打包下载链接:http://pan.baidu.com/s/1i3B08Up 密码:o50u https://yunpan.cn/cBKDSbrGDgBvz  访问密码 1f55 ...

随机推荐

  1. java学习-初级入门-面向对象②-面向对象概述-面向对象程序设计

    我们在  面向对象①中学习了,结构化程序设计. 今天我们一起学习面向对象程序设计. 学习面向对象程序设计就要了解,在面向对象中重要的知识点. 继承  .  多态   . 抽象  . 接口 我们会在接下 ...

  2. JavaScript--选择器

    1.选择器是jQuery的根基,在jQuery中,对事件处理,遍历DOM和Ajax操作都依赖于选择器. 2.选择的优点: --写法简洁: --完善的事件处理机制. 3.基本选择器: --基本选择器是j ...

  3. iOS Burp suite CA证书 HTTPS

    设置好burp suite代理后,在浏览器地址输入http://burp/,下载CA证书: 在iOS上下载CA证书,可通过邮件或百度云等一切iOS可以访问证书文件的方法: 点击证书文件iOS提示安装, ...

  4. Django(十九)文件上传:图片上传(后台上传、自定义上传)、

    一.基本设置 参考:https://docs.djangoproject.com/zh-hans/3.0/topics/http/file-uploads/ 1)配置project1/settings ...

  5. Python下opencv使用笔记(图像频域滤波与傅里叶变换)

    Python下opencv使用笔记(图像频域滤波与傅里叶变换) 转载一只程序喵 最后发布于2018-04-06 19:07:26 阅读数 1654  收藏 展开 本文转载自  https://blog ...

  6. 洛谷 P3435 [POI2006]OKR-Periods of Words

    题目传送门 解题思路: 这道题题面比较乱,先说一下这道题要求什么: 对于一个字符串,求它及它的所有前缀的一个答案串的长度之和,答案串就是对于一个字符串,找到一个它的一个前缀,这个前缀后面在复制一遍,得 ...

  7. R 《回归分析与线性统计模型》page140,5.1

    rm(list = ls()) library(car) library(MASS) library(openxlsx) A = read.xlsx("data140.xlsx") ...

  8. Element-UI Table 实现筛选数据功能

    最近产品提出了一个筛选数据的功能,要求在表头里实现一个下拉框进行筛选. 首先, Element-ui 的官方文档,el-table-column 下有一个 filters , 用于数据的筛选和过滤, ...

  9. String+、intern()、字符串常量池

    字符串连接符 "+"及字符串常量池实验.字符串final属性 结果预览 public class StrTest{ public static void main(String[] ...

  10. 值得一学的C语言

    P1085 不高兴的津津 #include <stdio.h> int main( ) { int a,b; int max=0; int result; for (int i = 0; ...