=====================================================

最简单的基于FFmpeg的视频播放器系列文章列表:

100行代码实现最简单的基于FFMPEG+SDL的视频播放器(SDL1.x)

最简单的基于FFMPEG+SDL的视频播放器 ver2 (采用SDL2.0)

最简单的基于FFmpeg的解码器-纯净版(不包含libavformat)

最简单的基于FFMPEG+SDL的视频播放器:拆分-解码器和播放器

最简单的基于FFMPEG的Helloworld程序

=====================================================

简介

之前做过一个FFMPEG+SDL的简单播放器:《100行代码实现最简单的基于FFMPEG+SDL的视频播放器》。该播放器采用SDL1.2显示视频。最近有不少人反映SDL已经升级到2.0版本了,甚至官网的Wiki上都只有SDL2.0的文档了,因此下载了SDL 2.0 并且进行了简单的研究。随后对此前的播放器进行了修改,将SDL1.2换成了SDL2.0。

注:《100行代码实现最简单的基于FFMPEG+SDL的视频播放器》文章中提到的很多知识这里不再重复记录。本文重点记录SDL1.2与SDL2.0的不同。

平台使用了VC2010,FFmpeg类库使用了最近的版本,SDL使用2.0版本。

Simplest FFmpeg Player 2

项目主页

SourceForge:https://sourceforge.net/projects/simplestffmpegplayer/

Github:https://github.com/leixiaohua1020/simplest_ffmpeg_player

开源中国:http://git.oschina.net/leixiaohua1020/simplest_ffmpeg_player

流程图

FFmpeg解码一个视频流程如下图所示:

SDL2.0显示YUV的流程图:

对比SDL1.2的流程图,发现变化还是很大的。几乎所有的API都发生了变化。但是函数和变量有一定的对应关系:

SDL_SetVideoMode()————SDL_CreateWindow()

SDL_Surface————SDL_Window

SDL_CreateYUVOverlay()————SDL_CreateTexture()

SDL_Overlay————SDL_Texture

不再一一例举。

下图为SDL1.x显示YUV的流程图。

简单解释各个变量的作用:

SDL_Window就是使用SDL的时候弹出的那个窗口。在SDL1.x版本中,只可以创建一个一个窗口。在SDL2.0版本中,可以创建多个窗口。
SDL_Texture用于显示YUV数据。一个SDL_Texture对应一帧YUV数据。
SDL_Renderer用于渲染SDL_Texture至SDL_Window。
SDL_Rect用于确定SDL_Texture显示的位置。注意:一个SDL_Texture可以指定多个不同的SDL_Rect,这样就可以在SDL_Window不同位置显示相同的内容(使用SDL_RenderCopy()函数)。
它们的关系如下图所示:

下图举了个例子,指定了4个SDL_Rect,可以实现4分屏的显示。

simplest_ffmpeg_player(标准版)代码

最基础的版本,学习的开始。

