H264 Pro Recorder & SDK

Ask software engineering and SDK questions for developers working on Mac OS X, Windows or Linux.
  • Author
  • Message
Offline

Nicolas Galinotti

  • Posts: 3
  • Joined: Wed Feb 11, 2015 5:56 pm

H264 Pro Recorder & SDK

PostWed Feb 11, 2015 6:02 pm

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.
Offline

Matt Jefferson

Blackmagic Design

  • Posts: 130
  • Joined: Fri Aug 31, 2012 12:50 am

Re: H264 Pro Recorder & SDK

PostFri Feb 13, 2015 1:18 am

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
Offline

Nicolas Galinotti

  • Posts: 3
  • Joined: Wed Feb 11, 2015 5:56 pm

Re: H264 Pro Recorder & SDK

PostMon Feb 16, 2015 1:26 pm

Hi Matt.
Thanks for your answer
Regards,
Nicolas.
Offline

Nicolas Galinotti

  • Posts: 3
  • Joined: Wed Feb 11, 2015 5:56 pm

Re: H264 Pro Recorder & SDK

PostSat May 30, 2015 4:50 pm

Hi,
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 ?
Offline

Matt Jefferson

Blackmagic Design

  • Posts: 130
  • Joined: Fri Aug 31, 2012 12:50 am

Re: H264 Pro Recorder & SDK

PostWed Jun 03, 2015 5:15 pm

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
Offline

Vincent Guigue

  • Posts: 4
  • Joined: Tue May 10, 2016 4:25 pm

Re: H264 Pro Recorder & SDK

PostFri May 27, 2016 10:00 am

Hi

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,
Vincent
Offline

Nicholas Gill

Blackmagic Design

  • Posts: 169
  • Joined: Mon May 04, 2015 10:28 pm

Re: H264 Pro Recorder & SDK

PostSun May 29, 2016 11:49 pm

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.

Cheers,

-nick

[1] 2.6.7.3 IBMDStreamingH264InputCallback::MPEG2TSPacketArrived method
[2] 2.6.10.2 IBMDStreamingMPEG2TSPacket::GetBytes method
[3] 2.6.10 IBMDStreamingMPEG2TSPacket Interface
[4] 2.6.7.1 IBMDStreamingH264InputCallback::H264NALPacketArrived method
[5] 2.6.7.2 IBMDStreamingH264InputCallback::H264AudioPacketArrived method
Offline

Aditya Kadambi

  • Posts: 14
  • Joined: Tue Jun 30, 2015 10:32 am

Re: H264 Pro Recorder & SDK

PostThu Jun 16, 2016 4:10 am

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.
Offline

Nicholas Gill

Blackmagic Design

  • Posts: 169
  • Joined: Mon May 04, 2015 10:28 pm

Re: H264 Pro Recorder & SDK

PostFri Jun 17, 2016 12:53 am

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.

Cheers,

-nick

[1] https://www.blackmagicdesign.com/au/support/family/capture-and-playback
Offline

Aditya Kadambi

  • Posts: 14
  • Joined: Tue Jun 30, 2015 10:32 am

Re: H264 Pro Recorder & SDK

PostFri Jun 17, 2016 2:50 am

Hi Nicholas,

Excellent.

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.

-Aditya
Offline

Carlo Gambirasio

  • Posts: 1
  • Joined: Wed Jul 27, 2016 1:43 pm

Re: H264 Pro Recorder & SDK

PostWed Jul 27, 2016 2:05 pm

Hello,

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
nalPacket->GetBytes(&nalPacketPtr);

// 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
newBuffer->Unlock();

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

// construct a IMFSample with the buffer
MFCreateSample(&newSample);

newSample->AddBuffer(newBuffer);

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

anybody can provide a valid sample ?

thank you
Offline

Martin Kibsgaard

  • Posts: 4
  • Joined: Wed Jul 02, 2014 1:00 pm

Re: H264 Pro Recorder & SDK

PostFri May 19, 2017 9:21 am

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) {
   CloseHandle(FileHandle);
   FileHandle = NULL;
}


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

Return to Software Developers

Who is online

Users browsing this forum: No registered users and 2 guests