Recent projects related to the development of streaming media, because of the development experience know its difficulty, no way can only be picked up, the latest version of the SDK was changed a mess, but the general development of ideas are the same, see how many books to check how much information is useless, step by step to write code is the key to learn.
I will pass every day of learning, updated to the blog post, I hope to give more people want to learn to bring help, the end of the article attached to the project and the latest version of the SDK.
FFmpeg is used by most people to command the line, in fact, in real streaming media development, in order to flexibly use its development of streaming media application sequence, must use the official SDK development, in fact, we have a lot of products on the market
are based on ffmpeg, such as XX Av.
FFmpeg official website http://www.ffmpeg.org/
API Address http://www.ffmpeg.org/doxygen/trunk/index.html
Because the compilation in Windows is very painful, so it is recommended to download the compiled binaries directly, note that the official web site does not have a direct complete development package, you need to remove the download Linux or Windows
Shared libraries for Windows also need to download. lib Import library, since I am windows here I will provide windows
http://ffmpeg.zeranoe.com/builds/This page can be downloaded to the dynamic library and to the storage. Because FFmpeg has been entrusted to other organizations to maintain ... Find it on the page below there is also a point is that since the use of other people's things to remember must follow the LGPL or GPL license ... Don't embarrass your countrymen.
That's what foreigners say.
Donating shows that's benefit from my work and is thankful for the time I spend on it. So if you like my work and would like to see more, feel free to donate, if you can ' t right now don ' t worry about it and Ju St enjoy using FFmpeg on Windows. Thank all who have donated in the past!
Specific no nonsense, how to configure the project what, this is the novice level of the problem, I will not elaborate directly on the code plus comments I will provide source code download ... Project configuration Well, everyone, download the research.
[CPP]View Plaincopyprint?
- Ffmpeg_test.cpp: Defines the entry point of the console application.
- //
- #include "stdafx.h"
- #include <windows.h>
- #ifdef _cpprtti
- extern "C"
- {
- #endif
- #include "libavcodec/avcodec.h"//Codec
- #include "libavformat/avformat.h"//format context
- #include "libavformat/avio.h"//audio/Video IO
- #include "libavutil/file.h"//Processing files
- #ifdef _cpprtti
- };
- #endif
- void Setstdclr (WORD wd)
- {
- Setconsoletextattribute (:: GetStdHandle (Std_output_handle), WD);
- }
- int _tmain (int argc, _tchar* argv[])
- {
- //Register all encoder parser binary stream filters
- Av_register_all ();
- Avcodec_register_all ();
- SETSTDCLR (foreground_red | Foreground_green);
- Avformatcontext *pcontext=null; //Format Context
- int errno=0;
- Pcontext=avformat_alloc_context ();
- //Open input File New interface
- if (0==avformat_open_input (&pcontext,". \\test.mp4", Nullptr,null)) {
- printf ("Open file input succeeded!\n");
- }Else
- return 0;
- //Retrieve flow information from context
- if (0==avformat_find_stream_info (pcontext,null))
- {
- printf ("Get flow information successfully!\n");
- }Else
- return 0;
- //Loop multiple streams
- SETSTDCLR (foreground_red | Foreground_blue);
- For (unsigned int i=0;i<pcontext->nb_streams;i++)
- {
- //Media streaming
- Avstream *pstream = pcontext->streams[i];
- //Frame rate information is rational number/irrational number
- Avrational Frame =pstream->r_frame_rate;
- //Time ratio units
- Avrational timebase = pstream->time_base;
- //Stream duration bit rate
- int64_t duration= pstream->duration;
- printf ("Media Duration%d\n", duration);
- //Get the encoding type
- Avcodeccontext *pcodeccontext=pstream->codec;
- //Get Media type
- /************************************************************************/
- /*
- Enum Avmediatype {
- Avmedia_type_unknown =-1,///< usually treated as Avmedia_type_data
- Avmedia_type_video,
- Avmedia_type_audio,
- Avmedia_type_data,///< Opaque DATA information usually continuous
- Avmedia_type_subtitle,
- Avmedia_type_attachment,///< Opaque data information usually sparse
- Avmedia_type_nb
- };
- */
- /************************************************************************/
- Avmediatype avmediatype=pcodeccontext->codec_type;
- //Encoder ID
- Avcodecid codecid=pcodeccontext->codec_id;
- if (Avmediatype = = Avmedia_type_audio)
- {
- //If the video
- int audiochannels = pcodeccontext->channels;
- int samplerate = pcodeccontext->sample_rate;
- PixelFormat PixelFormat = pcodeccontext->pix_fmt;
- printf ("stream%d audio \ n", i);
- printf ("Audio sampling frequency%d/%d\n", Timebase.num,timebase.den);
- printf ("Audio time Unit%d/%d\n", Timebase.num,timebase.den);
- printf ("Number of audio channels%d\n", audiochannels);
- }
- Else if (Avmediatype = = avmedia_type_video)
- {
- //If the audio
- int videowidth = pcodeccontext->width;
- int videoheight = pcodeccontext->height;
- Avsampleformat samplefmt = pcodeccontext->sample_fmt;
- printf ("stream%d video \ n", i);
- printf ("frame rate frame rate%d/%d\n", frame.den,frame.num);
- printf ("Video time Unit%d/%d\n", Timebase.num,timebase.den);
- printf ("image width:%d\t height:%d\t%\n", videowidth,videoheight);
- printf ("image width:%d\t height:%d\t%\n", videowidth,videoheight);
- }
- switch (codecid)
- {
- Case AV_CODEC_ID_AAC:
- printf ("encoder faac\n");
- Break ;
- Case av_codec_id_h264:
- printf ("encoder h264\n");
- Break ;
- }
- }
- //Release context
- if (!pcontext)
- {
- Avformat_close_input (&pcontext);
- }
- return 0;
- }
The results of the operation are as follows:
Engineering
http://download.csdn.net/detail/yue7603835/8268095
FFmpeg SDK based streaming media Development 1---Decoding media file stream information (GO)