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