初入ffmpeg。跑个demo压压惊
一、软件环境环境:
Ubuntu 14.04.4
ffmpeg 4.2.2
SDL 2.0.12
二、参考文章
1、https://blog.csdn.net/leixiaohua1020/article/details/38868499
2、https://blog.csdn.net/ashqal/article/details/17640179
3、https://www.cnblogs.com/lifan3a/articles/6944157.html
三、流程
ffmpeg流程
SDL流程
源码整理
#include <stdio.h>
#include <stdlib.h>
#ifdef __cplusplus
extern"C"
{
#endif
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libswscale/swscale.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_thread.h>
#ifdef __cplusplus
}
#endif
//#define SDL_VERSION_1 //version:1->SDL1.2 0->SDL2.0
//Refresh
#define SFM_REFRESH_EVENT (SDL_USEREVENT + 1)
int thread_exit=0;
//Thread
int sfp_refresh_thread(void *opaque)
{
SDL_Event event;
while (thread_exit==0)
{
event.type = SFM_REFRESH_EVENT;
SDL_PushEvent(&event);
//Wait 40 ms
SDL_Delay(40);
}
return 0;
}
int main(int argc, char *argv[])
{
AVFormatContext *pFormatCtx; //视频上下文
AVCodecContext *pCodecCtx; //解码上下文
int i, videoindex;
AVCodec *pCodec;
AVFrame *pFrame,*pFrameYUV;
AVPacket *packet;
struct SwsContext *img_convert_ctx;
//SDL
int ret, got_picture;
int screen_w=0,screen_h=0;
#if defined(SDL_VERSION_1)
SDL_Surface *screen;
SDL_Overlay *bmp;
#else
SDL_Texture *bmp = NULL;
SDL_Window *screen = NULL;
SDL_Renderer *renderer = NULL;
#endif
SDL_Rect rect;
SDL_Thread *video_tid;
SDL_Event event;
int numBytes;
uint8_t* buffer;
if(1 == argc)
{
printf("%s:%d parameter error \n", __func__, __LINE__);
return -1;
}
//------------