[cpp] view plaincopy
  1. /**
  2. * 最简单的基于FFmpeg的视频播放器 2
  3. * Simplest FFmpeg Player 2
  4. *
  5. * 雷霄骅 Lei Xiaohua
  6. * leixiaohua1020@126.com
  7. * 中国传媒大学/数字电视技术
  8. * Communication University of China / Digital TV Technology
  9. * http://blog.csdn.net/leixiaohua1020
  10. *
  11. * 第2版使用SDL2.0取代了第一版中的SDL1.2
  12. * Version 2 use SDL 2.0 instead of SDL 1.2 in version 1.
  13. *
  14. * 本程序实现了视频文件的解码和显示(支持HEVC,H.264,MPEG2等)。
  15. * 是最简单的FFmpeg视频解码方面的教程。
  16. * 通过学习本例子可以了解FFmpeg的解码流程。
  17. * This software is a simplest video player based on FFmpeg.
  18. * Suitable for beginner of FFmpeg.
  19. *
  20. */
  21. #include <stdio.h>
  22. #define __STDC_CONSTANT_MACROS
  23. #ifdef _WIN32
  24. //Windows
  25. extern "C"
  26. {
  27. #include "libavcodec/avcodec.h"
  28. #include "libavformat/avformat.h"
  29. #include "libswscale/swscale.h"
  30. #include "libavutil/imgutils.h"
  31. #include "SDL2/SDL.h"
  32. };
  33. #else
  34. //Linux...
  35. #ifdef __cplusplus
  36. extern "C"
  37. {
  38. #endif
  39. #include <libavcodec/avcodec.h>
  40. #include <libavformat/avformat.h>
  41. #include <libswscale/swscale.h>
  42. #include <SDL2/SDL.h>
  43. #include <libavutil/imgutils.h>
  44. #ifdef __cplusplus
  45. };
  46. #endif
  47. #endif
  48. //Output YUV420P data as a file
  49. #define OUTPUT_YUV420P 0
  50. int main(int argc, char* argv[])
  51. {
  52. AVFormatContext *pFormatCtx;
  53. int             i, videoindex;
  54. AVCodecContext  *pCodecCtx;
  55. AVCodec         *pCodec;
  56. AVFrame *pFrame,*pFrameYUV;
  57. unsigned char *out_buffer;
  58. AVPacket *packet;
  59. int y_size;
  60. int ret, got_picture;
  61. struct SwsContext *img_convert_ctx;
  62. char filepath[]="bigbuckbunny_480x272.h265";
  63. //SDL---------------------------
  64. int screen_w=0,screen_h=0;
  65. SDL_Window *screen;
  66. SDL_Renderer* sdlRenderer;
  67. SDL_Texture* sdlTexture;
  68. SDL_Rect sdlRect;
  69. FILE *fp_yuv;
  70. av_register_all();
  71. avformat_network_init();
  72. pFormatCtx = avformat_alloc_context();
  73. if(avformat_open_input(&pFormatCtx,filepath,NULL,NULL)!=0){
  74. printf("Couldn't open input stream.\n");
  75. return -1;
  76. }
  77. if(avformat_find_stream_info(pFormatCtx,NULL)<0){
  78. printf("Couldn't find stream information.\n");
  79. return -1;
  80. }
  81. videoindex=-1;
  82. for(i=0; i<pFormatCtx->nb_streams; i++)
  83. if(pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO){
  84. videoindex=i;
  85. break;
  86. }
  87. if(videoindex==-1){
  88. printf("Didn't find a video stream.\n");
  89. return -1;
  90. }
  91. pCodecCtx=pFormatCtx->streams[videoindex]->codec;
  92. pCodec=avcodec_find_decoder(pCodecCtx->codec_id);
  93. if(pCodec==NULL){
  94. printf("Codec not found.\n");
  95. return -1;
  96. }
  97. if(avcodec_open2(pCodecCtx, pCodec,NULL)<0){
  98. printf("Could not open codec.\n");
  99. return -1;
  100. }
  101. pFrame=av_frame_alloc();
  102. pFrameYUV=av_frame_alloc();
  103. out_buffer=(unsigned char *)av_malloc(av_image_get_buffer_size(AV_PIX_FMT_YUV420P,  pCodecCtx->width, pCodecCtx->height,1));
  104. av_image_fill_arrays(pFrameYUV->data, pFrameYUV->linesize,out_buffer,
  105. AV_PIX_FMT_YUV420P,pCodecCtx->width, pCodecCtx->height,1);
  106. packet=(AVPacket *)av_malloc(sizeof(AVPacket));
  107. //Output Info-----------------------------
  108. printf("--------------- File Information ----------------\n");
  109. av_dump_format(pFormatCtx,0,filepath,0);
  110. printf("-------------------------------------------------\n");
  111. img_convert_ctx = sws_getContext(pCodecCtx->width, pCodecCtx->height, pCodecCtx->pix_fmt,
  112. pCodecCtx->width, pCodecCtx->height, AV_PIX_FMT_YUV420P, SWS_BICUBIC, NULL, NULL, NULL);
  113. #if OUTPUT_YUV420P
  114. fp_yuv=fopen("output.yuv","wb+");
  115. #endif
  116. if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER)) {
  117. printf( "Could not initialize SDL - %s\n", SDL_GetError());
  118. return -1;
  119. }
  120. screen_w = pCodecCtx->width;
  121. screen_h = pCodecCtx->height;
  122. //SDL 2.0 Support for multiple windows
  123. screen = SDL_CreateWindow("Simplest ffmpeg player's Window", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
  124. screen_w, screen_h,
  125. SDL_WINDOW_OPENGL);
  126. if(!screen) {
  127. printf("SDL: could not create window - exiting:%s\n",SDL_GetError());
  128. return -1;
  129. }
  130. sdlRenderer = SDL_CreateRenderer(screen, -1, 0);
  131. //IYUV: Y + U + V  (3 planes)
  132. //YV12: Y + V + U  (3 planes)
  133. sdlTexture = SDL_CreateTexture(sdlRenderer, SDL_PIXELFORMAT_IYUV, SDL_TEXTUREACCESS_STREAMING,pCodecCtx->width,pCodecCtx->height);
  134. sdlRect.x=0;
  135. sdlRect.y=0;
  136. sdlRect.w=screen_w;
  137. sdlRect.h=screen_h;
  138. //SDL End----------------------
  139. while(av_read_frame(pFormatCtx, packet)>=0){
  140. if(packet->stream_index==videoindex){
  141. ret = avcodec_decode_video2(pCodecCtx, pFrame, &got_picture, packet);
  142. if(ret < 0){
  143. printf("Decode Error.\n");
  144. return -1;
  145. }
  146. if(got_picture){
  147. sws_scale(img_convert_ctx, (const unsigned char* const*)pFrame->data, pFrame->linesize, 0, pCodecCtx->height,
  148. pFrameYUV->data, pFrameYUV->linesize);
  149. #if OUTPUT_YUV420P
  150. y_size=pCodecCtx->width*pCodecCtx->height;
  151. fwrite(pFrameYUV->data[0],1,y_size,fp_yuv);    //Y
  152. fwrite(pFrameYUV->data[1],1,y_size/4,fp_yuv);  //U
  153. fwrite(pFrameYUV->data[2],1,y_size/4,fp_yuv);  //V
  154. #endif
  155. //SDL---------------------------
  156. #if 0
  157. SDL_UpdateTexture( sdlTexture, NULL, pFrameYUV->data[0], pFrameYUV->linesize[0] );
  158. #else
  159. SDL_UpdateYUVTexture(sdlTexture, &sdlRect,
  160. pFrameYUV->data[0], pFrameYUV->linesize[0],
  161. pFrameYUV->data[1], pFrameYUV->linesize[1],
  162. pFrameYUV->data[2], pFrameYUV->linesize[2]);
  163. #endif
  164. SDL_RenderClear( sdlRenderer );
  165. SDL_RenderCopy( sdlRenderer, sdlTexture,  NULL, &sdlRect);
  166. SDL_RenderPresent( sdlRenderer );
  167. //SDL End-----------------------
  168. //Delay 40ms
  169. SDL_Delay(40);
  170. }
  171. }
  172. av_free_packet(packet);
  173. }
  174. //flush decoder
  175. //FIX: Flush Frames remained in Codec
  176. while (1) {
  177. ret = avcodec_decode_video2(pCodecCtx, pFrame, &got_picture, packet);
  178. if (ret < 0)
  179. break;
  180. if (!got_picture)
  181. break;
  182. sws_scale(img_convert_ctx, (const unsigned char* const*)pFrame->data, pFrame->linesize, 0, pCodecCtx->height,
  183. pFrameYUV->data, pFrameYUV->linesize);
  184. #if OUTPUT_YUV420P
  185. int y_size=pCodecCtx->width*pCodecCtx->height;
  186. fwrite(pFrameYUV->data[0],1,y_size,fp_yuv);    //Y
  187. fwrite(pFrameYUV->data[1],1,y_size/4,fp_yuv);  //U
  188. fwrite(pFrameYUV->data[2],1,y_size/4,fp_yuv);  //V
  189. #endif
  190. //SDL---------------------------
  191. SDL_UpdateTexture( sdlTexture, &sdlRect, pFrameYUV->data[0], pFrameYUV->linesize[0] );
  192. SDL_RenderClear( sdlRenderer );
  193. SDL_RenderCopy( sdlRenderer, sdlTexture,  NULL, &sdlRect);
  194. SDL_RenderPresent( sdlRenderer );
  195. //SDL End-----------------------
  196. //Delay 40ms
  197. SDL_Delay(40);
  198. }
  199. sws_freeContext(img_convert_ctx);
  200. #if OUTPUT_YUV420P
  201. fclose(fp_yuv);
  202. #endif
  203. SDL_Quit();
  204. av_frame_free(&pFrameYUV);
  205. av_frame_free(&pFrame);
  206. avcodec_close(pCodecCtx);
  207. avformat_close_input(&pFormatCtx);
  208. return 0;
  209. }

