SDL 紋理與FFmpeg的解碼格式對應
BGRA ==> SDL_PIXELFORMAT_ARGB8888
RGB24 ==> SDL_PIXELFORMAT_RGB888
BGR24 ==> SDL_PIXELFORMAT_BGR888
YUV420P ==> SDL_PIXELFORMAT_IYUV
BGR24和RGB24解碼後需要轉32bit 才能夠被SDL_UpdateTexture()讀取到紋理資料
24to32代碼
void CONVERT_24to32 (unsigned char *image_in, unsigned char *image_out, int w, int h)
{
for (int i = 0; i < h; i++)
{
for (int j = 0; j < w; j++)
{
if (SDL_BYTEORDER == SDL_LIL_ENDIAN)
{
image_out[(i * w + j) * 4 + 0] = image_in[(i * w + j) * 3 + 2];
image_out[(i * w + j) * 4 + 1] = image_in[(i * w + j) * 3 + 1];
image_out[(i * w + j) * 4 + 2] = image_in[(i * w + j) * 3 + 0];
image_out[(i * w + j) * 4 + 3] = '0';
}
else
{
image_out[(i * w + j) * 4] = 0;
memcpy(image_out + (i * w + j) * 4 + 1, image_in + (i * w + j) * 3, 3);
}
}
}
}
SDL播放視訊流程
1 初始化
2 循環顯示畫面
參考:
https://blog.csdn.net/leixiaohua1020/article/details/40525591