VS2008+ffmpeg SDK3.2调试tutorial01
最近研究ffmpeg,在ubuntu下感觉不太好调试,老是找不到函数的声明。所以我就把他移到windows下用vs2008分析
关于环境的搭建,我参考了 http://hi.baidu.com/forever803/blog/item/ba90cdd2cca917093af3cf9e.html ,这里我把步骤整理一下,顺便奉上图文
第1步:
下载ffmpeg SDK3.2:点击下载,并解压。
第2步:
打开vs2008新建一个空的vc++项目



第3步:
新建一个C++源文件,test.cpp,输入简单代码测试一下
- #include<stdio.h>
- #include<stdlib.h>
- int main(){
- printf("aaaa\n");
- system("pause");
- return 0;
- }
按F5运行,打印输出aaaa,则没问题

第4步:
将解压出来的sdk下的include目录下的所有文件夹和文件拷到vc++工程目录下的test.cpp同一个目录。我的是(C:\Users\easou\Documents\Visual Studio 2008\Projects\testffmpeg\testffmpeg),此时,目录结构如下图

第5步:
将解压出来的lib文件夹拷贝至tes.cpp同一目录下。
然后在vs2008里,单击工程右键->属性->常规->附加库目录 填入$(SolutionDir)\$(ProjectName)\lib

属性->链接器-> 附加依赖项 填入avcodec.lib avdevice.lib avfilter.lib avformat.lib avutil.lib swscale.lib 点击确定

