MCPcopy Create free account
hub / github.com/MediaArea/MediaInfoLib / FromSeconds

Method FromSeconds

Source/MediaInfo/TimeCode.cpp:684–713  ·  view source on GitHub ↗

---------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

682
683//---------------------------------------------------------------------------
684int TimeCode::FromSeconds(double Seconds, bool Truncate, bool TimeIsDropFrame)
685{
686 // Sign
687 auto IsSigned = Seconds < 0;
688 SetNegative(IsSigned);
689 if (IsSigned)
690 Seconds = -Seconds;
691
692 // Seconds to frames
693 double FrameCountF = Seconds * ((int64_t)GetFramesMax() + 1) / ((!TimeIsDropFrame && Is1001fps()) ? 1.001 : 1) + (Truncate ? 0.0 : 0.5);
694 if (FrameCountF > (double)numeric_limits<int64_t>::max() || FrameCountF < (double)numeric_limits<int64_t>::min())
695 {
696 *this = TimeCode();
697 return 1;
698 }
699 int64_t FrameCountI = (int64_t)FrameCountF;
700
701 // Manage rounding errors, that makes FromSeconds(ToSeconds()) neutral (symetry)
702 if (FrameCountF / (FrameCountI + 1) > (double)0.999999999999999)
703 FrameCountI++;
704
705 // Compute time code from frames, managing the need to consider time with also drop frames
706 if (TimeIsDropFrame && IsDropFrame())
707 SetDropFrame(false);
708 auto Result = FromFrames(FrameCountI);
709 if (TimeIsDropFrame && IsDropFrame())
710 SetDropFrame();
711
712 return Result;
713}
714
715//---------------------------------------------------------------------------
716TimeCode TimeCode::ToRescaled(uint32_t FramesMax, flags Flags, rounding Rounding) const

Callers 1

Streams_FinishMethod · 0.80

Calls 1

TimeCodeClass · 0.70

Tested by

no test coverage detected