simplest_ffmpeg_player_su(SU版)代码

标准版的基础之上引入了SDL的Event。

效果如下:

(1)SDL弹出的窗口可以移动了
(2)画面显示是严格的40ms一帧

[cpp] view plaincopy
  1. /**
  2. * 最简单的基于FFmpeg的视频播放器2(SDL升级版)
  3. * Simplest FFmpeg Player 2(SDL Update)
  4. *
  5. * 雷霄骅 Lei Xiaohua
  6. * leixiaohua1020@126.com
  7. * 中国传媒大学/数字电视技术
  8. * Communication University of China / Digital TV Technology
  9. * http://blog.csdn.net/leixiaohua1020
  10. *
  11. * 第2版使用SDL2.0取代了第一版中的SDL1.2
  12. * Version 2 use SDL 2.0 instead of SDL 1.2 in version 1.
  13. *
  14. * 本程序实现了视频文件的解码和显示(支持HEVC,H.264,MPEG2等)。
  15. * 是最简单的FFmpeg视频解码方面的教程。
  16. * 通过学习本例子可以了解FFmpeg的解码流程。
  17. * 本版本中使用SDL消息机制刷新视频画面。
  18. * This software is a simplest video player based on FFmpeg.
  19. * Suitable for beginner of FFmpeg.
  20. *
  21. * 备注:
  22. * 标准版在播放视频的时候,画面显示使用延时40ms的方式。这么做有两个后果:
  23. * (1)SDL弹出的窗口无法移动,一直显示是忙碌状态
  24. * (2)画面显示并不是严格的40ms一帧,因为还没有考虑解码的时间。
  25. * SU(SDL Update)版在视频解码的过程中,不再使用延时40ms的方式,而是创建了
  26. * 一个线程,每隔40ms发送一个自定义的消息,告知主函数进行解码显示。这样做之后:
  27. * (1)SDL弹出的窗口可以移动了
  28. * (2)画面显示是严格的40ms一帧
  29. * Remark:
  30. * Standard Version use's SDL_Delay() to control video's frame rate, it has 2
  31. * disadvantages:
  32. * (1)SDL's Screen can't be moved and always "Busy".
  33. * (2)Frame rate can't be accurate because it doesn't consider the time consumed
  34. * by avcodec_decode_video2()
  35. * SU(SDL Update)Version solved 2 problems above. It create a thread to send SDL
  36. * Event every 40ms to tell the main loop to decode and show video frames.
  37. */
  38. #include <stdio.h>
  39. #define __STDC_CONSTANT_MACROS
  40. #ifdef _WIN32
  41. //Windows
  42. extern "C"
  43. {
  44. #include "libavcodec/avcodec.h"
  45. #include "libavformat/avformat.h"
  46. #include "libswscale/swscale.h"
  47. #include "libavutil/imgutils.h"
  48. #include "SDL2/SDL.h"
  49. };
  50. #else
  51. //Linux...
  52. #ifdef __cplusplus
  53. extern "C"
  54. {
  55. #endif
  56. #include <libavcodec/avcodec.h>
  57. #include <libavformat/avformat.h>
  58. #include <libswscale/swscale.h>
  59. #include <libavutil/imgutils.h>
  60. #include <SDL2/SDL.h>
  61. #ifdef __cplusplus
  62. };
  63. #endif
  64. #endif
  65. //Refresh Event
  66. #define SFM_REFRESH_EVENT  (SDL_USEREVENT + 1)
  67. #define SFM_BREAK_EVENT  (SDL_USEREVENT + 2)
  68. int thread_exit=0;
  69. int thread_pause=0;
  70. int sfp_refresh_thread(void *opaque){
  71. thread_exit=0;
  72. thread_pause=0;
  73. while (!thread_exit) {
  74. if(!thread_pause){
  75. SDL_Event event;
  76. event.type = SFM_REFRESH_EVENT;
  77. SDL_PushEvent(&event);
  78. }
  79. SDL_Delay(40);
  80. }
  81. thread_exit=0;
  82. thread_pause=0;
  83. //Break
  84. SDL_Event event;
  85. event.type = SFM_BREAK_EVENT;
  86. SDL_PushEvent(&event);
  87. return 0;
  88. }
  89. int main(int argc, char* argv[])
  90. {
  91. AVFormatContext *pFormatCtx;
  92. int             i, videoindex;
  93. AVCodecContext  *pCodecCtx;
  94. AVCodec         *pCodec;
  95. AVFrame *pFrame,*pFrameYUV;
  96. unsigned char *out_buffer;
  97. AVPacket *packet;
  98. int ret, got_picture;
  99. //------------SDL----------------
  100. int screen_w,screen_h;
  101. SDL_Window *screen;
  102. SDL_Renderer* sdlRenderer;
  103. SDL_Texture* sdlTexture;
  104. SDL_Rect sdlRect;
  105. SDL_Thread *video_tid;
  106. SDL_Event event;
  107. struct SwsContext *img_convert_ctx;
  108. //char filepath[]="bigbuckbunny_480x272.h265";
  109. char filepath[]="Titanic.ts";
  110. av_register_all();
  111. avformat_network_init();
  112. pFormatCtx = avformat_alloc_context();
  113. if(avformat_open_input(&pFormatCtx,filepath,NULL,NULL)!=0){
  114. printf("Couldn't open input stream.\n");
  115. return -1;
  116. }
  117. if(avformat_find_stream_info(pFormatCtx,NULL)<0){
  118. printf("Couldn't find stream information.\n");
  119. return -1;
  120. }
  121. videoindex=-1;
  122. for(i=0; i<pFormatCtx->nb_streams; i++)
  123. if(pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO){
  124. videoindex=i;
  125. break;
  126. }
  127. if(videoindex==-1){
  128. printf("Didn't find a video stream.\n");
  129. return -1;
  130. }
  131. pCodecCtx=pFormatCtx->streams[videoindex]->codec;
  132. pCodec=avcodec_find_decoder(pCodecCtx->codec_id);
  133. if(pCodec==NULL){
  134. printf("Codec not found.\n");
  135. return -1;
  136. }
  137. if(avcodec_open2(pCodecCtx, pCodec,NULL)<0){
  138. printf("Could not open codec.\n");
  139. return -1;
  140. }
  141. pFrame=av_frame_alloc();
  142. pFrameYUV=av_frame_alloc();
  143. out_buffer=(unsigned char *)av_malloc(av_image_get_buffer_size(AV_PIX_FMT_YUV420P,  pCodecCtx->width, pCodecCtx->height,1));
  144. av_image_fill_arrays(pFrameYUV->data, pFrameYUV->linesize,out_buffer,
  145. AV_PIX_FMT_YUV420P,pCodecCtx->width, pCodecCtx->height,1);
  146. //Output Info-----------------------------
  147. printf("---------------- File Information ---------------\n");
  148. av_dump_format(pFormatCtx,0,filepath,0);
  149. printf("-------------------------------------------------\n");
  150. img_convert_ctx = sws_getContext(pCodecCtx->width, pCodecCtx->height, pCodecCtx->pix_fmt,
  151. pCodecCtx->width, pCodecCtx->height, AV_PIX_FMT_YUV420P, SWS_BICUBIC, NULL, NULL, NULL);
  152. if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER)) {
  153. printf( "Could not initialize SDL - %s\n", SDL_GetError());
  154. return -1;
  155. }
  156. //SDL 2.0 Support for multiple windows
  157. screen_w = pCodecCtx->width;
  158. screen_h = pCodecCtx->height;
  159. screen = SDL_CreateWindow("Simplest ffmpeg player's Window", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
  160. screen_w, screen_h,SDL_WINDOW_OPENGL);
  161. if(!screen) {
  162. printf("SDL: could not create window - exiting:%s\n",SDL_GetError());
  163. return -1;
  164. }
  165. sdlRenderer = SDL_CreateRenderer(screen, -1, 0);
  166. //IYUV: Y + U + V  (3 planes)
  167. //YV12: Y + V + U  (3 planes)
  168. sdlTexture = SDL_CreateTexture(sdlRenderer, SDL_PIXELFORMAT_IYUV, SDL_TEXTUREACCESS_STREAMING,pCodecCtx->width,pCodecCtx->height);
  169. sdlRect.x=0;
  170. sdlRect.y=0;
  171. sdlRect.w=screen_w;
  172. sdlRect.h=screen_h;
  173. packet=(AVPacket *)av_malloc(sizeof(AVPacket));
  174. video_tid = SDL_CreateThread(sfp_refresh_thread,NULL,NULL);
  175. //------------SDL End------------
  176. //Event Loop
  177. for (;;) {
  178. //Wait
  179. SDL_WaitEvent(&event);
  180. if(event.type==SFM_REFRESH_EVENT){
  181. while(1){
  182. if(av_read_frame(pFormatCtx, packet)<0)
  183. thread_exit=1;
  184. if(packet->stream_index==videoindex)
  185. break;
  186. }
  187. ret = avcodec_decode_video2(pCodecCtx, pFrame, &got_picture, packet);
  188. if(ret < 0){
  189. printf("Decode Error.\n");
  190. return -1;
  191. }
  192. if(got_picture){
  193. sws_scale(img_convert_ctx, (const unsigned char* const*)pFrame->data, pFrame->linesize, 0, pCodecCtx->height, pFrameYUV->data, pFrameYUV->linesize);
  194. //SDL---------------------------
  195. SDL_UpdateTexture( sdlTexture, NULL, pFrameYUV->data[0], pFrameYUV->linesize[0] );
  196. SDL_RenderClear( sdlRenderer );
  197. //SDL_RenderCopy( sdlRenderer, sdlTexture, &sdlRect, &sdlRect );
  198. SDL_RenderCopy( sdlRenderer, sdlTexture, NULL, NULL);
  199. SDL_RenderPresent( sdlRenderer );
  200. //SDL End-----------------------
  201. }
  202. av_free_packet(packet);
  203. }else if(event.type==SDL_KEYDOWN){
  204. //Pause
  205. if(event.key.keysym.sym==SDLK_SPACE)
  206. thread_pause=!thread_pause;
  207. }else if(event.type==SDL_QUIT){
  208. thread_exit=1;
  209. }else if(event.type==SFM_BREAK_EVENT){
  210. break;
  211. }
  212. }
  213. sws_freeContext(img_convert_ctx);
  214. SDL_Quit();
  215. //--------------
  216. av_frame_free(&pFrameYUV);
  217. av_frame_free(&pFrame);
  218. avcodec_close(pCodecCtx);
  219. avformat_close_input(&pFormatCtx);
  220. return 0;
  221. }

