2012-09-02 24 views
0

我的应用程序通过SDL + ffmpeg库(不是exe工具)播放视频。通过程序对YUV视频数据(SDL_Overlay)执行Sdd水印

,我想给文本添加到视频

的FFmpeg的VHOOK source code显示它的数据转换为RGB32。 不能直接在YUV中完成吗?

在这里我现在的代码,你能给我一些建议吗?

SDL_Overlay * pOverlay = SDL_CreateYUVOverlay(pDecodedFrame->width 
      , pDecodedFrame->height 
      , SDL_YV12_OVERLAY 
      , pThis->m_pSurface 
      ); 
if(pOverlay != NULL) 
{ 
    SDL_LockYUVOverlay(pOverlay); 

    pSwsContext = sws_getCachedContext(pSwsContext 
     , pDecodedFrame->width 
     , pDecodedFrame->height 
     , pThis->m_pMediaFile->GetVideoPixcelFormat() 
     , pDecodedFrame->width 
     , pDecodedFrame->height 
     , PIX_FMT_YUV420P 
     , SWS_SPLINE 
     , NULL 
     , NULL 
     , NULL 
     ); 

    AVPicture tPicture; 
    tPicture.data[0] = pOverlay->pixels[0]; 
    tPicture.data[1] = pOverlay->pixels[2]; 
    tPicture.data[2] = pOverlay->pixels[1]; 

    tPicture.linesize[0] = pOverlay->pitches[0]; 
    tPicture.linesize[1] = pOverlay->pitches[2]; 
    tPicture.linesize[2] = pOverlay->pitches[1]; 

    int nSliceHeight = sws_scale(pSwsContext 
     , pDecodedFrame->data 
     , pDecodedFrame->linesize 
     , 0 
     , pDecodedFrame->height 
     , tPicture.data 
     , tPicture.linesize 
     ); 


    SDL_UnlockYUVOverlay(pOverlay); 
    VideoPicture tVideoPicture = {0}; 
    tVideoPicture.pOverlay = pOverlay; 
    tVideoPicture.nWidth = pDecodedFrame->width; 
    tVideoPicture.nHeight = pDecodedFrame->height; 
    tVideoPicture.dbPTS = dbPTS; 

    pThis->m_pVideoPictureQueue.Append(tVideoPicture); 
} 

回答

1

是的,你可以只写foreach循环遍历YUV像素(YUV基本上亮度色度+),你需要一点处理把RGB数据(水印图像)转换成YUV和将它们结合起来。它不会那么难,但你需要了解如何混合和转换rgb到yuv420p。