Last active
May 21, 2024 21:02
-
-
Save M-Yankov/afab1c2e2fe190c7d0db912d614f1431 to your computer and use it in GitHub Desktop.
Calculate with C# next postion in timeline using timecodes start/end between clips for Davinci Resolve
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Sample; | |
var d1 = new DateTime(2024, 05, 11, 08, 31, 49); // End of Clip_00002 | |
var d2 = new DateTime(2024, 05, 11, 13, 09, 20); // Start of Clip_00003 | |
var res = d2 - d1; | |
Console.WriteLine("Diff {0}", res); | |
var timeLine = new DateTime(2024, 01, 1, 0, 1, 16) + res; // Last clip timeline end | |
Console.WriteLine("Put next video at {0:HH:mm:ss:ff}", timeLine); /// ?? Less than 4:33 | |
const int FPS = 60; | |
TimeFrame t1end = new(FPS, 08, 31, 49, 26); | |
TimeFrame t2start = new(FPS, 13, 09, 20, 30); | |
TimeFrame timelineLastClipEnd = new(FPS, 0, 1, 16, 29); | |
int frames = timelineLastClipEnd.TotalFrames + (t2start.TotalFrames - t1end.TotalFrames); | |
TimeFrame postionNextClip = TimeFrame.FromFrames(frames, FPS); | |
Console.WriteLine(postionNextClip); | |
namespace Sample | |
{ | |
public record TimeFrame(int fps, int Hours, int Minutes, int Seconds, int Frames) | |
{ | |
// 1 day * 60fps | |
private int MaxFrames = 5184000; | |
private readonly int fps = fps; | |
public int TotalFrames => | |
(Hours * 60 * 60 * fps) + (Minutes * 60 * fps) + (Seconds * fps) + Frames; | |
public static TimeFrame FromFrames(int totalFrames, int fps = 60) | |
{ | |
double totalSeconds = totalFrames / (double)fps; | |
TimeSpan timeSpan = TimeSpan.FromSeconds(totalSeconds); | |
int leftFrames = totalFrames % fps; | |
return new TimeFrame(fps, timeSpan.Hours, timeSpan.Minutes, timeSpan.Seconds, leftFrames); | |
} | |
public override string ToString() | |
{ | |
return $"{this.Hours:D2}:{this.Minutes:D2}:{this.Seconds:D2}.{Frames}"; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment