[Libav-user] get RGB values from ffmpeg frame
Navin
nkipe at tatapowersed.com
Mon Nov 26 15:19:23 CET 2012
Sorry, the correct code (with the necessary typedefs) is as such:
#include <Windows.h>
#include <libavformat/avformat.h>
#include <libavcodec/avcodec.h>
#include <libswscale/swscale.h>
typedef SwsContext* (__cdecl *__sws_getContext)(int srcW, int srcH, enum
AVPixelFormat srcFormat, int dstW, int dstH, enum AVPixelFormat
dstFormat, int flags, SwsFilter *srcFilter, SwsFilter *dstFilter, const
double *param);
typedef int (__cdecl *__sws_scale)(struct SwsContext *c, const uint8_t
*const srcSlice[], const int srcStride[], int srcSliceY, int srcSliceH,
uint8_t *const dst[], const int dstStride[]);
typedef int (__cdecl *__avpicture_fill)(AVPicture *picture, uint8_t
*ptr, enum AVPixelFormat pix_fmt, int width, int height);
int main()
{
const char * swsDLLpointer =
"F:\\Nav\\VisualStudio\\ffmpegTestProgram\\ffmpegTestProgram\\swscale-2.dll";
const char * avcDLLpointer =
"F:\\Nav\\VisualStudio\\ffmpegTestProgram\\ffmpegTestProgram\\avcodec-54.dll";
HINSTANCE hinstLib_swscale = LoadLibrary(swsDLLpointer);
HINSTANCE hinstLib_avcodec = LoadLibrary(avcDLLpointer);
__avpicture_fill avpicture_fill_proc =
(__avpicture_fill) GetProcAddress(hinstLib_avcodec,
"avpicture_fill");
__sws_getContext sws_getContext_proc =
(__sws_getContext) GetProcAddress(hinstLib_swscale,
"sws_getContext");
__sws_scale sws_scale_proc =
(__sws_scale) GetProcAddress(hinstLib_swscale, "sws_scale");
...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...
}
It's basically that simple to get RGB values.
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