|
|
|
@ -1,6 +1,7 @@ |
|
|
|
using System.Diagnostics; |
|
|
|
using System.Text; |
|
|
|
using System.Text; |
|
|
|
|
|
|
|
using Bugsnag; |
|
|
|
using Bugsnag; |
|
|
|
|
|
|
|
using CliWrap; |
|
|
|
|
|
|
|
using CliWrap.Buffered; |
|
|
|
using ErsatzTV.Core; |
|
|
|
using ErsatzTV.Core; |
|
|
|
using ErsatzTV.Core.Domain; |
|
|
|
using ErsatzTV.Core.Domain; |
|
|
|
using ErsatzTV.Core.FFmpeg; |
|
|
|
using ErsatzTV.Core.FFmpeg; |
|
|
|
@ -54,38 +55,34 @@ public class GetLastPtsDurationHandler : IRequestHandler<GetLastPtsDuration, Eit |
|
|
|
Option<FileInfo> maybeLastSegment = GetLastSegment(parameters.ChannelNumber); |
|
|
|
Option<FileInfo> maybeLastSegment = GetLastSegment(parameters.ChannelNumber); |
|
|
|
foreach (FileInfo segment in maybeLastSegment) |
|
|
|
foreach (FileInfo segment in maybeLastSegment) |
|
|
|
{ |
|
|
|
{ |
|
|
|
var startInfo = new ProcessStartInfo |
|
|
|
string[] argumentList = |
|
|
|
{ |
|
|
|
{ |
|
|
|
FileName = parameters.FFprobePath, |
|
|
|
// `-v 0` seems to prevent ffprobe from outputting anything on windows
|
|
|
|
RedirectStandardOutput = true, |
|
|
|
"-show_entries", |
|
|
|
RedirectStandardError = true, |
|
|
|
"packet=pts,duration", |
|
|
|
UseShellExecute = false, |
|
|
|
"-of", |
|
|
|
StandardOutputEncoding = Encoding.UTF8, |
|
|
|
"compact=p=0:nk=1", |
|
|
|
StandardErrorEncoding = Encoding.UTF8 |
|
|
|
"-read_intervals", |
|
|
|
|
|
|
|
"-999999", |
|
|
|
|
|
|
|
segment.FullName |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// `-v 0` seems to prevent ffprobe from outputting anything on windows
|
|
|
|
BufferedCommandResult probe = await Cli.Wrap(parameters.FFprobePath) |
|
|
|
startInfo.ArgumentList.Add("-show_entries"); |
|
|
|
.WithArguments(argumentList) |
|
|
|
startInfo.ArgumentList.Add("packet=pts,duration"); |
|
|
|
.WithValidation(CommandResultValidation.None) |
|
|
|
startInfo.ArgumentList.Add("-of"); |
|
|
|
.ExecuteBufferedAsync(cancellationToken); |
|
|
|
startInfo.ArgumentList.Add("compact=p=0:nk=1"); |
|
|
|
|
|
|
|
startInfo.ArgumentList.Add("-read_intervals"); |
|
|
|
|
|
|
|
startInfo.ArgumentList.Add("-999999"); |
|
|
|
|
|
|
|
startInfo.ArgumentList.Add(segment.FullName); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var probe = new Process |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
StartInfo = startInfo |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
probe.Start(); |
|
|
|
|
|
|
|
string output = await probe.StandardOutput.ReadToEndAsync(); |
|
|
|
|
|
|
|
await probe.WaitForExitAsync(cancellationToken); |
|
|
|
|
|
|
|
if (probe.ExitCode != 0) |
|
|
|
if (probe.ExitCode != 0) |
|
|
|
{ |
|
|
|
{ |
|
|
|
return BaseError.New($"FFprobe at {parameters.FFprobePath} exited with code {probe.ExitCode}"); |
|
|
|
return BaseError.New($"FFprobe at {parameters.FFprobePath} exited with code {probe.ExitCode}"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string output = probe.StandardOutput; |
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(probe.StandardOutput)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
output = probe.StandardError; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
try |
|
|
|
try |
|
|
|
{ |
|
|
|
{ |
|
|
|
string[] lines = output.Split("\n"); |
|
|
|
string[] lines = output.Split("\n"); |
|
|
|
|