运行结果

程序运行后,会在命令行窗口打印一些视频信息,同时会弹出一个窗口播放视频内容。

下载

CSDN完整工程下载地址:

http://download.csdn.net/detail/leixiaohua1020/7826277

更新(2014.10.5)==============================

版本升级至2.2。

1.新版本在原版本的基础上增加了“flush_decoder”功能。当av_read_frame()循环退出的时候,实际上解码器中可能还包含剩余的几帧数据。因此需要通过“flush_decoder”将这几帧数据输出。“flush_decoder”功能简而言之即直接调用avcodec_decode_video2()获得AVFrame,而不再向解码器传递AVPacket。参考代码如下:

[cpp] view plaincopy
  1. //FIX: Flush Frames remained in Codec
  2. while (1) {
  3. ret = avcodec_decode_video2(pCodecCtx, pFrame, &got_picture, packet);
  4. if (ret < 0)
  5. break;
  6. if (!got_picture)
  7. break;
  8. sws_scale(img_convert_ctx, (const uint8_t* const*)pFrame->data, pFrame->linesize, 0, pCodecCtx->height, pFrameYUV->data, pFrameYUV->linesize);
  9. //处理...
  10. }

2.为了更好地适应Linux等其他操作系统,做到可以跨平台,去除掉了VC特有的一些函数。比如“#include "stdafx.h"”,“_tmain()”等等。

