0

My application plays video via SDL + ffmpeg library(not the exe tool).

and I want to add the text onto the video

The ffmpeg's VHOOK source code shows it converts the data to RGB32. Can't it be done in YUV directly?

Here my current code, can you please give me some suggestion?

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);
}
Mr.Wang from Next Door
  • 10,685
  • 10
  • 47
  • 76

1 Answers1

1

Yes you can just write foreach loop to loop over YUV pixels(YUV is basically brightness+chroma), you need little processing to turn RGB data(watermark image) into YUV and combine them. It wont be that hard but you need to understand how to blend and convert rgb to yuv420p.

Erti-Chris Eelmaa
  • 22,879
  • 5
  • 54
  • 76