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?