FFmpeg rewrite the tutorial01 Program-decode a video file and output the PPM file or BMP file.

Source: Internet
Author: User

Link: http://dranger.com/ffmpeg/tutorial01.html

This link is a good tutorial for getting started with FFMPEG, but the code in the original article is updated with the FFMPEG version, and some APIs have been replaced. Therefore, the program needs to be modified accordingly.

Reference 2: FFMPEG
Reference link 3: BMP file format Introduction Running Environment: Window 7 + vs2008 + ffmpeg0.10 Pipeline file can not run, due to the relationship of time, I did not go to the complete solution to this problem, there are dedicated to provide windows compiled lib and DLL (please refer to: http://ffmpeg.zeranoe.com/builds ), during Development in windows, beginners can skip the compilation issue and run a small example that can be seen directly, which gives them more confidence in the compilation process. Compiling FFMPEG by yourself is essential, because when you need to expand FFMPEG functions (such as adding faac), some people may not provide the corresponding lib and DLL on the Internet. This is called: self-help, tianzhuzhi, just enjoy it. The functions of the fuse file call the windows. h header file. For information about the BMP file format and conversion, refer to "Reference 2" and "Reference 3" I mentioned ". Before compiling tutorial01, make sure that the path of your header file and Lib file is correct. For example, you need to modify the path of the Lib library.


Source code: http://download.csdn.net/detail/ajaxhe/4130532source code:
// tutorial01.cpp// Code based on a tutorial by Martin Bohme (boehme@inb.uni-luebeckREMOVETHIS.de)// Tested on Gentoo, CVS version 5/01/07 compiled with GCC 4.1.1// A small sample program that shows how to use libavformat and libavcodec to// read video from a file.//// Use//// gcc -o tutorial01 tutorial01.c -lavutil -lavformat -lavcodec -lz//// to build (assuming libavformat and libavcodec are correctly installed// your system).//// Run using//// tutorial01 myvideofile.mpg//// to write the first five frames from "myvideofile.mpg" to disk in PPM// format.//#include <stdio.h>extern "C"{#include <libavcodec/avcodec.h>#include <libavformat/avformat.h>#include <libswscale/swscale.h>};#include <windows.h>bool saveAsBitmap(AVFrame *pFrameRGB, int width, int height, int iFrame){      FILE *pFile = NULL;      BITMAPFILEHEADER bmpheader;      BITMAPINFO bmpinfo;      char fileName[32];      int bpp = 24;      // open file      sprintf(fileName, "frame%d.bmp", iFrame);      pFile = fopen(fileName, "wb");      if (!pFile)            return false;            bmpheader.bfType = ('M' <<8)|'B';      bmpheader.bfReserved1 = 0;      bmpheader.bfReserved2 = 0;      bmpheader.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);      bmpheader.bfSize = bmpheader.bfOffBits + width*height*bpp/8;      bmpinfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);      bmpinfo.bmiHeader.biWidth = width;      bmpinfo.bmiHeader.biHeight = -height; //reverse the image      bmpinfo.bmiHeader.biPlanes = 1;      bmpinfo.bmiHeader.biBitCount = bpp;      bmpinfo.bmiHeader.biCompression = BI_RGB;      bmpinfo.bmiHeader.biSizeImage = 0;      bmpinfo.bmiHeader.biXPelsPerMeter = 100;      bmpinfo.bmiHeader.biYPelsPerMeter = 100;      bmpinfo.bmiHeader.biClrUsed = 0;      bmpinfo.bmiHeader.biClrImportant = 0;      fwrite(&bmpheader, sizeof(BITMAPFILEHEADER), 1, pFile);      fwrite(&bmpinfo.bmiHeader, sizeof(BITMAPINFOHEADER), 1, pFile);      uint8_t *buffer = pFrameRGB->data[0];      for (int h=0; h

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.