最近研究ffmpeg,在ubuntu下感觉不太好调试,老是找不到函数的声明。所以我就把他移到windows下用vs2008分析

关于环境的搭建,我参考了 http://hi.baidu.com/forever803/blog/item/ba90cdd2cca917093af3cf9e.html ,这里我把步骤整理一下,顺便奉上图文

第1步:

下载ffmpeg SDK3.2:点击下载,并解压。

第2步:

打开vs2008新建一个空的vc++项目

第3步:

新建一个C++源文件,test.cpp,输入简单代码测试一下

  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. int main(){
  4. printf("aaaa\n");
  5. system("pause");
  6. return 0;
  7. }

按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代码:

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. #include "libavcodec/avcodec.h"
  7. #include "libavformat/avformat.h"
  8. #include "libswscale/swscale.h"
  9. #ifdef __cplusplus
  10. }
  11. #endif
  12. void SaveFrame(AVFrame *pFrame, int width, int height, int iFrame) {
  13. FILE *pFile;
  14. char szFilename[32];
  15. int  y;
  16. // Open file
  17. sprintf(szFilename, "frame%d.ppm", iFrame);
  18. pFile=fopen(szFilename, "wb");
  19. if(pFile==NULL)
  20. return;
  21. // Write header
  22. fprintf(pFile, "P6\n%d %d\n255\n", width, height);
  23. // Write pixel data
  24. for(y=0; y<height; y++)
  25. fwrite(pFrame->data[0]+y*pFrame->linesize[0], 1, width*3, pFile);
  26. // Close file
  27. fclose(pFile);
  28. }
  29. int main() {
  30. AVFormatContext *pFormatCtx;
  31. int             i, videoStream;
  32. AVCodecContext  *pCodecCtx;
  33. AVCodec         *pCodec;
  34. AVFrame         *pFrame;
  35. AVFrame         *pFrameRGB;
  36. AVPacket        packet;
  37. int             frameFinished;
  38. int             numBytes;
  39. uint8_t         *buffer;
  40. static struct SwsContext *img_convert_ctx;
  41. char * filePath="test.mp4";
  42. // Register all formats and codecs
  43. av_register_all();
  44. // Open video file
  45. if(av_open_input_file(&pFormatCtx, filePath, NULL, 0, NULL)!=0)
  46. return -1; // Couldn't open file
  47. // Retrieve stream information
  48. if(av_find_stream_info(pFormatCtx)<0)
  49. return -1; // Couldn't find stream information
  50. // Dump information about file onto standard error
  51. dump_format(pFormatCtx, 0, filePath, 0);
  52. // Find the first video stream
  53. videoStream=-1;
  54. for(i=0; i<pFormatCtx->nb_streams; i++)
  55. if(pFormatCtx->streams[i]->codec->codec_type==CODEC_TYPE_VIDEO) {
  56. videoStream=i;
  57. break;
  58. }
  59. if(videoStream==-1)
  60. return -1; // Didn't find a video stream
  61. // Get a pointer to the codec context for the video stream
  62. pCodecCtx=pFormatCtx->streams[videoStream]->codec;
  63. // Find the decoder for the video stream
  64. pCodec=avcodec_find_decoder(pCodecCtx->codec_id);
  65. if(pCodec==NULL) {
  66. fprintf(stderr, "Unsupported codec!\n");
  67. return -1; // Codec not found
  68. }
  69. // Open codec
  70. if(avcodec_open(pCodecCtx, pCodec)<0)
  71. return -1; // Could not open codec
  72. // Allocate video frame
  73. pFrame=avcodec_alloc_frame();
  74. // Allocate an AVFrame structure
  75. pFrameRGB=avcodec_alloc_frame();
  76. if(pFrameRGB==NULL)
  77. return -1;
  78. // Determine required buffer size and allocate buffer
  79. numBytes=avpicture_get_size(PIX_FMT_RGB24, pCodecCtx->width,
  80. pCodecCtx->height);
  81. buffer=(uint8_t *)av_malloc(numBytes*sizeof(uint8_t));
  82. // Assign appropriate parts of buffer to image planes in pFrameRGB
  83. // Note that pFrameRGB is an AVFrame, but AVFrame is a superset
  84. // of AVPicture
  85. avpicture_fill((AVPicture *)pFrameRGB, buffer, PIX_FMT_RGB24,
  86. pCodecCtx->width, pCodecCtx->height);
  87. // Read frames and save first five frames to disk
  88. i=0;
  89. while(av_read_frame(pFormatCtx, &packet)>=0) {
  90. if(packet.stream_index==videoStream) {
  91. // Decode video frame
  92. avcodec_decode_video(pCodecCtx, pFrame, &frameFinished,packet.data, packet.size);
  93. if(frameFinished) {
  94. // Convert the image from its native format to RGB
  95. img_convert_ctx = sws_getContext(pCodecCtx->width, pCodecCtx->height,pCodecCtx->pix_fmt, pCodecCtx->width, pCodecCtx->height,PIX_FMT_RGB24, SWS_BICUBIC, NULL, NULL, NULL);
  96. // Convert the image from its native format to RGB
  97. sws_scale(img_convert_ctx, pFrame->data, pFrame->linesize,0, pCodecCtx->height, pFrameRGB->data, pFrameRGB->linesize);
  98. if(++i<=5)
  99. SaveFrame(pFrameRGB, pCodecCtx->width, pCodecCtx->height,i);
  100. }
  101. }
  102. // Free the packet that was allocated by av_read_frame
  103. av_free_packet(&packet);
  104. }
  105. // Free the RGB image
  106. av_free(buffer);
  107. av_free(pFrameRGB);
  108. // Free the YUV frame
  109. av_free(pFrame);
  110. // Close the codec
  111. avcodec_close(pCodecCtx);
  112. // Close the video file
  113. av_close_input_file(pFormatCtx);
  114. printf("执行完毕\n");
  115. system("pause");
  116. return 0;
  117. }