具体信息参见文章:avcodec_decode_video2()解码视频后丢帧的问题解决

2.2版下载地址: http://download.csdn.net/detail/leixiaohua1020/8002337

更新-2.3(2015.1.03)==============================

新增一个工程:最简单的基于FFmpeg的解码器-纯净版(不包含libavformat)

2.3版CSDN下载地址: http://download.csdn.net/detail/leixiaohua1020/8322307

更新-2.4(2015.2.13)==============================

这次考虑到了跨平台的要求,调整了源代码。经过这次调整之后,源代码可以在以下平台编译通过:

VC++:打开sln文件即可编译,无需配置。

cl.exe:打开compile_cl.bat即可命令行下使用cl.exe进行编译,注意可能需要按照VC的安装路径调整脚本里面的参数。编译命令如下。

[plain] view plaincopy
  1. ::VS2010 Environment
  2. call "D:\Program Files\Microsoft Visual Studio 10.0\VC\vcvarsall.bat"
  3. ::include
  4. @set INCLUDE=include;%INCLUDE%
  5. ::lib
  6. @set LIB=lib;%LIB%
  7. ::compile and link
  8. cl simplest_ffmpeg_player.cpp /MD /link SDL2.lib SDL2main.lib avcodec.lib ^
  9. avformat.lib avutil.lib avdevice.lib avfilter.lib postproc.lib swresample.lib swscale.lib ^
  10. /SUBSYSTEM:WINDOWS /OPT:NOREF

