Format -ss timespan argument to calculate hours

Former-commit-id: bb08076db4
This commit is contained in:
crypton 2021-02-12 22:16:55 -08:00
parent 83c9478007
commit bff3406545
2 changed files with 20 additions and 3 deletions

View file

@ -197,7 +197,7 @@ public void Builder_BuildString_Loop()
public void Builder_BuildString_Seek()
{
var str = FFMpegArguments.FromFileInput("input.mp4", false, opt => opt.Seek(TimeSpan.FromSeconds(10))).OutputToFile("output.mp4", false, opt => opt.Seek(TimeSpan.FromSeconds(10))).Arguments;
Assert.AreEqual("-ss 00:00:10 -i \"input.mp4\" -ss 00:00:10 \"output.mp4\"", str);
Assert.AreEqual("-ss 00:00:10.000 -i \"input.mp4\" -ss 00:00:10.000 \"output.mp4\"", str);
}
[TestMethod]

View file

@ -8,11 +8,28 @@ namespace FFMpegCore.Arguments
public class SeekArgument : IArgument
{
public readonly TimeSpan? SeekTo;
public SeekArgument(TimeSpan? seekTo)
{
SeekTo = seekTo;
}
public string Text => !SeekTo.HasValue ? string.Empty : $"-ss {SeekTo.Value}";
public string Text {
get {
if(SeekTo.HasValue)
{
int hours = SeekTo.Value.Hours;
if(SeekTo.Value.Days > 0)
{
hours += SeekTo.Value.Days * 24;
}
return $"-ss {hours.ToString("00")}:{SeekTo.Value.Minutes.ToString("00")}:{SeekTo.Value.Seconds.ToString("00")}.{SeekTo.Value.Milliseconds.ToString("000")}";
}
else
{
return string.Empty;
}
}
}
}
}