Skip to content

Commit

Permalink
MkvWriter UYVY integration
Browse files Browse the repository at this point in the history
Signed-off-by: Maxime Gervais <[email protected]>
  • Loading branch information
g-maxime committed Jun 7, 2024
1 parent 39a82c1 commit 059991b
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 27 deletions.
10 changes: 10 additions & 0 deletions Source/Common/Output_Mkv.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@
#include "Common/ProcessFileWrapper.h"
#include "ThirdParty/TimeCode/TimeCode.h"

//***************************************************************************
//enums
//***************************************************************************

enum video_format
{
v210,
UYVY,
};

//***************************************************************************
// Class matroska_writer
//***************************************************************************
Expand Down
3 changes: 1 addition & 2 deletions Source/Common/ProcessFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,15 +417,14 @@ void file::Parse(const String& FileName)
#if defined(ENABLE_SIMULATOR) || defined(ENABLE_DECKLINK)
if (CaptureMode == Capture_Mode_DeckLink)
{
video_format VideoFormat = v210;
uint32_t Width = 720;
uint32_t Height = DeckLinkVideoMode == Decklink_Video_Mode_NTSC ? 486 : 576;
uint32_t Num = DeckLinkVideoMode == Decklink_Video_Mode_NTSC ? 30000 : 25;
uint32_t Den = DeckLinkVideoMode == Decklink_Video_Mode_NTSC ? 1001 : 1;
uint32_t SampleRate = 48000;
uint8_t Channels = 2;

Wrapper = new FileWrapper(VideoFormat, Width, Height, Num, Den, SampleRate, Channels, DeckLinkTimecodeFormat<Decklink_Timecode_Format_Max);
Wrapper = new FileWrapper(Width, Height, Num, Den, SampleRate, Channels, DeckLinkTimecodeFormat<Decklink_Timecode_Format_Max);
}
else
#endif
Expand Down
36 changes: 22 additions & 14 deletions Source/Common/ProcessFileWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,10 @@ FileWrapper::FileWrapper(file* File) : File(File)

//---------------------------------------------------------------------------
#if defined(ENABLE_DECKLINK) || defined(ENABLE_SIMULATOR)
FileWrapper::FileWrapper(video_format vid_fmt, int Width, int Height, int Framerate_Num, int Framerate_Den, int SampleRate, int Channels, bool Has_Timecode) : File(nullptr)
FileWrapper::FileWrapper(int Width, int Height, int Framerate_Num, int Framerate_Den, int SampleRate, int Channels, bool Has_Timecode) : File(nullptr)
{
IsMatroska = true;
for (string OutputFile : Merge_OutputFileNames)
{
matroska_output Output;
if (OutputFile == "-")
Output.Writer = new matroska_writer(&cout, vid_fmt, Width, Height, Framerate_Num, Framerate_Den, Has_Timecode);
else
{
Output.Output = new ofstream(OutputFile, ios_base::binary | ios_base::trunc);
Output.Writer = new matroska_writer(Output.Output, vid_fmt, Width, Height, Framerate_Num, Framerate_Den, Has_Timecode);
}
Outputs.push_back(Output);
}

HasTimecode = Has_Timecode;
FramesInfo.video_width = Width;
FramesInfo.video_height = Height;
FramesInfo.video_rate_num = Framerate_Num;
Expand Down Expand Up @@ -84,6 +72,26 @@ void FileWrapper::Parse_Buffer(const uint8_t *Buffer, size_t Buffer_Size)
if (!FramesInfo.pixel_format && Frame->Pixel_Format)
FramesInfo.pixel_format = Frame->Pixel_Format;

if (!Merge_OutputFileNames.empty() && Outputs.empty())
{
video_format Format = v210;
if (FramesInfo.pixel_format == Decklink_Pixel_Format_8BitYUV)
Format = UYVY;

for (string OutputFile : Merge_OutputFileNames)
{
matroska_output Output;
if (OutputFile == "-")
Output.Writer = new matroska_writer(&cout, Format, FramesInfo.video_width, FramesInfo.video_height, FramesInfo.video_rate_num, FramesInfo.video_rate_den, HasTimecode);
else
{
Output.Output = new ofstream(OutputFile, ios_base::binary | ios_base::trunc);
Output.Writer = new matroska_writer(Output.Output, Format, FramesInfo.video_width, FramesInfo.video_height, FramesInfo.video_rate_num, FramesInfo.video_rate_den, HasTimecode);
}
Outputs.push_back(Output);
}
}

for (matroska_output& Output : Outputs)
{
Output.Writer->write_frame((const char*)Frame->Video_Buffer, (uint32_t)Frame->Video_Buffer_Size,
Expand Down
13 changes: 2 additions & 11 deletions Source/Common/ProcessFileWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,6 @@ struct matroska_output
};
#endif

//***************************************************************************
//enums
//***************************************************************************

enum video_format
{
v210,
UYVY,
};

//***************************************************************************
// Class FileWrapper
//***************************************************************************
Expand All @@ -91,7 +81,7 @@ class FileWrapper {
public:
FileWrapper(file* File); // Constructor for DV/MediaInfo Interface
#if defined(ENABLE_DECKLINK) || defined(ENABLE_SIMULATOR)
FileWrapper(video_format vid_fmt, int Width, int Height, int Framerate_Num, int Framerate_Den, int SampleRate, int Channels, bool Has_Timecode = false); // Constructor for Decklink/Matroska Interface
FileWrapper(int Width, int Height, int Framerate_Num, int Framerate_Den, int SampleRate, int Channels, bool Has_Timecode = false); // Constructor for Decklink/Matroska Interface
~FileWrapper();
#endif
void Parse_Buffer(const uint8_t* Buffer, std::size_t Buffer_Size);
Expand All @@ -104,6 +94,7 @@ class FileWrapper {
file* File;
#if defined(ENABLE_DECKLINK) || defined(ENABLE_SIMULATOR)
bool IsMatroska = false;
bool HasTimecode = false;
std::vector<matroska_output> Outputs;
size_t FrameCount = 0;
#endif
Expand Down

0 comments on commit 059991b

Please sign in to comment.