Page 1 of 1

H264 Pro Recorder & SDK

PostPosted: Wed Feb 11, 2015 6:02 pm
by Nicolas Galinotti
Hi is it possible to control the H264 pro recorder with any of the BlackMagic SDKS ?
I simply need to start/stop the recording and specify the output file location from inside another application on a windows machine.

Re: H264 Pro Recorder & SDK

PostPosted: Fri Feb 13, 2015 1:18 am
by Matt Jefferson
Yes, the Desktop Video SDK has two sections. The first is our uncompressed capture and playback devices called Decklink, Ultrastudio and Intensity.

The second section (page 229 of manual) supports the H264 to able to control that H264 hardware solution programmatically. The SDK can be found by going to the support page select capture and playback driver area on lower left section along with the drivers needed for boards.

Matt Jefferson

Re: H264 Pro Recorder & SDK

PostPosted: Mon Feb 16, 2015 1:26 pm
by Nicolas Galinotti
Hi Matt.
Thanks for your answer

Re: H264 Pro Recorder & SDK

PostPosted: Sat May 30, 2015 4:50 pm
by Nicolas Galinotti
I'm trying to modify the StreamingPreview sample on Windows to create an MP4 file from the H264 IMMediaSamples generated in the DecoderMF::DoProcessInputNal(...) but I'm not able to generate a valid MP4 file, its size is always 0 or a few KB.

Do you have some piece of code that you could share ?

Re: H264 Pro Recorder & SDK

PostPosted: Wed Jun 03, 2015 5:15 pm
by Matt Jefferson
Nicolas -
I sent you a PM about this issue for the windows sample program and sample code for streaming preview for the H264 Pro Recoder.

thanks again.
Matt Jefferson

Re: H264 Pro Recorder & SDK

PostPosted: Fri May 27, 2016 10:00 am
by Vincent Guigue

I am also trying to use the SDK to capture those IBMDStreamingH264NALPacket and send them to a file on my computer, not sure how to do it though.
I would be interested too by some help about how this works, mayby by modifying the "StreamingPreview" sample.

Thanks in advance,

Re: H264 Pro Recorder & SDK

PostPosted: Sun May 29, 2016 11:49 pm
by Nicholas Gill
Hi Vincent,

The DeckLink Streaming API provides audio and video encapsulated in MPEG2-TS packets as an option, which may be written directly to disk and interpreted as a valid MPEG2-TS stream.

With reference to the StreamingPreview sample (Windows version in this example), CStreamingPreviewDlg::MPEG2TSPacketArrived[1] implements this method from the IBMDStreamingH264InputCallback interface.

Within this method, call GetBytes[2] on the IBMDStreamingMPEG2TSPacket[3] parameter, to receive a pointer to the MPEG2TS packet buffer. Append the captured MPEG2TS packet to a file (e.g. <capture_filename>.ts).

Writing the encoded H.264 video (+ audio) to other container formats (mp4, avi, etc.) is outside of the scope of what is provided by the DeckLink API; the application will need to implement / integrate code for that purpose - the H264NALPacketArrived[4] and H264AudioPacketArrived[5] methods are likely to be more suitable for that purpose.



[1] IBMDStreamingH264InputCallback::MPEG2TSPacketArrived method
[2] IBMDStreamingMPEG2TSPacket::GetBytes method
[3] 2.6.10 IBMDStreamingMPEG2TSPacket Interface
[4] IBMDStreamingH264InputCallback::H264NALPacketArrived method
[5] IBMDStreamingH264InputCallback::H264AudioPacketArrived method

Re: H264 Pro Recorder & SDK

PostPosted: Thu Jun 16, 2016 4:10 am
by Aditya Kadambi
Hi Matt,

Can you send me the sample code for previewing the H.264 video? I am looking to buy the recorder. Just want to make sure I can get H.264 video samples that I can write to my mp4 container.

Re: H264 Pro Recorder & SDK

PostPosted: Fri Jun 17, 2016 12:53 am
by Nicholas Gill
Hi Aditya,

The StreamingPreview sample mentioned is included in the DeckLink API, which is freely available from the Blackmagic Design Support page, in the "Capture and Playback"[1] section.

Within the SDK package, the Windows StreamingPreview sample is contained in the path Win\Samples\Streaming\StreamingPreview\

Just to clarify regarding 'mp4 container', please note that the Streaming API subset of the DeckLink API provides access to the encoded H.264 data as raw NAL packets and audio, or optionally encapsulated within MPEG2 Transport Stream packets.

The DeckLink API does not provide interfaces for file io nor video container formats (e.g. mp4). If that is a requirement the application will need to implement / integrate code to write the H.264 encoded NAL units into the desired video container format.




Re: H264 Pro Recorder & SDK

PostPosted: Fri Jun 17, 2016 2:50 am
by Aditya Kadambi
Hi Nicholas,


I want the raw H.264 packets. I already have my own container code (using Windows Media Foundation) that I can utilize to write to my mp4 container.


Re: H264 Pro Recorder & SDK

PostPosted: Wed Jul 27, 2016 2:05 pm
by Carlo Gambirasio

I'm trying to save a h264/mp4 with data in H264NALPacketArrived() using Microsoft Media Foundation, but file has always 0 length:

// Get a pointer to the NAL data

// Create the MF media buffer
MFCreateMemoryBuffer(nalPacket->GetPayloadSize(), &newBuffer);

// Lock the MF media buffer
newBuffer->Lock(&newBufferPtr, NULL, NULL);

// Copy the data
memcpy(newBufferPtr, nalPacketPtr, nalPacket->GetPayloadSize());

// Unlock the MF media buffer

// Update the current length of the MF media buffer
hr = newBuffer->SetCurrentLength(nalPacket->GetPayloadSize());

// construct a IMFSample with the buffer


// Send the sample to the Sink Writer.
sinkWriter->WriteSample(curStreamIndex, newSample);

anybody can provide a valid sample ?

thank you

Re: H264 Pro Recorder & SDK

PostPosted: Fri May 19, 2017 9:21 am
by Martin Kibsgaard
In case someone finds this thread and just needs to save the encoded video to a file, here's a code example that does what Nicholas Gill suggested.

First you need to create a File Handle. Somewhere in the StreamingPreviewDlg.h header file add this:
Code: Select all
HANDLE FileHandle;

Somewhere in the initialization code (e.g. in StreamingDeviceArrived()) add:
Code: Select all
FileHandle = CreateFile("C:\\Users\\DeckLinkUser\\Videos\\test1.ts", FILE_APPEND_DATA, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
//Change the path to somewhere the application is allowed to write.

Replace the MPEG2TSPacketArrived-function with this:
Code: Select all
HRESULT CStreamingPreviewDlg::MPEG2TSPacketArrived(IBMDStreamingMPEG2TSPacket* mpeg2TSPacket)
   void* inputBuffer;
   mpeg2TSPacket->GetBytes(&inputBuffer);            //Get a pointer to the new MPEG2TS packet
   int bufferSize = mpeg2TSPacket->GetPayloadSize();   //Get the size of the packet
   DWORD dwBytesWritten;

   WriteFile(FileHandle, inputBuffer, bufferSize, &dwBytesWritten, NULL); //Write the data from the packet to a file

   ASSERT(bufferSize == dwBytesWritten);            //Check if all bytes were written to the file. If the program breaks here, the program most likely doesn't have write access to the file location. TODO: recover from failed write?
   return S_OK;

Close the File Handle in the OnClose()-function:
Code: Select all
if (FileHandle) {
   FileHandle = NULL;

Hope this can help someone. @Carlo, did you ever resolve your issue using Media Foundation?