这里可能出现的问题比较多,主要有:

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的更多相关文章

  1. VS2008/2005 MFC程序调试经验

    我的VS2008不知道是有bug还是自己的问题,很多时候变量定义后CTRL+F5运行却没反应,一定要“生成解决方案”下才行? 1.没有可用于当前位置的源代码 将工具->选项->调试-> ...

  2. VS2008 开发wince程序设备调试

    今天之前开发的一个wince程序,用户反馈报错,由于很久没玩了,从用户那里拿来设备.结果怎么调试的忘记了.在网上找了些资料,自己有摸索了一下.才搞定. 1.安装Microsoft ActiveSync ...

  3. Linux下编译ffmpeg并用GDB调试

    1.在Ubuntu界面上调处命令行界面,最方便的方式是使用快捷键Ctrl+Alt+T. 2.安装SDL SDL是一个开源的多媒体开发库,可以设置图像和视频的绘制等操作.如果不安装SDL,FFMPEG将 ...

  4. ubuntu下编译ffmpeg并用eclipse调试

    一.下载ffnpeg源码 下载地址:http://ffmpeg.org/download.html 二.解决版本问题 可能之前你编译过ffmpeg,或者装过相关的库,那都要先卸载掉,否则用的时候会报一 ...

  5. ffmpeg 使用 gdb 调试相关技巧

    本文说明了,在ffmpeg二次开发或调用库的过程,如何借助于ffmpeg源码进行调试. 注:ffmpeg版本是4.0. 1. 编写代码 编写将pcm数据转换为mp2的代码 pcm_to_mp2.c # ...

  6. win7 VS2008 ffmpeg release 版本崩溃 0x00905a4d 处未处理的异常

    这个坑, 我始终不相信编码的问题,但还是花了一上午加各种调试代码.一般加个断点,调试几下就知道是什么问题.在最后找不到解决办法的情况下google了一下,短短几分钟解决了这个问题. 程序都是踩着各种坑 ...

  7. VS2008远程调试

    环境:      同一局域网内,主机和虚拟机远程调试   远程计算机:虚拟机搭的WindowsXP/32(局域网中使用桥接,非局域网使用NAT)     本地计算机:Windows XP.Win71. ...

  8. VS2008远程调试方法

    在网上找了好多资料才把这个调试环境搭好,下面总结一下: 先说明两个概念: 1.      目标机:远程需要调试的机子,也就是被调试程序exe所在的机子,该机子可以安装VS2008或者不安装vs2008 ...

  9. win7 64 下 VS2008 调试、退出时错误的解决

    最近调试老程序的时候发现原来的VS2008会偶尔在调试C++程序的时候出现程序未响应的情况,开始还以为是个案,后来出现的频率越来越高完全影响心情啊!! 准备花时间解决一下这个问题.网上搜索没有发现任何 ...

随机推荐

  1. [转载]C# winform登陆框验证码的实现

    验证码技术已愈来愈成熟,从最初的数字.字母.字符.汉字已经到目前的语言,其应用也甚广,之前大多数只有在网站上可以看到,现在在一些客户端软件也经常可见(比如证券相关软件).之前做的一个基于 C# 客户端 ...

  2. windows下编译Libevent

    下载最新的libevent,目前是 libevent-2.0.21-stable.tar.gz 修改“D:\libevent-2.0.21-stable\event_iocp.c”.“D:\libev ...

  3. linux系统进程的内存布局

    内存管理模块是操作系统的心脏:它对应用程序和系统管理非常重要.今后的几篇文章中,我将着眼于实际的内存问题,但也不避讳其中的技术内幕.由于不少概念是通用的,所以文中大部分例子取自32位x86平台的Lin ...

  4. EasyTouch 3.1中文翻译

    Unity3D的Easy Touch 的手册最近寻找中文版本,google无果,自己动手.目前暂时只有c# ,javascript原理是一样的. 一.Quick Start 1-Import Easy ...

  5. 使用异步 I/O 大大提高应用程序的性能

    使用异步 I/O 大大提高应用程序的性能 学习何时以及如何使用 POSIX AIO API Linux® 中最常用的输入/输出(I/O)模型是同步 I/O.在这个模型中,当请求发出之后,应用程序就会阻 ...

  6. Linq to Entity中连接两个数据库时要注意的问题

    Linq to Entity中连接两个数据库时要注意的问题 今天大学同学问了我一个问题,Linq to Entity中连接两个数据库时,报错“指定的 LINQ 表达式包含对与不同上下文关联的查询的引用 ...

  7. 2014多校第一场A题 || HDU 4861 Couple doubi

    题目链接 题意 : 有K个球,给你一个数P,可以求出K个值,(i=1,2,...,k) : 1^i+2^i+...+(p-1)^i (mod p).然后女朋友先取,再xp取,都希望赢,如果女朋友能赢输 ...

  8. POJ3080Blue Jeans

    http://poj.org/problem?id=3080 题意 : 给你几个DNA序列,让你找他们的共同的最长的子串,若是子串长度小于3,就输出no significant commonaliti ...

  9. SDUT1466双向队列

    http://acm.sdut.edu.cn/sdutoj/showproblem.php?pid=1466&cid=1182 题目描述 想想双向链表……双向队列的定义差不多,也就是说一个队列 ...

  10. cojs 西瓜 解题报告

    首先我们要知道pick公式 设二维平面内任意多边形面积为S 设多边形内部整点数为a 设多边形边界的整点数为b 则满足S=a+b/2-1 变形得a=S-b/2+1 由期望的线性性质我们把问题转化为 1. ...