How to convert RGB from YUV420p for ffmpeg encoder? -


i want make .avi video file bitmap images using c++ code. wrote following code:

//get rgb array data bmp file uint8_t* rgb24data = new uint8_t[3*imgwidth*imgheight]; hbitmap = (hbitmap) loadimage( null, _t("myfile.bmp"), image_bitmap, 0, 0, lr_loadfromfile); getdibits(hdc, hbitmap, 0, imgheight, rgb24data , (bitmapinfo*)&bmi, dib_rgb_colors);  /* allocate encoded raw picture. */ avpicture dst_picture; avpicture_alloc(&dst_picture, av_pix_fmt_yuv420p, imgwidth, imgheight);  /* convert rgb24data yuv420p , stored array dst_picture.data */ rgb24toyuv420p(imgwidth, imgheight, rgb24data, dst_picture.data); //how implement function?  //code encode frame dst_picture here 

my problem how implement rgb24toyuv420p() function, function convert rgb24 data array rgb24data yuv420p , store array dst_picture.data ffmpeg encoder?

you can use swscale

something this:

#include <libswscale/swscale.h> swscontext * ctx = sws_getcontext(imgwidth, imgheight,                                   av_pix_fmt_rgb24, imgwidth, imgheight,                                   av_pix_fmt_yuv420p, 0, 0, 0, 0); uint8_t * indata[1] = { rgb24data }; // rgb24 have 1 plane int inlinesize[1] = { 3*imgwidth }; // rgb stride sws_scale(ctx, indata, inlinesize, 0, imgheight, dst_picture.data, dst_picture.linesize) 

note should create instance of swscontext object once, not each frame.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -