Skip to content

Commit

Permalink
Add --csv support with decklink input
Browse files Browse the repository at this point in the history
+ add tc_r and tc_nc to DeckLink XML

Signed-off-by: Maxime Gervais <[email protected]>
  • Loading branch information
g-maxime committed Apr 11, 2024
1 parent e4444ed commit 3f3c322
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 2 deletions.
7 changes: 7 additions & 0 deletions Source/Common/Output_Xml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,13 @@ return_value Output_Xml(ostream& Out, std::vector<file*>& PerFile, bitset<Option
Text += " tc=\"";
timecode_to_string(Text, tc_in_seconds, dropframe, frame);
Text += '\"';

if (File->Wrapper->FramesInfo.frames[Pos].tc_r)
Text += " tc_r=\"1\"";
else if (File->Wrapper->FramesInfo.frames[Pos].tc_nc == 2)
Text += " tc_nc=\"2\"";
else if (File->Wrapper->FramesInfo.frames[Pos].tc_nc == 1)
Text += " tc_nc=\"1\"";
}

Text += "/>\n";
Expand Down
66 changes: 65 additions & 1 deletion Source/Common/ProcessFileWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,80 @@ void FileWrapper::Parse_Buffer(const uint8_t *Buffer, size_t Buffer_Size)
(const char*)Frame->Audio_Buffer, Frame->Audio_Buffer_Size, Frame->TC);
}

bool TimeCode_Repeat = false;
bool TimeCode_NonConsecutive = false;
bool TimeCode_NonConsecutive_IsLess = false;
if (Frame->TC.HasValue() && FramesInfo.frames.size() && FramesInfo.frames.back().tc.HasValue())
{
TimeCode_Repeat = Frame->TC == FramesInfo.frames.back().tc;
if (!TimeCode_Repeat)
{
TimeCode Previous = FramesInfo.frames.back().tc;
TimeCode Current = Frame->TC;
Previous.FramesPerSecond = (FramesInfo.video_rate_num / FramesInfo.video_rate_num) + (FramesInfo.video_rate_num % FramesInfo.video_rate_num);
Previous.FramesPerSecond_Is1001 = FramesInfo.video_rate_den == 1001;
Current.FramesPerSecond = Previous.FramesPerSecond;
Current.FramesPerSecond_Is1001 = Previous.FramesPerSecond_Is1001;

TimeCode_NonConsecutive = Current.ToFrames() != Previous.ToFrames() + 1;
if (TimeCode_NonConsecutive)
TimeCode_NonConsecutive_IsLess = Current.ToFrames() < Previous.ToFrames();
}
}

double FrameRate = (double)FramesInfo.video_rate_num / FramesInfo.video_rate_den;
double ElapsedTime = (double)FramesInfo.frames.size() / FrameRate;
FramesInfo.frames.push_back(decklink_framesinfo::frame {
Frame->TC,
TimeCode_Repeat,
TimeCode_NonConsecutive ? (TimeCode_NonConsecutive_IsLess ? 2 : 1) : 0,
ElapsedTime * 1000000000.0,
1.0 / FrameRate
});

cerr << "\33[2K\rCapture frame " << ++FrameCount << ", press " << (InControl ? "q" : "ctrl+c") << " to stop.";
if (MergeInfo_Format == 1)
{
if (!FrameCount)
{
cout << "FramePos,abst,abst_r,abst_nc,tc,tc_r,tc_nc,rdt,rdt_r,rdt_nc,rec_start,rec_end,Used,Status,Comments,BlockErrors,BlockErrors_Even,IssueFixed"
<< (Verbosity > 5 ? ",SourceSpeed,FrameSpeed,InputPos,OutputPos" : "")
<< (ShowFrames_Intermediate ? ",RewindStatus" : "")
<< endl;
}

cout << FrameCount++ // framePos
<< "," // abst
"," // abst_r
"," // abst_nc
"," << (Frame->TC.HasValue() ? Frame->TC.ToString() : "XX:XX:XX:XX") // tc
<< "," << (TimeCode_Repeat ? "1" : "") // tc_r
<< "," << (TimeCode_NonConsecutive ? (TimeCode_NonConsecutive_IsLess ? "2" : "1") : "") // tc_nc
<< "," // rdt
"," // rdt_r
"," // rdt_nc
"," // rec_start
"," // rec_end
"," // Used
"," // Status
"," // Comments
"," // BlockErrors
"," // BlocksErrors_Even
"," // IssueFixed
<< (Verbosity > 5 ?
"," // SourceSpeed
"," // FrameSpeed
"," // InputPos
"," // OutputPos
: ""
)
<< (ShowFrames_Intermediate ?
"," // RewindStatus
: ""
)
<< endl;
}
else
cerr << "\33[2K\rCapture frame " << ++FrameCount << ", press " << (InControl ? "q" : "ctrl+c") << " to stop.";
return;
}
#endif
Expand Down
2 changes: 2 additions & 0 deletions Source/Common/ProcessFileWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ struct decklink_frame
struct decklink_framesinfo {
struct frame {
TimeCode tc;
bool tc_r;
uint8_t tc_nc;
double pts;
double dur;
};
Expand Down
2 changes: 1 addition & 1 deletion Source/ThirdParty/TimeCode/TimeCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ bool TimeCode::FromString(const char* Value)
//---------------------------------------------------------------------------
string TimeCode::ToString() const
{
if (!IsValid())
if (!HasValue())
return string();

string TC;
Expand Down

0 comments on commit 3f3c322

Please sign in to comment.