美文网首页
sdl 绘制 yuv视频

sdl 绘制 yuv视频

作者: shuinan | 来源:发表于2019-08-22 11:58 被阅读0次

    sdl提供跨平台的视频绘制,功能很强大,还一直保持更新,很不错,下面时相关介绍。

    https://blog.csdn.net/leixiaohua1020/article/details/38868499 最简单的基于FFMPEG+SDL的视频播放器 

    利用他在指定的窗口上绘制,很方便

    不过,我们还需要在保持图像本身的比例不变下,提供两种绘制模式: 

    1. 填满绘制窗口;

    2. 显示全部图形,窗口空余部分保持底色

    在指定的窗口中绘制,调用这个:SDL_CreateWindowFrom

    sdl支持多种格式的图像: 多种yuv  多种 rgb, 有相关的配套接口,上面的例子中也有介绍。

    不过,绘制方式还是有些麻烦。

    sdl缺省方式,会自动拉伸图像、填满窗口。 试验了SDL_SetHint几个参数,没感觉到效果。

    另外发现sdl提供类似opengl的设置viewport和scale,

    SDL_RenderSetViewport(m_renderer, &rect);

    SDL_RenderSetScale(m_renderer, r, r);

    但是在sdl本身的拉伸作用下,不见效。

    看来需要利用填写数据函数了SDL_RenderCopyEx,这个函数可以设置绘制区域和提供的图像区域,如下,目标达到。

    int winWidth, winHeight;

    SDL_GetWindowSize(m_window, &winWidth, &winHeight);

    float wScale = (float)winWidth / (float)m_lastWidth;

    float hScale = (float)winHeight / (float)m_lastHeight;

    SDL_Rect winRect, imageRect;

    SDL_Rect* ptrWinRect = nullptr;

    SDL_Rect* ptrImageRect = nullptr;

    if (m_renderMode == xrtc::RENDER_MODE_FIT) {

    float r = MIN_(wScale, hScale);

    // clip window to fit image

    winRect.h = r * m_lastHeight;

    winRect.w = r * m_lastWidth;

    winRect.x = (int)(winWidth - winRect.w) / 2;

    winRect.y = (int)(winHeight - winRect.h) / 2;

    ptrWinRect = &winRect;

    }

    else {

    // clip image to fit window

    float r = MIN_(1 / wScale, 1 / hScale);

    imageRect.h = r * winHeight;

    imageRect.w = r * winWidth;

    imageRect.x = (int)(m_lastWidth - imageRect.w) / 2;

    imageRect.y = (int)(m_lastHeight - imageRect.h) / 2;

    ptrImageRect = &imageRect;

    }

    SDL_RenderCopyEx(m_renderer, m_texture, ptrImageRect, ptrWinRect, 0, nullptr, SDL_FLIP_NONE);

    相关文章

      网友评论

          本文标题:sdl 绘制 yuv视频

          本文链接:https://www.haomeiwen.com/subject/mlqnsctx.html