* Created : 2017.09.21.
* Author : Yu Weifeng
* Function List :
* Last Modified :
* History :
* Modify Date Version Author Modification
* -----------------------------------------------
* 2017/09/21 V1.0.0 Yu Weifeng Created
******************************************************************************/
/*
__STDC_LIMIT_MACROS and __STDC_CONSTANT_MACROS are a workaround to allow C++ programs to use stdint.h
macros specified in the C99 standard that aren't in the C++ standard. The macros, such as UINT8_MAX, INT64_MIN,
and INT32_C() may be defined already in C++ applications in other ways. To allow the user to decide
if they want the macros defined as C99 does, many implementations require that __STDC_LIMIT_MACROS
and __STDC_CONSTANT_MACROS be defined before stdint.h is included.
This isn't part of the C++ standard, but it has been adopted by more than one implementation.
*/
#define __STDC_CONSTANT_MACROS
/*****************************************************************************
-Fuction : main
-Description : main
-Input :
-Output :
-Return :
* Modify Date Version Author Modification
* -----------------------------------------------
* 2017/09/21 V1.0.0 Yu Weifeng Created
******************************************************************************/
int main(int argc, char* argv[])
{
/*------------FFmpeg----------------*/
const char *strFilePath = "屌丝男士.mov";
AVFormatContext *ptFormatContext = NULL;//封装格式上下文,内部包含所有的视频信息
int i = 0;
int iVideoindex=0;//纯视频信息在音视频流中的位置,也就是指向音视频流数组中的视频元素
AVCodecContext *ptCodecContext;//编码器相关信息上下文,内部包含编码器相关的信息,指向AVFormatContext中的streams成员中的codec成员
AVCodec *ptCodec;//编码器,使用函数avcodec_find_decoder或者,该函数需要的id参数,来自于ptCodecContext中的codec_id成员
AVFrame *ptFrame=NULL;//存储一帧解码后像素(采样)数据
AVFrame *ptFrameAfterScale=NULL;//存储(解码数据)转换后的像素(采样)数据
unsigned char *pucFrameAfterScaleBuf=NULL;//用于存储ptFrameAfterScale中的像素(采样)缓冲数据
AVPacket *ptPacket=NULL;//存储一帧压缩编码数据
int iRet =0;
int iGotPicture=0;//解码函数的返回参数,got_picture_ptr Zero if no frame could be decompressed, otherwise, it is nonzero
/*------------SDL----------------*/
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER))
{//初始化SDL系统
printf("Could not initialize SDL - %s\n", SDL_GetError());
return -1;
}
//SDL 2.0 Support for multiple windows
iScreenWidth = ptCodecContext->width;
iScreenHeight = ptCodecContext->height;
ptSdlWindow = SDL_CreateWindow("Simplest ffmpeg player's Window", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
iScreenWidth, iScreenHeight, SDL_WINDOW_OPENGL);//创建窗口SDL_Window
if (!ptSdlWindow)
{
printf("SDL: could not create window - exiting:%s\n", SDL_GetError());
return -1;
}
ptSdlRenderer = SDL_CreateRenderer(ptSdlWindow, -1, 0);//创建渲染器SDL_Renderer
//IYUV: Y + U + V (3 planes)
//YV12: Y + V + U (3 planes)
//创建纹理SDL_Texture
ptSdlTexture = SDL_CreateTexture(ptSdlRenderer, SDL_PIXELFORMAT_IYUV, SDL_TEXTUREACCESS_STREAMING, ptCodecContext->width, ptCodecContext->height);