【FFmpeg】SDL音视频渲染

1 SDL编译和安装

下载源码:SDL2-2.0.14.tar.gz

tar -zvxf SDL2-2.0.14.tar.gz
cd SDL2-2.0.14
./configure --prefix=/usr/local 
sudo make -j 8 && make install

2 SDL使用基本步骤

添加头文件:#include<SDL.h>
初始化SDL
退出SDL

SDL渲染窗口

SDL_Init()  / SDL_Quit()
SDL_CreateWindow() / SDL_DestoryWindow()
SDL_CreateRender()

最简单的sdl程序:

#include

int main(int argc, char **argv){
	SDL_Init(SDL_INIT_VIDEO);
	SDL_Quit();
	return 0;
}

编译运行:
结果就是毫无反应,因为并没有创建窗口。

clang -g -o firstsdl firstsdl.c `pkg-config --cflags --libs sdl2`
./firstsdl

创建一个窗口,但是暂时不渲染:

#include
#include
int main(int argc, char **argv){

	SDL_Window *window = NULL;
	SDL_Init(SDL_INIT_VIDEO);
	
	window = SDL_CreateWindow(  "SDL2 Window", 
						200, 200, 640, 480, 
						SDL_WINDOW_SHOWN);
	if(!window){
		printf("Faild to Create window!");
		goto __EXIT;
	}
	
	SDL_DestroyWindow(window);
__EXIT:
	SDL_Quit();
	return 0;
}

同样的方法编译运行,发现还是毫无反应,因为没有将窗口渲染到屏幕上。
创建窗口只是在内存中分配了一段空间,如果想将内容显示在显示器上,要将内容推到显卡驱动上,显卡通过驱动程序推到显示器去。

3 SDL渲染窗口

SDL_CreateRenderer() / SDL_DestroyRenderer()

SDL_RenderClear()

SDL_RenderPresent()
#include
#include
int main(int argc, char **argv){

	SDL_Window *window = NULL;
    SDL_Renderer *render = NULL;
	SDL_Init(SDL_INIT_VIDEO);
	
	window = SDL_CreateWindow(  "SDL2 Window", 
						200, 200, 640, 480, 
						SDL_WINDOW_SHOWN);
	if(!window){
		printf("Faild to Create window!");
		goto __EXIT;
	}
	
    render = SDL_CreateRenderer(window, -1, 0);
    if(!render){
        SDL_Log("Failed to Create Render!");
        goto __DWINDOW;
    }
    
    SDL_SetRenderDrawColor(render, 255, 0, 0, 255);
    
    SDL_RenderClear(render);
    
    SDL_RenderPresent(render);
    
    SDL_Delay(30000);
    
__DWINDOW:
    SDL_DestroyWindow(window);
    
__EXIT:
	SDL_Quit();
	return 0;
}

你可能感兴趣的:(音视频)