public ProcessStartInfo CreateMEncoderProcessStartInfo(string workingDir, MEncoderArguments args) { workingDir = Path.GetFullPath(workingDir); // @MSDN: // You must set UseShellExecute to false if you want to set RedirectStandardOutput to true. // Otherwise, reading from the StandardOutput stream throws an exception. var info = new ProcessStartInfo(); info.Arguments = CreateMEncoderArguments(workingDir, args); info.CreateNoWindow = true; info.ErrorDialog = false; info.FileName = Path.GetFullPath(Config.MEncoderFilePath); info.RedirectStandardOutput = true; info.RedirectStandardError = true; info.UseShellExecute = false; info.WindowStyle = ProcessWindowStyle.Hidden; info.WorkingDirectory = workingDir; // @TODO: Remove? LogInfo("Processing '{0}'", workingDir); LogInfo(info.Arguments); return(info); }
public override bool ProcessJob() { TotalWorkLoad = 0; ProcessedWorkLoad = 0; foreach (var sequence in _imageSequences) { TotalWorkLoad += sequence.ImageFilePaths.Count; } var i = 0; foreach (var sequence in _imageSequences) { CurrentSubJobWorkLoad = sequence.ImageFilePaths.Count; InitializeMEncoderErrorOutput(); var config = UmmApp.Instance.GetConfig(); var outputFilePath = CreateOutputFilePath(sequence, config, i); var args = new MEncoderArguments(); args.AviHasAudio = false; args.ImageSequence = true; args.InputAudioPath = null; args.InputImagesPath = sequence.ImageSequencePath; args.OutputFilePath = outputFilePath; args.UseSeparateAudioFile = false; args.Monochrome = sequence.Type == ImageType.Depth; args.InputFrameRate = sequence.FrameRate; args.OutputFrameRate = sequence.FrameRate; var info = UmmApp.Instance.CreateMEncoderProcessStartInfo(sequence.FolderPath, args); var process = Process.Start(info); if (process == null) { return(false); } ReadProcessOutputUntilDone(process); // Update progress. ProcessedWorkLoad += CurrentSubJobWorkLoad; // Display error output, if any. DisplayMEncoderErrorOutput(); ++i; } return(true); }
public override bool ProcessJob() { // This job only has 1 sub-job. TotalWorkLoad = DoesNeedAdditionalPass ? (FrameCount * 2) : FrameCount; ProcessedWorkLoad = 0; CurrentSubJobWorkLoad = _videoFileFrameCounts[0]; InitializeMEncoderErrorOutput(); // @NOTE: MEncoder can't mux multiple .avi files with a single .wav file. var workDir = GetWorkDir(); var outputFilePath = CreateOutputFilePath(); var videoFilePaths = GetVideoFilePaths(); var args = new MEncoderArguments(); args.AviHasAudio = _aviHasAudio; args.ImageSequence = false; args.InputAudioPath = _audioFilePath != null?Path.GetFullPath(_audioFilePath) : null; args.InputVideoPaths.AddRange(videoFilePaths); args.OutputFilePath = outputFilePath; args.UseSeparateAudioFile = (_audioFilePath != null) && (_videoFilePaths.Count == 1); var info = UmmApp.Instance.CreateMEncoderProcessStartInfo(workDir, args); var process = Process.Start(info); if (process == null) { return(false); } ReadProcessOutputUntilDone(process); // Update progress. ProcessedWorkLoad += CurrentSubJobWorkLoad; // Display error output, if any. DisplayMEncoderErrorOutput(); if (DoesNeedAdditionalPass) { ProcessFinalAudioMuxJob(); } return(true); }
public override void SaveJobToBatchFile(StreamWriter file) { foreach (var sequence in _imageSequences) { var config = UmmApp.Instance.GetConfig(); var args = new MEncoderArguments(); args.AviHasAudio = false; args.ImageSequence = true; args.InputAudioPath = HasAudio ? Path.GetFullPath(_audioFilePath) : null; args.InputImagesPath = sequence.ImageSequencePath; args.OutputFilePath = CreateOutputFilePath(sequence, config); args.UseSeparateAudioFile = HasAudio && !sequence.Monochrome; args.Monochrome = sequence.Monochrome; var folderPath = Path.GetFullPath(_folderPath); UmmApp.Instance.WriteTobatchFile(file, folderPath, args); } }
public void WriteTobatchFile(StreamWriter file, string workingDir, MEncoderArguments args) { workingDir = Path.GetFullPath(workingDir); var arguments = CreateMEncoderArguments(workingDir, args); var encoderPath = Path.GetFullPath(Config.MEncoderFilePath); var stringBuilder = new StringBuilder(); // Set the current directory. stringBuilder.Append("cd /D \""); stringBuilder.Append(workingDir); stringBuilder.AppendLine("\""); // Invoke MEncoder. stringBuilder.Append("\""); stringBuilder.Append(encoderPath); stringBuilder.Append("\" "); stringBuilder.AppendLine(arguments); file.Write(stringBuilder.ToString()); }
private bool ProcessFinalAudioMuxJob() { InitializeMEncoderErrorOutput(); var workDir = GetWorkDir(); var outputFilePath = CreateOutputFilePath(true); var args = new MEncoderArguments(); args.AviHasAudio = false; args.ImageSequence = false; args.InputAudioPath = Path.GetFullPath(_audioFilePath); args.InputVideoPaths.Add(TempFileName); args.OutputFilePath = outputFilePath; args.UseSeparateAudioFile = true; args.CodecOverride = true; args.Codec = VideoCodec.Copy; var info = UmmApp.Instance.CreateMEncoderProcessStartInfo(workDir, args); var process = Process.Start(info); if (process == null) { return(false); } ReadProcessOutputUntilDone(process); DisplayMEncoderErrorOutput(); var tempFilePath = Path.Combine(workDir, TempFileName); if (File.Exists(tempFilePath)) { File.Delete(tempFilePath); } return(true); }
public override void SaveJobToBatchFile(StreamWriter file) { var workDir = GetWorkDir(); var outputFilePath = CreateOutputFilePath(); var videoFilePaths = GetVideoFilePaths(); var args = new MEncoderArguments(); args.AviHasAudio = _aviHasAudio; args.ImageSequence = false; args.InputAudioPath = _audioFilePath != null?Path.GetFullPath(_audioFilePath) : null; args.InputVideoPaths.AddRange(videoFilePaths); args.OutputFilePath = outputFilePath; args.UseSeparateAudioFile = (_audioFilePath != null) && (_videoFilePaths.Count == 1); UmmApp.Instance.WriteTobatchFile(file, workDir, args); if (DoesNeedAdditionalPass) { workDir = GetWorkDir(); outputFilePath = CreateOutputFilePath(true); args = new MEncoderArguments(); args.AviHasAudio = false; args.ImageSequence = false; args.InputAudioPath = Path.GetFullPath(_audioFilePath); args.InputVideoPaths.Add(TempFileName); args.OutputFilePath = outputFilePath; args.UseSeparateAudioFile = true; args.CodecOverride = true; args.Codec = VideoCodec.Copy; UmmApp.Instance.WriteTobatchFile(file, workDir, args); var tempFilePath = Path.Combine(workDir, TempFileName); file.Write("del "); file.WriteLine(tempFilePath); } }
public override void SaveJobToBatchFile(StreamWriter file) { var i = 0; foreach (var sequence in _imageSequences) { var config = UmmApp.Instance.GetConfig(); var args = new MEncoderArguments(); args.AviHasAudio = false; args.ImageSequence = true; args.InputAudioPath = null; args.InputImagesPath = sequence.ImageSequencePath; args.OutputFilePath = CreateOutputFilePath(sequence, config, i); args.UseSeparateAudioFile = false; args.Monochrome = sequence.Type == ImageType.Depth; args.InputFrameRate = sequence.FrameRate; args.OutputFrameRate = sequence.FrameRate; UmmApp.Instance.WriteTobatchFile(file, sequence.FolderPath, args); ++i; } }
public string CreateMEncoderArguments(string workingDir, MEncoderArguments args) { // MEncoder arguments examples: // @""new.avi" -audiofile "new.wav" -oac copy -ovc vfw -xvfwopts codec=LAGARITH.DLL -of avi -ofps 60 -o ..\umm_test_output.avi"; // @"mf://*.tga -mf fps=60 -audiofile "new.wav" -oac copy -ovc vfw -xvfwopts codec=LAGARITH.DLL -of avi -o ..\umm_test_output.avi"; var codec = args.Monochrome ? Config.MonochromeCodec : Config.ColorCodec; var customOptionsLavc = args.Monochrome ? Config.CustomMonochromeOptionsLavc : Config.CustomColorOptionsLavc; var customCodecVfw = args.Monochrome ? Config.CustomMonochromeVfwCodecName : Config.CustomColorVfwCodecName; var showCodecDialog = args.Monochrome ? Config.ShowMonochromeCodecDialog : Config.ShowColorCodecDialog; var codecDialogShown = args.Monochrome ? MonochromeCodecDialogShown : ColorCodecDialogShown; if (args.CodecOverride) { codec = args.Codec; } var inputFrameRate = Config.FrameRate; var outputFrameRate = Config.OutputFrameRate; if (Config.UseFolderLocalFrameRate) { if (args.InputFrameRate > 0) { inputFrameRate = args.InputFrameRate; } if (args.OutputFrameRate > 0) { outputFrameRate = args.OutputFrameRate; } } if (args.ImageSequence && args.InputImagesPath == null) { LogWarning("CreateMEncoderArguments: args.ImageSequence && args.InputImagesPath == null"); LogWarning("Told to use an image sequence but none was specified. The format is like this: *.tga"); } if (args.InputVideoPaths.Count > 1 && args.UseSeparateAudioFile) { LogWarning("CreateMEncoderArguments: args.InputVideoPaths.Count > 1 && args.UseSeparateAudioFile"); LogWarning("Can't mux multiple .avi files with 1 .wav in MEncoder"); } if (args.UseSeparateAudioFile && (args.InputAudioPath == null || !File.Exists(args.InputAudioPath))) { LogWarning("CreateMEncoderArguments: args.UseSeparateAudioFile && (args.InputAudioPath == null || !File.Exists(args.InputAudioPath))"); LogWarning("Told to use an audio file but none valid was specified"); } var arguments = new StringBuilder(); if (args.ImageSequence) { arguments.Append(" mf://"); arguments.Append(args.InputImagesPath); arguments.Append(" -mf fps="); arguments.Append(inputFrameRate); } else { arguments.Append(" -fps "); arguments.Append(inputFrameRate); foreach (var inputVideoPath in args.InputVideoPaths) { arguments.Append(" \""); arguments.Append(inputVideoPath); arguments.Append("\""); } } if (Config.FramesToSkip > 0) { var startTimeSeconds = (double)Config.FramesToSkip * (1.0 / (double)outputFrameRate); arguments.Append(" -ss "); arguments.Append(startTimeSeconds); } if (args.UseSeparateAudioFile && args.InputAudioPath != null && File.Exists(args.InputAudioPath)) { var audioFilePath = args.InputAudioPath; var audioFileName = Path.GetFileName(audioFilePath); if (Path.GetFullPath(audioFilePath).ToLower() == Path.GetFullPath(Path.Combine(workingDir, audioFileName)).ToLower()) { audioFilePath = audioFileName; } arguments.Append(" -audiofile \""); arguments.Append(audioFilePath); arguments.Append("\" -oac copy"); } else if (!args.ImageSequence && args.InputVideoPaths.Count == 1 && args.AviHasAudio) { arguments.Append(" -oac copy"); } switch (codec) { case VideoCodec.Copy: arguments.Append(" -ovc copy"); break; case VideoCodec.Raw: arguments.Append(" -ovc raw"); break; case VideoCodec.Lagarith: arguments.Append(" -ovc vfw -xvfwopts codec=LAGARITH.DLL"); if (showCodecDialog && !codecDialogShown) { arguments.Append(":compdata=dialog"); SetCodecDialogShown(args.Monochrome); } break; case VideoCodec.Lavc: arguments.Append(" -ovc lavc"); if (!string.IsNullOrWhiteSpace(customOptionsLavc)) { arguments.Append(" -lavcopts "); arguments.Append(customOptionsLavc); } break; case VideoCodec.CustomVfw: arguments.Append(" -ovc vfw -xvfwopts codec="); arguments.Append(customCodecVfw); if (showCodecDialog && !codecDialogShown) { arguments.Append(":compdata=dialog"); SetCodecDialogShown(args.Monochrome); } break; } if (args.ImageSequence && outputFrameRate != inputFrameRate) { arguments.Append(" -ofps "); arguments.Append(outputFrameRate); } arguments.Append(" -of avi -o \""); arguments.Append(args.OutputFilePath); arguments.Append("\""); // Strip the leading space. arguments.Remove(0, 1); return(arguments.ToString()); }