MinGW:MinGW命令行下运行compile_mingw.sh即可使用MinGW的g++进行编译。编译命令如下。

[plain] view plaincopy
  1. g++ simplest_ffmpeg_player.cpp -g -o simplest_ffmpeg_player.exe \
  2. -I /usr/local/include -L /usr/local/lib \
  3. -lmingw32 -lSDL2main -lSDL2 -lavformat -lavcodec -lavutil -lswscale

GCC:Linux或者MacOS命令行下运行compile_gcc.sh即可使用GCC进行编译。编译命令如下。

[plain] view plaincopy
  1. gcc simplest_ffmpeg_player.cpp -g -o simplest_ffmpeg_player.out \
  2. -I /usr/local/include -L /usr/local/lib -lSDL2main -lSDL2 -lavformat -lavcodec -lavutil -lswscale

PS:相关的编译命令已经保存到了工程文件夹中

CSDN项目下载地址:http://download.csdn.net/detail/leixiaohua1020/8443943
SourceForge、Github等上面已经更新。
更新-2.5(2015.7.17)==============================
增加了下列工程:
simplest_ffmpeg_decoder:一个包含了封装格式处理功能的解码器。使用了libavcodec和libavformat。
simplest_video_play_sdl2:使用SDL2播放YUV的例子。
simplest_ffmpeg_helloworld:输出FFmpeg类库的信息。
CSDN项目下载地址:http://download.csdn.net/detail/leixiaohua1020/8924321
SourceForge、Github等上面已经更新。

