[Libav-user] get RGB values from ffmpeg frame

Navin nkipe at tatapowersed.com
Mon Nov 26 14:57:11 CET 2012


Got the solution to my problem quite a while back. Posting it now as I 
have time. Hope it helps someone else. Like Carl said, it'd be best for 
a person to build the ffmpeg libraries by themselves.
I was using the 32bit dev builds from Zeranoe, and linking to the .lib 
files caused the compiler to ask for the corresponding DLL files too, 
but DLL's aren't part of the dev builds, so I had to take the DLL's of 
the shared build.
Using it this way, my ffmpeg code worked, but used to strangely crash at 
sws_scale.

But using purely the shared build's DLL's everything worked fine. Some 
example code for the RGB values:
//This example is from the updated tutorial 01: 
https://github.com/mpenkov/ffmpeg-tutorial
#include <Windows.h>
#include <libavformat/avformat.h>
#include <libavcodec/avcodec.h>//just as an example

int main()
{
    const char * avfDLLpointer = 
"F:\\Nav\\VisualStudio\\ffmpegTestProgram\\ffmpegTestProgram\\avformat-54.dll";//you 
can place this DLL in the same directory as your exe
    const char * avcDLLpointer = 
"F:\\Nav\\VisualStudio\\ffmpegTestProgram\\ffmpegTestProgram\\avcodec-54.dll";.//just 
as an example
    HINSTANCE hinstLib_avformat = LoadLibrary(avfDLLpointer);
    HINSTANCE hinstLib_avcodec  = LoadLibrary(avcDLLpointer);//just as 
an example
   __av_dump_format       av_dump_format_proc         = 
(__av_dump_format)        GetProcAddress(hinstLib_avformat, 
"av_dump_format");

...blah blah...
   sws_ctx = sws_getContext_proc(pCodecCtx->width, pCodecCtx->height, 
pCodecCtx->pix_fmt, pCodecCtx->width, pCodecCtx->height, PIX_FMT_RGB24, 
SWS_BILINEAR, NULL, NULL, NULL );
   avpicture_fill_proc((AVPicture *)pFrameRGB, buffer, PIX_FMT_RGB24, 
pCodecCtx->width, pCodecCtx->height);
...blah blah...
sws_scale_proc(sws_ctx, (uint8_t const * const *)pFrame->data, 
pFrame->linesize, 0, pCodecCtx->height, pFrameRGB->data, 
pFrameRGB->linesize );
             for(int yy = 0; yy < pCodecCtx->height; ++yy)
             {
                 for(int xx = 0; xx < pCodecCtx->width; ++xx)
                 {
                     int p = xx * 3 + yy * pFrameRGB->linesize[0];
                     int r = pFrameRGB->data[0][p];
                     int g = pFrameRGB->data[0][p+1];
                     int b = pFrameRGB->data[0][p+2];
                 }
             }
...blah blah...
}


Navin

On 11/22/2012 4:32 AM, Carl Eugen Hoyos wrote:
> Malik Cissé<mc at ...>  writes:
>
>> Carl Eugen ... writes:
>>> ...compile FFmpeg with msvc.
>> This sounds interesting. Where can I find msvc sample project?
> Please see the MSVC section on the platform page
> of the fine documentation to find information on
> how to compile FFmpeg with MSVC.
>
> Carl Eugen
>
> _______________________________________________
> Libav-user mailing list
> Libav-user at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/libav-user
>
>


More information about the Libav-user mailing list