ffmpeg将一个视频文件解码输出bmp和jpg文件--重写tutorial01程序
2013-11-16 09:49
519 查看
URL:http://blog.csdn.net/ajaxhe/article/details/7383800
参考链接1:Compile LibJPEG
http://w3studi.informatik.uni-stuttgart.de/~bischowg/languages/C++/CPPlibjpeg.html
参考链接2:利用ffmpeg0.5 和libjpeg实现抽取视频帧并将其保存为jpeg文件格式程序
http://blog.csdn.net/xingyu19871124/article/details/4316776
参考链接3:ffmpeg 重写tutorial01程序--将一个视频文件解码输出ppm文件或bmp文件
http://blog.csdn.net/ajaxhe/article/details/7340508
之前写过一个将视频文件解码输出bitmap文件(见参考链接3),由于项目需要,需要输出jpg文件,由于jpg格式是有损压缩的,比bmp格式要复杂许多,简单google下,libjpeg开源库正合我意,使用起来简单清晰,网上很多朋友提供了很好的例子,我在windows7下编译花费了较多的时间。
操作系统: windows 7 旗舰版
开发环境:vs2008
相关库:ffmpeg,libjpeg
vs工程文件:
http://download.csdn.net/detail/ajaxhe/4163638
1. 编译libjpeg
以前编译ffmpeg受过伤,想偷个懒,想想这么通用的库,网上提供的的.lib应该很多的,google "libjpeg for windows",第一条就提供了相应的库,大喜,用之,而事实上,正是因为自己的拿来主义,导致我后面遇到了各种莫名奇妙的问题,在执行jpeg_wirte_scanlines()和jpeg_finish_compress()时出现"写入位置发生访问冲突",由于是编译好的lib库,无法单步调试到相关函数里面检查错误,这个问题让人很绝望。
网上google时,无意找到了Compile
LibJPEG看看,似乎编译过程也并不复杂,报着最后一丝希望,决定自己编译下libjpeg。该文已经将编译过程写得很详细了,我在windows7下编译也没有任何问题。下面我做一个简单的翻译。
1.1 从 http://www.ijg.org/files/上下载jpegsrc.v6b.tar.gz。
1.2 解压,假设我们放在C:\temp\jpegsrc.v6b下。
1.3 重命名c:\jpegsrc.v6b\jpeg-6b\makefile.vc 为 c:\jpegsrc.v6b\jpeg-6b\Makefile。
1.4 重命名c:\jpegsrc.v6b\jpeg-6b\jconfig.vc 为 c:\jpegsrc.v6b\jpeg-6b\jconfig.h。
1.5 打开cmd(快捷键:win+r)
1.6 在cmd中运行如下命令。vsvars32.bat的位置可能会不同,结合自己情况修改。注意:""不能少
"C:\Program Files\Microsoft Visual Studio 9.0\Common7\Tools\vsvars32.bat"
cd C:\temp\jpegsrc.v6b\jpeg-6b
nmake -f Makefile
1.7 编译成功后,在C:\temp\jpegsrc.v6b\jpeg-6b下会生成一个libjpeg.lib文件
1.8 对C:\temp\jpegsrc.v6b\jpeg-6b\jmorecfg.h进行修改:
and make it look like this:
1.9 对C:\temp\jpegsrc.v6b\jpeg-6b\jmorecfg.h进行修改:
and make it look like this:
1.10 将
"jconfig.h"
"jerror.h"
"jinclude.h"
"jmorecfg.h"
"jpeglib.h"
以及
jpegliblib
添加到你的vs2008工程文件中
2. 使用libjpeg
由于libjpeg是C语言写的,在包含jpeglib.h时需要加上
3. 部分源代码
参考链接1:Compile LibJPEG
http://w3studi.informatik.uni-stuttgart.de/~bischowg/languages/C++/CPPlibjpeg.html
参考链接2:利用ffmpeg0.5 和libjpeg实现抽取视频帧并将其保存为jpeg文件格式程序
http://blog.csdn.net/xingyu19871124/article/details/4316776
参考链接3:ffmpeg 重写tutorial01程序--将一个视频文件解码输出ppm文件或bmp文件
http://blog.csdn.net/ajaxhe/article/details/7340508
之前写过一个将视频文件解码输出bitmap文件(见参考链接3),由于项目需要,需要输出jpg文件,由于jpg格式是有损压缩的,比bmp格式要复杂许多,简单google下,libjpeg开源库正合我意,使用起来简单清晰,网上很多朋友提供了很好的例子,我在windows7下编译花费了较多的时间。
操作系统: windows 7 旗舰版
开发环境:vs2008
相关库:ffmpeg,libjpeg
vs工程文件:
http://download.csdn.net/detail/ajaxhe/4163638
1. 编译libjpeg
以前编译ffmpeg受过伤,想偷个懒,想想这么通用的库,网上提供的的.lib应该很多的,google "libjpeg for windows",第一条就提供了相应的库,大喜,用之,而事实上,正是因为自己的拿来主义,导致我后面遇到了各种莫名奇妙的问题,在执行jpeg_wirte_scanlines()和jpeg_finish_compress()时出现"写入位置发生访问冲突",由于是编译好的lib库,无法单步调试到相关函数里面检查错误,这个问题让人很绝望。
网上google时,无意找到了Compile
LibJPEG看看,似乎编译过程也并不复杂,报着最后一丝希望,决定自己编译下libjpeg。该文已经将编译过程写得很详细了,我在windows7下编译也没有任何问题。下面我做一个简单的翻译。
1.1 从 http://www.ijg.org/files/上下载jpegsrc.v6b.tar.gz。
1.2 解压,假设我们放在C:\temp\jpegsrc.v6b下。
1.3 重命名c:\jpegsrc.v6b\jpeg-6b\makefile.vc 为 c:\jpegsrc.v6b\jpeg-6b\Makefile。
1.4 重命名c:\jpegsrc.v6b\jpeg-6b\jconfig.vc 为 c:\jpegsrc.v6b\jpeg-6b\jconfig.h。
1.5 打开cmd(快捷键:win+r)
1.6 在cmd中运行如下命令。vsvars32.bat的位置可能会不同,结合自己情况修改。注意:""不能少
"C:\Program Files\Microsoft Visual Studio 9.0\Common7\Tools\vsvars32.bat"
cd C:\temp\jpegsrc.v6b\jpeg-6b
nmake -f Makefile
1.7 编译成功后,在C:\temp\jpegsrc.v6b\jpeg-6b下会生成一个libjpeg.lib文件
1.8 对C:\temp\jpegsrc.v6b\jpeg-6b\jmorecfg.h进行修改:
/* INT32 must hold at least signed 32-bit values. */
#ifndef XMD_H /* X11/xmd.h correctly defines INT32 */
typedef long INT32;
#endif
and make it look like this:
// INT32 must hold at least signed 32-bit values.
//#ifndef XMD_H // X11/xmd.h correctly defines INT32
#if !defined( XMD_H ) && !defined( WIN32 )
typedef long INT32;
#endif
1.9 对C:\temp\jpegsrc.v6b\jpeg-6b\jmorecfg.h进行修改:
#ifdef NEED_FAR_POINTERS
#define FAR far
#else
#define FAR
#endif
and make it look like this:
#ifdef NEED_FAR_POINTERS
#define FAR far
#else
#undef FAR // Added by Linden Lab to remove warnings
#define FAR
#endif
1.10 将
"jconfig.h"
"jerror.h"
"jinclude.h"
"jmorecfg.h"
"jpeglib.h"
以及
jpegliblib
添加到你的vs2008工程文件中
2. 使用libjpeg
由于libjpeg是C语言写的,在包含jpeglib.h时需要加上
extern "C" {
#include "jpeglib.h"
}
3. 部分源代码
#include <windows.h> extern "C"{ #include <libavcodec/avcodec.h> #include <libavformat/avformat.h> #include <libswscale/swscale.h> #include "jpeglib.h" // for jpeglib }; //实现视频帧的jpeg压缩 void saveAsJpeg(***Frame *pFrameRGB, int width, int height, int framenum) { char fname[128]; // ***Picture my_pic ; struct jpeg_compress_struct cinfo; struct jpeg_error_mgr jerr; JSAMPROW row_pointer[1]; int row_stride; uint8_t *buffer; FILE *fp = NULL; buffer = pFrameRGB->data[0]; int size = sizeof(buffer); cinfo.err = jpeg_std_error(&jerr); jpeg_create_compress(&cinfo); //_snprintf(fname, sizeof(fname), "frames%d.jpg", framenum); sprintf(fname, "frames%d.jpg", framenum); fp = fopen(fname, "wb"); if (fp == NULL) return; jpeg_stdio_dest(&cinfo, fp); cinfo.image_width = width; cinfo.image_height = height; cinfo.input_components = 3; cinfo.in_color_space = JCS_RGB; jpeg_set_defaults(&cinfo); jpeg_set_quality(&cinfo, 80, true); jpeg_start_compress(&cinfo, TRUE); row_stride = width * 3; while (cinfo.next_scanline < height) { /* jpeg_write_scanlines expects an array of pointers to scanlines. * Here the array is only one element long, but you could pass * more than one scanline at a time if that's more convenient. */ row_pointer[0] = &buffer[cinfo.next_scanline * row_stride]; jpeg_write_scanlines(&cinfo, row_pointer, 1); } jpeg_finish_compress(&cinfo); fclose(fp); jpeg_destroy_compress(&cinfo); printf("compress %d frame finished!\n",framenum) ; return ; } |
相关文章推荐
- ffmpeg 重写tutorial01程序--将一个视频文件解码输出bmp和jpg文件
- ffmpeg 重写tutorial01程序--将一个视频文件解码输出ppm文件或bmp文件
- ffmpeg解码视频保存为BMP文件
- [学习笔记]基于ffmpeg的视频解码,输出YUV图像到文件。
- ffmpeg解码视频存为BMP文件
- 【转】ffmpeg解码含有B帧的视频文件的输出顺序
- ffmpeg解码视频存为BMP文件
- ffmpeg解码视频存为BMP文件
- 使用ffmpeg将BMP图片编码为x264视频文件,将H264视频保存为BMP图片,yuv视频文件保存为图片的代码
- 关于ffmpeg 的总结(一个linux 下 集 屏幕录像录音,音频视频转换,合并音频视频文件,格式转换于一身的命令)
- Android 音视频深入 九 FFmpeg解码视频生成yuv文件(附源码下载)
- 关于ffmpeg 的总结(一个linux 下 集 屏幕录像录音,音频视频转换,合并音频视频文件,格式转换于一身的命令)
- Android 本地视频播放器开发 —— ffmpeg解码视频文件中的音频
- 使用 FFmpeg 开发播放器基础--使用 ffmpeg 解码视频文件
- MFC中怎样读取一个JPG文件或BMP位图文件
- FFMPEG解复用、解码测试,音频保存WAV文件,视频保存为PPM图像
- 基于ffmpeg-1.1的视频解码并输出到LCD显示
- OpenCV中,将一个彩色视频文件以灰度格式输出
- Android本地视频播放器开发--ffmpeg解码视频文件中的音频(1)
- 利用FFmpeg将视频文件生成bmp图像帧