我在分析网上大神的博客后使用ffmpeg + sdl 成功地播放了h264数据,所以做了下面的记录.
解码h264数据为yuv240p
1
2
3
4 ffmpeg 头文件
1
2
3
4
5
6
7
8
9
10 AVFormatContext *pFormatCtx;
int i, videoindex;
AVCodecContext *pCodecCtx;
AVCodec *pCodec;
AVFrame *pFrame, *pFrameYUV;
uint8_t *out_buffer;
AVPacket *packet;
int y_size;
int ret, got_picture;
struct SwsContext *img_convert_ctx;
创建这些变量,结构体
1 | //注册ffmpeg编解码器 |
1 | if (avformat_open_input(&pFormatCtx, filepath, NULL, NULL) != 0) { |
1 | pFrame = av_frame_alloc(); //初始化 |
1 | while (av_read_frame(pFormatCtx, packet) >= 0) { |
SDL
初始化SDL
1 | if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER)) { |
1 | SDL_UpdateYUVTexture(sdlTexture, &sdlRect, |
1 | //最后将所有的资源释放掉 |
tips
在编译完成后,我点击运行,没有什么反应,但是我点击生成的exe却可以执行
当时我觉得很奇怪,在试错之后明白了,是filepath[]的问题,编译的是cpp的路径,
执行的exe在Debug下面,它们不一样.
感觉这是不人性化的设置