public string ReadAsString(CancelFlag cancellationToken) { #if NET35 var buf = new byte[8192]; #else var buf = System.Buffers.ArrayPool <byte> .Shared.Rent(8192); #endif try { var sourceStream = responseStream; var ms = new MemoryStream(); while (!cancellationToken.IsCancellationRequested) { var x = sourceStream.Read(buf, 0, buf.Length); if (x == 0) { break; } ms.Write(buf, 0, x); cancellationToken.ThrowIfCancellationRequested(); } return(Encoding.UTF8.GetString(ms.ToArray())); } finally { #if !NET35 System.Buffers.ArrayPool <byte> .Shared.Return(buf); #endif } }
public override MediaProcessingResult ConvertToMp3Audio(string infile, string outfile, CancelFlag cancellationToken, out long outFileSize) { var args = CreateMP3MergeArgs(infile, outfile); var ret = this.ProcessMedia(args, cancellationToken); try { outFileSize = new FileInfo(outfile).Length; } catch { outFileSize = -1; } return(ret); }
public override MediaProcessingResult MergeHLSAudioVideStream(string fileList, string outfile, CancelFlag cancellationToken, out long outFileSize) { var args = CreateHLSMergeArgs(fileList, outfile); var ret = this.ProcessMedia(args, cancellationToken); try { outFileSize = new FileInfo(outfile).Length; } catch { outFileSize = -1; } return(ret); }
private void ExportStats() { const int colLen = 25; StringBuilder sb = new StringBuilder(); sb.AppendLine("Job ID:".PadRight(colLen) + Stats.JobID.ToString()); sb.AppendLine("Debug Mode:".PadRight(colLen) + Stats.RunInDebugMode.ToString()); sb.AppendLine("Cancelled by User:"******"Destination Root:".PadRight(colLen) + Stats.DestPathRoot); sb.AppendLine("Started:".PadRight(colLen) + Stats.DtTmStarted.ToString()); sb.AppendLine("Ended:".PadRight(colLen) + Stats.DtTmEnded.ToString()); sb.AppendLine("Duration:".PadRight(colLen) + Stats.JobSpanAsStr); sb.AppendLine("Errors:".PadRight(colLen) + Stats.NumErrors.ToString()); if (Stats.NumErrors > 0) { sb.AppendLine("".PadRight(colLen) + "(see associated error log for details)"); } sb.AppendLine("Warnings:".PadRight(colLen) + Stats.NumWarnings.ToString()); sb.AppendLine("Excluded Folders:".PadRight(colLen) + Stats.FoldersExcluded.ToString()); sb.AppendLine("Excluded Files:".PadRight(colLen) + Stats.FilesExcluded.ToString()); sb.AppendLine("Scanned Folders:".PadRight(colLen) + Stats.FoldersScanned.ToString()); sb.AppendLine("Scanned Files:".PadRight(colLen) + Stats.FilesScanned.ToString()); sb.AppendLine("Size of Files Scanned:".PadRight(colLen) + $"{Stats.VolumeScanned} ({FileSizeHelper.LongAsSizeStrBestApprox(Stats.VolumeScanned)})"); if (Stats.RunInSimMode) { sb.AppendLine("Simulation Mode:".PadRight(colLen) + Stats.RunInSimMode.ToString()); sb.AppendLine("Number of Sim Adds:".PadRight(colLen) + Stats.SimNumAdds.ToString()); sb.AppendLine("Number of Sim Updates:".PadRight(colLen) + Stats.NumUpdates.ToString()); sb.AppendLine("Size of Sim Adds:".PadRight(colLen) + $"{Stats.SimVolumeAdds} ({FileSizeHelper.LongAsSizeStrBestApprox(Stats.SimVolumeAdds)})"); sb.AppendLine("Size of Sim Updates:".PadRight(colLen) + $"{Stats.SimVolumeUpdates} ({FileSizeHelper.LongAsSizeStrBestApprox(Stats.SimVolumeUpdates)})"); } else { sb.AppendLine("Number of File Adds:".PadRight(colLen) + Stats.NumAdds.ToString()); sb.AppendLine("Number of File Updates:".PadRight(colLen) + Stats.NumUpdates.ToString()); sb.AppendLine("Number of File Deletes:".PadRight(colLen) + Stats.NumDeletes.ToString()); sb.AppendLine("Size of File Adds:".PadRight(colLen) + $"{Stats.VolumeAdds} ({FileSizeHelper.LongAsSizeStrBestApprox(Stats.VolumeAdds)})"); sb.AppendLine("Size of File Updates:".PadRight(colLen) + $"{Stats.VolumeUpdates} ({FileSizeHelper.LongAsSizeStrBestApprox(Stats.VolumeUpdates)})"); sb.AppendLine("Size of File Deletes:".PadRight(colLen) + $"{Stats.VolumeDeletes} ({FileSizeHelper.LongAsSizeStrBestApprox(Stats.VolumeDeletes)})"); } File.WriteAllText(Stats.StatsLogFileName, sb.ToString(), PathUtils.UTFWithNoBom); }
public abstract MediaProcessingResult MergeAudioVideStream(string file1, string file2, string outfile, CancelFlag cancellationToken, out long outFileSize);
public abstract MediaProcessingResult ConvertToMp3Audio(string segmentListFile, string outfile, CancelFlag cancellationToken, out long outFileSize);
public abstract MediaProcessingResult MergeHLSAudioVideStream(string segmentListFile, string outfile, CancelFlag cancellationToken, out long outFileSize);
public override MediaProcessingResult MergeHLSAudioVideStream(string segmentListFile, string outfile, CancelFlag cancellationToken, out long outFileSize) { Log.Information(segmentListFile + " " + outfile); outFileSize = -1; return(MediaProcessingResult.Success); }
public override MediaProcessingResult MergeAudioVideStream(string file1, string file2, string outfile, CancelFlag cancellationToken, out long outFileSize) { Log.Information(file1 + " " + file2 + " " + outfile); outFileSize = new FileInfo(file1).Length + new FileInfo(file2).Length; return(MediaProcessingResult.Success); }
private MediaProcessingResult ProcessMedia(string[] args, CancelFlag cancellationToken) { try { Log.Debug("FFmpeg args: " + string.Join(" ", args)); var duration = 0L; var time = 0L; var file = FindFFmpegBinary(); Log.Debug("FFmpeg binary: " + file); var lastTick = Helpers.TickCount(); var pb = new ProcessStartInfo { FileName = file, UseShellExecute = false, CreateNoWindow = true }; #if NET5_0_OR_GREATER foreach (var arg in args) { pb.ArgumentList.Add(arg); } #else pb.Arguments = XDM.Compatibility.ProcessStartInfoHelper.ArgumentListToArgsString(args); #endif //#if NET5_0_OR_GREATER // foreach (var arg in args) // { // pb.ArgumentList.Add(arg); // } //#else // pb.Arguments = CoreFx.Polyfill.ProcessStartInfoHelper.ArgumentListToArgsString(args); //#endif //var sb = new StringBuilder(); //foreach (var arg in args) //{ // sb.Append(arg.Contains(' ') ? "\"" + arg + "\"" : arg); //} //pb.Arguments = sb.ToString(); pb.RedirectStandardOutput = true; using var proc = Process.Start(pb); if (proc == null) { throw new Exception("FFmpeg process could not be started - Process.Start"); } proc.OutputDataReceived += (a, b) => { try { var line = b.Data; if (line != null) { Log.Debug(line); if (duration == 0.0) { var md = ParsingHelper.RxDuration.Match(line); var ret = ParsingHelper.ParseTime(md); if (ret > 0) { duration = ret; } } var mt = ParsingHelper.RxTime.Match(line); var ret2 = ParsingHelper.ParseTime(mt); if (ret2 > 0) { time += ret2; var tick = Helpers.TickCount(); if (duration > 0 && tick - lastTick > 1000) { UpdateProgress((int)((time * 100) / duration)); } } } } catch (Exception ex) { Log.Debug(ex, ex.Message); } }; proc.ErrorDataReceived += (a, b) => { var line = b.Data; if (line != null) { Log.Debug(line); } }; proc.BeginOutputReadLine(); while (true) { if (cancellationToken.IsCancellationRequested) { proc.Kill(); break; } if (proc.WaitForExit(100)) { proc.WaitForExit(); //see remarks section https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.process.waitforexit?view=net-6.0 break; } } if (proc.ExitCode == 0) { return(MediaProcessingResult.Success); } Log.Debug("FFmpeg exitcode: " + proc.ExitCode); return(MediaProcessingResult.Failed); } catch (OperationCanceledException ex) { Console.WriteLine(ex); return(MediaProcessingResult.Success); } catch (FileNotFoundException ex) { Console.WriteLine(ex); return(MediaProcessingResult.AppNotFound); } catch (Exception ex) { Console.WriteLine(ex); return(MediaProcessingResult.Failed); } }