第6步:
将tutorial01.c的内容复制到test.cpp中,并修改相关引用路径,按F7编译。F5运行
tes.cpp代码:
- #include <stdio.h>
- #include <stdlib.h>
- #ifdef __cplusplus
- extern "C" {
- #endif
- #include "libavcodec/avcodec.h"
- #include "libavformat/avformat.h"
- #include "libswscale/swscale.h"
- #ifdef __cplusplus
- }
- #endif
- void SaveFrame(AVFrame *pFrame, int width, int height, int iFrame) {
- FILE *pFile;
- char szFilename[32];
- int y;
- // Open file
- sprintf(szFilename, "frame%d.ppm", iFrame);
- pFile=fopen(szFilename, "wb");
- if(pFile==NULL)
- return;
- // Write header
- fprintf(pFile, "P6\n%d %d\n255\n", width, height);
- // Write pixel data
- for(y=0; y<height; y++)
- fwrite(pFrame->data[0]+y*pFrame->linesize[0], 1, width*3, pFile);
- // Close file
- fclose(pFile);
- }
- int main() {
- AVFormatContext *pFormatCtx;
- int i, videoStream;
- AVCodecContext *pCodecCtx;
- AVCodec *pCodec;
- AVFrame *pFrame;
- AVFrame *pFrameRGB;
- AVPacket packet;
- int frameFinished;
- int numBytes;
- uint8_t *buffer;
- static struct SwsContext *img_convert_ctx;
- char * filePath="test.mp4";
- // Register all formats and codecs
- av_register_all();
- // Open video file
- if(av_open_input_file(&pFormatCtx, filePath, NULL, 0, NULL)!=0)
- return -1; // Couldn't open file
- // Retrieve stream information
- if(av_find_stream_info(pFormatCtx)<0)
- return -1; // Couldn't find stream information
- // Dump information about file onto standard error
- dump_format(pFormatCtx, 0, filePath, 0);
- // Find the first video stream
- videoStream=-1;
- for(i=0; i<pFormatCtx->nb_streams; i++)
- if(pFormatCtx->streams[i]->codec->codec_type==CODEC_TYPE_VIDEO) {
- videoStream=i;
- break;
- }
- if(videoStream==-1)
- return -1; // Didn't find a video stream
- // Get a pointer to the codec context for the video stream
- pCodecCtx=pFormatCtx->streams[videoStream]->codec;
- // Find the decoder for the video stream
- pCodec=avcodec_find_decoder(pCodecCtx->codec_id);
- if(pCodec==NULL) {
- fprintf(stderr, "Unsupported codec!\n");
- return -1; // Codec not found
- }
- // Open codec
- if(avcodec_open(pCodecCtx, pCodec)<0)
- return -1; // Could not open codec
- // Allocate video frame
- pFrame=avcodec_alloc_frame();
- // Allocate an AVFrame structure
- pFrameRGB=avcodec_alloc_frame();
- if(pFrameRGB==NULL)
- return -1;
- // Determine required buffer size and allocate buffer
- numBytes=avpicture_get_size(PIX_FMT_RGB24, pCodecCtx->width,
- pCodecCtx->height);
- buffer=(uint8_t *)av_malloc(numBytes*sizeof(uint8_t));
- // Assign appropriate parts of buffer to image planes in pFrameRGB
- // Note that pFrameRGB is an AVFrame, but AVFrame is a superset
- // of AVPicture
- avpicture_fill((AVPicture *)pFrameRGB, buffer, PIX_FMT_RGB24,
- pCodecCtx->width, pCodecCtx->height);
- // Read frames and save first five frames to disk
- i=0;
- while(av_read_frame(pFormatCtx, &packet)>=0) {
- if(packet.stream_index==videoStream) {
- // Decode video frame
- avcodec_decode_video(pCodecCtx, pFrame, &frameFinished,packet.data, packet.size);
- if(frameFinished) {
- // Convert the image from its native format to RGB
- img_convert_ctx = sws_getContext(pCodecCtx->width, pCodecCtx->height,pCodecCtx->pix_fmt, pCodecCtx->width, pCodecCtx->height,PIX_FMT_RGB24, SWS_BICUBIC, NULL, NULL, NULL);
- // Convert the image from its native format to RGB
- sws_scale(img_convert_ctx, pFrame->data, pFrame->linesize,0, pCodecCtx->height, pFrameRGB->data, pFrameRGB->linesize);
- if(++i<=5)
- SaveFrame(pFrameRGB, pCodecCtx->width, pCodecCtx->height,i);
- }
- }
- // Free the packet that was allocated by av_read_frame
- av_free_packet(&packet);
- }
- // Free the RGB image
- av_free(buffer);
- av_free(pFrameRGB);
- // Free the YUV frame
- av_free(pFrame);
- // Close the codec
- avcodec_close(pCodecCtx);
- // Close the video file
- av_close_input_file(pFormatCtx);
- printf("执行完毕\n");
- system("pause");
- return 0;
- }
这里可能出现的问题比较多,主要有:
1、找不到stdint.h这个文件,将出现问题的头文件中的“include <stdint.h>”改为“include "stdint.h"”即可
2、无法解析的外部符号 _img_convert,参考文章http://witmax.cn/ffmpeg-img-convert.html
3、运行时会出现找不到avformat.dll的对话框,将sdk下的bin文件下的dll文件都拷贝到工程目录下的debug文件夹解决。
4、信息窗出现 testffmpeg.exe: 本机”已退出,返回值为 -1字样。检查一下,是否没有将你的test.mp4拷到tes.cpp同一个目录下,mp4文件网上随便找一个就可以。提供我的视频一个http://115.com/file/e7f1ylpy
最后按F5出现命令窗口如下,调试通过

到test.cpp文件的目录下看一下,多出了5个ppm文件

可以用acd查看