最简单的基于FFMPEG+SDL的视频播放器 ver2 (采用SDL2.0)相关推荐

  1. 最简单的基于FFMPEG+SDL的视频播放器:拆分-解码器和播放器

    ===================================================== 最简单的基于FFmpeg的视频播放器系列文章列表: 100行代码实现最简单的基于FFMPEG ...

  2. 100行代码实现最简单的基于FFMPEG+SDL的视频播放器(SDL1.x)

    ===================================================== 最简单的基于FFmpeg的视频播放器系列文章列表: 100行代码实现最简单的基于FFMPEG ...

  3. 100行代码实现最简单的基于FFMPEG+SDL的视频播放器

    简介 FFMPEG工程浩大,可以参考的书籍又不是很多,因此很多刚学习FFMPEG的人常常感觉到无从下手.我刚接触FFMPEG的时候也感觉不知从何学起. 因此我把自己做项目过程中实现的一个非常简单的视频 ...

  4. 《基于 FFmpeg + SDL 的视频播放器的制作》课程的视频

    这两天开始带广播电视工程大二的暑假小学期的课程设计了.本次小学期课程内容为<基于 FFmpeg + SDL 的视频播放器的制作>,其中主要讲述了视音频开发的入门知识.由于感觉本课程的内容不 ...

  5. 基于 FFmpeg SDL 的视频播放器的制作 课程的视频

    分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow 也欢迎大家转载本篇文章.分享知识,造福人民,实现我们中华民族伟大复兴! 这两天开 ...

  6. 基于FFmpeg+SDL的视频播放器的制作-基础知识

    基础知识 目录 视频播放器原理 封装格式(MP4.RMVB.TS.FLV.AVI) 视频编码数据(H.264.MPEG2.VC-1) 音频编码数据(AAC.MP3.AC-3) 视频像素数据(YUV42 ...

  7. 最简单的基于FFMPEG+SDL的音频播放器 ver2 (采用SDL2.0)

    ===================================================== 最简单的基于FFmpeg的音频播放器系列文章列表: <最简单的基于FFMPEG+SDL ...

  8. 雷神FFmpeg + SDL 的视频播放器修正版

    雷神(雷霄桦)在FFmpeg + SDL 的视频播放器的代码中清晰地展示了作为一个播放器代码的思路.非常适合初学者学习借鉴. 雷神在"广播电视工程大二的暑假小学期的课程设计"中,课 ...

  9. 最简单的基于FFMPEG+SDL的音频播放器

    ===================================================== 最简单的基于FFmpeg的音频播放器系列文章列表: <最简单的基于FFMPEG+SDL ...

最新文章

  1. 当我们按下电源键,Android 究竟做了些什么?
  2. 【C语言】一文搞定如何计算结构体的大小----结构体内存对齐规则
  3. linux定时器回调处理过程,Linux内核系统定时器TIMER实现过程分析
  4. 大数据处理黑科技:揭秘PB级数仓GaussDB(DWS) 并行计算技术
  5. Jquery 中each循环嵌套的使用示例教程
  6. PDF文档阅读必备的PDF阅读器
  7. 亿乐社区一比一高仿源码全开源
  8. Geohot使用绿雨的BETA4越狱iPhone4 4.1固件详细教程
  9. (时频分析学习)Week01:傅里叶级数,S变换与广义S变换
  10. 计算机路由器无线级联配置,不同品牌无线路由器 无线级联 配置案例
  11. matlab ga工具箱 使用教程,MATLAB7.0 GA工具箱详细讲解及实例演示.pdf
  12. 弗吉尼亚大学计算机就业如何,假设你是新华中学的学生李华,高中毕业后想到美国弗吉尼亚大学(University of Virginia)计算机专业深造...
  13. kafka comsumer消费消息后不commit offset的情况分析
  14. 使用echarts的3D地图中的map3D与scatter3D混合使用时出现坐标位移的情况
  15. 自己动手做一个绿色便携版的谷歌浏览器Chrome,可以放入U盘随意带走的
  16. UG背景颜色修改和截图
  17. 怎么在阿里妈妈投放广告?--人人有责-- .
  18. 李笑来 css,CSS
  19. 32位计算机百度盘,【安装包】正版office_2010(win7专用【32位】)
  20. 专访寒武纪CEO陈天石:AI芯片是中国主导世界AI产业的机会

热门文章

  1. Hive的基本操作-分组和多表连接
  2. ES6新特性之let和const命令
  3. IDEA与tomcat相关配置
  4. Hystrix Health Indicator及Metrics Stream支持
  5. Bootstrap全局css样式_代码
  6. Spring-- ApplicationContext
  7. html追加datatype,jquery ajax中dataType的设置问题
  8. python不支持_为什么 Python 不支持函数重载?而其他语言大都支持?
  9. python组成不重复的三位数是多少_超星Python 练习实例1-组成多少个互不相同且无重复的三位数字...
  10. 计算机系统优化的目的和原理,优化原理