Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MediaFoundation, bitmap array to mp4

I hold bitmaps as BYTE arrays which holds RGB values of each pixel in a very similar and interchangeable format with microsoft's CBitmap class. So lets consider I have an array of CBitmaps and I want to convert them to mp4 with MediaFoundation Transcode Api as in this example: toMp4 . However in this example, they stream from an url.

 // Use the source resolver to create the media source
  hr = pResolver->CreateObjectFromURL(pszURL, MF_RESOLUTION_MEDIASOURCE, NULL, &ObjectType, &pSource);

In my case I have my bitmaps in the memory. So I believe I can use this function instead. IMFSourceResolver::CreateObjectFromByteStream

I am not sure if this is doable in this way. As a summary how can I convert my CBitmap arrays to mp4 with transcode api ?

like image 568
top secret Avatar asked Jun 16 '17 11:06

top secret


1 Answers

Transcoding API assumes that you have source and destination for the operation in certain "format" recognized by Media Foundation. That is, source and destination are both represented by Media Foundation sources and sinks, and then the API covers the process of converting one to another.

It is not the case of yours. Your source is not Media Foundation friendly.

For you scenario the appropriate API is Sink Writer. It offers a friendly interface to push non Media Foundation data into Media Foundation pipeline, and produces encoded video file by means of Media Foundation.

That is, you get bitmap bits from your images, you configure Sink Writer instance to accept such input format and then it takes care of the encoding.

See Tutorial: Using the Sink Writer to Encode Video for respective sample code and guidance through the process.

like image 87
Roman R. Avatar answered Oct 27 '22 02:10

Roman R.