VS2008+ffmpeg SDK3.2调试tutorial01的更多相关文章
- VS2008/2005 MFC程序调试经验
我的VS2008不知道是有bug还是自己的问题,很多时候变量定义后CTRL+F5运行却没反应,一定要“生成解决方案”下才行? 1.没有可用于当前位置的源代码 将工具->选项->调试-> ...
- VS2008 开发wince程序设备调试
今天之前开发的一个wince程序,用户反馈报错,由于很久没玩了,从用户那里拿来设备.结果怎么调试的忘记了.在网上找了些资料,自己有摸索了一下.才搞定. 1.安装Microsoft ActiveSync ...
- Linux下编译ffmpeg并用GDB调试
1.在Ubuntu界面上调处命令行界面,最方便的方式是使用快捷键Ctrl+Alt+T. 2.安装SDL SDL是一个开源的多媒体开发库,可以设置图像和视频的绘制等操作.如果不安装SDL,FFMPEG将 ...
- ubuntu下编译ffmpeg并用eclipse调试
一.下载ffnpeg源码 下载地址:http://ffmpeg.org/download.html 二.解决版本问题 可能之前你编译过ffmpeg,或者装过相关的库,那都要先卸载掉,否则用的时候会报一 ...
- ffmpeg 使用 gdb 调试相关技巧
本文说明了,在ffmpeg二次开发或调用库的过程,如何借助于ffmpeg源码进行调试. 注:ffmpeg版本是4.0. 1. 编写代码 编写将pcm数据转换为mp2的代码 pcm_to_mp2.c # ...
- win7 VS2008 ffmpeg release 版本崩溃 0x00905a4d 处未处理的异常
这个坑, 我始终不相信编码的问题,但还是花了一上午加各种调试代码.一般加个断点,调试几下就知道是什么问题.在最后找不到解决办法的情况下google了一下,短短几分钟解决了这个问题. 程序都是踩着各种坑 ...
- VS2008远程调试
环境: 同一局域网内,主机和虚拟机远程调试 远程计算机:虚拟机搭的WindowsXP/32(局域网中使用桥接,非局域网使用NAT) 本地计算机:Windows XP.Win71. ...
- VS2008远程调试方法
在网上找了好多资料才把这个调试环境搭好,下面总结一下: 先说明两个概念: 1. 目标机:远程需要调试的机子,也就是被调试程序exe所在的机子,该机子可以安装VS2008或者不安装vs2008 ...
- win7 64 下 VS2008 调试、退出时错误的解决
最近调试老程序的时候发现原来的VS2008会偶尔在调试C++程序的时候出现程序未响应的情况,开始还以为是个案,后来出现的频率越来越高完全影响心情啊!! 准备花时间解决一下这个问题.网上搜索没有发现任何 ...
随机推荐
- 【POJ】【3537】Crosses and Crosses
博弈论 相当于放了x的位置,左右4格都不能再放x了,谁无处可放就输. n<=2000 直接枚举后继状态,暴力求SG函数即可. 例: 0000000->x..0000 / .x..000 / ...
- ASP文件操作(FSO)详解
实例一:写入文件 语法 object.CreateTextFile([要建立的文件],[如存在,是否替代]) <% Set fs =Server.CreateObject("Scrip ...
- tornado解析http body的过程分析
tornado解析http body的过程分析 在最近写的一个RESTful API Server过程中,发现tornaod对解析POST BODY的内容有限制. 而在以前用web.py则没有这个限制 ...
- Java 理论和实践: 了解泛型
转载自 : http://www.ibm.com/developerworks/cn/java/j-jtp01255.html 表面上看起来,无论语法还是应用的环境(比如容器类),泛型类型(或者泛型) ...
- hdu 1333 Smith Numbers
刚开始没看清题意,要找的数一定要是素数 ;}
- 套题T1
间隙妖怪(gap.cpp/c/pas) 题目描述: 八云紫是幻想乡的间隙妖怪.她喜欢和八云橙玩一个叫做翻转的游戏.具体规则如下,八云紫对一个长度为N字符串做M次翻转操作,每次操作给定一个X,八云紫将X ...
- C和指针贴图
ANSI C 算术转换 内存操作函数 打开流 关闭流 IO函数常用模式 字符输入函数 字符输出函数 撤销字符 未格式化的行IO 格式化的行IO-scanf家族 格式化IO-printf家族 print ...
- ipconfig
当使用ipconfig时不带任何参数选项,那么它为每个已经配置了的接口显示IP地址.子网掩码和缺省网关值. 如果你安装了虚拟机和无线网卡的话,它们的相关信息也会出现在这里.
- MSSQL2005数据库自动备份问题(到同一个局域网上的另一台电脑上)
有A数据库服务器,B本机: 我现在想通过在B机器上通过代码调用SQL来执行A数据库的备份到B机器上 调用的SQL语句为:Backup Database MYDATABASE To Disk ...
- Android WIFI 操作
代码 package com.wifitest; import java.util.List; import android.content.Context; import android.net.w ...