ms media foundation - How to create IMFSample for WindowsMediaFoundation H.264 encoder MFT -


i'm learning use h.264 encoder in windows media foundation.

what have media samples in yuv420p format, that's buffers containing yyyyyyyyuuvv data.

since h.264 encoder mft requires input in form of imfsample, i'm not sure how convert data in buffer imfsample.

may this:

imfmediabuffer *pbuffer = null; mfcreatememorybuffer(cbsize, &pbuffer); byte *pdata = null; pbuffer->lock(&pdata, null, null); memcpy(pdata, bufferihaveinyyyyuv format, buffer size); // correct? pbuffer->unlock(); imfsample *psample = null; mfcreatesample(&psample); psample->addbuffer(pbuffer); 

thanks

this how (full example @ https://github.com/sipsorcery/mediafoundationsamples/blob/master/mfmp4toyuvwithmft/mfmp4toyuvwithmft.cpp):

imfmediabuffer *srcbuf = null; dword srcbuflength; byte *srcbytebuffer; dword srcbuffcurrlen = 0; dword srcbuffmaxlen = 0; check_hr(videosample->converttocontiguousbuffer(&srcbuf), "converttocontiguousbuffer failed.\n"); check_hr(srcbuf->getcurrentlength(&srcbuflength), "get buffer length failed.\n"); check_hr(srcbuf->lock(&srcbytebuffer, &srcbuffmaxlen, &srcbuffcurrlen), "error locking source buffer.\n");  //// re-constuct. mfcreatesample(&reconstructedvideosample); check_hr(mfcreatememorybuffer(srcbuflength, &reconstructedbuffer), "failed create memory buffer.\n"); check_hr(reconstructedvideosample->addbuffer(reconstructedbuffer), "failed add buffer re-constructed sample.\n"); check_hr(reconstructedvideosample->setsampletime(llvideotimestamp), "error setting recon video sample time.\n"); check_hr(reconstructedvideosample->setsampleduration(llsampleduration), "error setting recon video sample duration.\n");  byte *reconbytebuffer; dword reconbuffcurrlen = 0; dword reconbuffmaxlen = 0; check_hr(reconstructedbuffer->lock(&reconbytebuffer, &reconbuffmaxlen, &reconbuffcurrlen), "error locking recon buffer.\n"); memcpy(reconbytebuffer, srcbytebuffer, srcbuffcurrlen); check_hr(reconstructedbuffer->unlock(), "error unlocking recon buffer.\n"); reconstructedbuffer->setcurrentlength(srcbuffcurrlen); 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -