private void SetInOutTemp(EncodeInfo inJob) { var asciiFile = FileSystemHelper.GetAsciiFileName(inJob.InputFile); if (string.CompareOrdinal(inJob.InputFile, asciiFile) != 0) { inJob.TempInput = FileSystemHelper.CreateTempFile(_configService.DemuxLocation, Path.GetExtension(inJob.InputFile)); } asciiFile = FileSystemHelper.GetAsciiFileName(inJob.OutputFile); if (string.CompareOrdinal(inJob.OutputFile, asciiFile) == 0) { return; } string fExt; if ((inJob.EncodingProfile.OutFormat == OutputType.OutputAvchd) || (inJob.EncodingProfile.OutFormat == OutputType.OutputBluRay) || (inJob.EncodingProfile.OutFormat == OutputType.OutputDvd)) { fExt = string.Empty; } else { fExt = Path.GetExtension(inJob.OutputFile); } inJob.TempOutput = FileSystemHelper.CreateTempFile(_configService.DemuxLocation, string.IsNullOrEmpty(inJob.TempInput) ? asciiFile : inJob.TempInput, fExt); }
static void EncodeLuaFile(EncodeInfo encodeInfo) { if (!encodeInfo.encode) // 不加密 { UnityEditor.FileUtil.CopyFileOrDirectory(encodeInfo.srcFile, encodeInfo.outFile); return; } string currentDirectory = Directory.GetCurrentDirectory(); Directory.SetCurrentDirectory(encodeInfo.extDir); ProcessStartInfo info = new ProcessStartInfo { FileName = encodeInfo.exe, Arguments = "-b -g " + encodeInfo.srcFile + " " + encodeInfo.outFile, WindowStyle = ProcessWindowStyle.Hidden, UseShellExecute = encodeInfo.isWin, ErrorDialog = true }; Process pro = Process.Start(info); pro.WaitForExit(); pro.Dispose(); Directory.SetCurrentDirectory(currentDirectory); }
private void DoEncodeVideo(EncodeInfo job) { switch (job.VideoProfile.Type) { case ProfileType.X264: { X264 x264Enc = new X264(); x264Enc.SetJob(job); _worker.DoWork += x264Enc.DoEncode; Log.Info("x264Encoder.DoEncode()"); } break; case ProfileType.HcEnc: { HcEnc hcEnc = new HcEnc(); hcEnc.SetJob(job); _worker.DoWork += hcEnc.DoEncodeDvd; Log.Info("HCEnc.DoEncodeDVD()"); } break; case ProfileType.VP8: { VpxEnc vpxEnc = new VpxEnc(); vpxEnc.SetJob(job); _worker.DoWork += vpxEnc.DoEncode; Log.Info("VpxEnc.DoEncode()"); } break; } }
private void CreateJob(string fileName) { EncodeInfo inJob = new EncodeInfo { InputFile = fileName, Input = Processing.DetectInputType(fileName) }; if ((string.IsNullOrEmpty(inJob.InputFile)) || (inJob.Input == InputType.InputUndefined)) { return; } StreamSelect streamSelection = new StreamSelect { JobInfo = inJob, Owner = this }; bool?retValue = streamSelection.ShowDialog(); if (retValue != true) { return; } Processing.CheckSubtitles(inJob); Processing.CheckStreamLimit(inJob); SetOutput(inJob); SetInOutTemp(inJob); JobCollection.Add(inJob); }
private static void SetInOutTemp(EncodeInfo inJob) { string asciiFile = Processing.GetAsciiFileName(inJob.InputFile); if (string.CompareOrdinal(inJob.InputFile, asciiFile) != 0) { inJob.TempInput = Processing.CreateTempFile(Path.GetExtension(inJob.InputFile)); } asciiFile = Processing.GetAsciiFileName(inJob.OutputFile); if (string.CompareOrdinal(inJob.OutputFile, asciiFile) != 0) { string fExt; if ((inJob.EncodingProfile.OutFormat == OutputType.OutputAvchd) || (inJob.EncodingProfile.OutFormat == OutputType.OutputBluRay) || (inJob.EncodingProfile.OutFormat == OutputType.OutputDvd)) { fExt = string.Empty; } else { fExt = Path.GetExtension(inJob.OutputFile); } inJob.TempOutput = Processing.CreateTempFile(string.IsNullOrEmpty(inJob.TempInput) ? asciiFile : inJob.TempInput, fExt); } }
void EncodeCompleted(object sender, RunWorkerCompletedEventArgs e) { if ((JobList[_actualJob].NextStep != EncodingStep.MoveOutFile) && (JobList[_actualJob].NextStep != EncodingStep.CopyTempFile)) { JobList[_actualJob] = (EncodeInfo)e.Result; } _actualProcessStep++; EncodeInfo job = JobList[_actualJob]; DeleteTempFiles(ref job); if (!_cancel) { if (JobList[_actualJob].ExitCode != 0) { _actualJob++; } StartEncode(); } else { if (_worker != null) { _worker.Dispose(); } AbortBtn.IsEnabled = true; CloseWindow(); } }
/// <summary> /// Starts queue processing /// </summary> /// <param name="queue"></param> public async void StartProcessing(ObservableCollection <EncodeInfo> queue) { InvokeQueueStarted(EventArgs.Empty); _queueList = queue; _processingSteps = await Task.Run(() => CountProcessingSteps()); _fullTaskPercent = 100f / _processingSteps; try { _currentJob = GetNextJob(); } catch (Exception ex) { _currentJob = null; InvokeQueueCompleted(new QueueCompletedEventArgs(false, ex, ex.Message)); return; } _finishedSteps = 0; GetNextStep(); ExecuteNextStep(); }
/// <summary> /// /// </summary> /// <param name="encodeQueueTask"></param> /// <exception cref="Exception"></exception> public override void Start(EncodeInfo encodeQueueTask) { try { if (IsEncoding) { encodeQueueTask.ExitCode = -1; throw new Exception("FileCopy is already running"); } IsEncoding = true; _currentTask = encodeQueueTask; _copyThread = new Thread(CopyWorker); _copyThread.Start(); _startTime = DateTime.Now; // Fire the Encode Started Event InvokeEncodeStarted(EventArgs.Empty); } catch (Exception exc) { Log.Error(exc); _currentTask.ExitCode = -1; IsEncoding = false; InvokeEncodeCompleted(new EncodeCompletedEventArgs(false, exc, exc.Message)); } }
private void DoDemux(EncodeInfo job) { Eac3To eac3Toenc = new Eac3To(); FfMpeg ffmpeg = new FfMpeg(); switch (job.Input) { case InputType.InputBluRay: case InputType.InputAvchd: case InputType.InputHddvd: eac3Toenc.SetJob(job); _worker.DoWork += eac3Toenc.DoDemux; Log.Info("eac3toEncoder.DoDemux()"); break; case InputType.InputDvd: case InputType.InputAvi: case InputType.InputFlash: case InputType.InputMp4: case InputType.InputWm: case InputType.InputMatroska: case InputType.InputMpegps: case InputType.InputTs: case InputType.InputOgg: case InputType.InputWebM: ffmpeg.SetJob(job); _worker.DoWork += ffmpeg.DoDemux; Log.Info("ffmpegEncoder.DoDemux()"); break; } }
public void DisplayWindow(ShellWin window, EncodeInfo inputInfo, ObservableCollection <EncodeInfo> jobList) { if (window == ShellWin.LastView) { window = LastView; } else if (window != ActualView) { LastView = ActualView; } ActualView = window; switch (window) { case ShellWin.MainView: ShowMainView = true; ShowOptions = false; ShowChangelog = false; ShowAboutView = false; ShowEncode = false; MainViewModel?.CheckUpdate(); break; case ShellWin.OptionsView: ShowOptions = true; ShowMainView = false; ShowChangelog = false; ShowAboutView = false; ShowEncode = false; break; case ShellWin.ChangelogView: ShowOptions = false; ShowMainView = false; ShowChangelog = true; ShowAboutView = false; ShowEncode = false; break; case ShellWin.AboutView: ShowOptions = false; ShowMainView = false; ShowChangelog = false; ShowAboutView = true; ShowEncode = false; break; case ShellWin.EncodeView: ShowOptions = false; ShowMainView = false; ShowChangelog = false; ShowAboutView = false; ShowEncode = true; EncodeViewModel?.StartEncode(jobList); break; } }
private void DoPreMuxResult(EncodeInfo job) { MJpeg mplex = new MJpeg(); mplex.SetJob(job); _worker.DoWork += mplex.DoEncode; Log.Info("mjpeg.DoEncode()"); }
private void DoPremuxSubtitle(EncodeInfo job) { SpuMux subMux = new SpuMux(); subMux.SetJob(job); _worker.DoWork += subMux.Process; Log.Info("SpuMux.Process()"); }
private void DoMoveOutFile(EncodeInfo job) { FileWorker fw = new FileWorker(); fw.SetFiles(job.TempOutput, job.OutputFile); _worker.DoWork += fw.MoveFile; Log.Info("FileWorker.MoveFile()"); }
private void DoWriteInfoFile(EncodeInfo job) { InfoWriter writer = new InfoWriter(); writer.SetJob(job); _worker.DoWork += writer.DoWrite; Log.Info("InfoWriter.DoWrite()"); }
private void DoIndexVideo(EncodeInfo job) { FfmsIndex fIndex = new FfmsIndex(); fIndex.SetJob(job); _worker.DoWork += fIndex.DoIndex; Log.Info("ffindex.DoIndex()"); }
private void GetCropRect(EncodeInfo job) { FfMpeg ffmpeg = new FfMpeg(); ffmpeg.SetJob(job); _worker.DoWork += ffmpeg.GetCrop; Log.Info("ffmpegEncoder.GetCropRect()"); }
private void DoCopyTempFile(EncodeInfo job) { FileWorker fw = new FileWorker(); fw.SetFiles(job.InputFile, job.TempInput); _worker.DoWork += fw.CopyFile; Log.Info("FileWorker.CopyFile()"); }
private void DoDemuxSubtitle(EncodeInfo job) { MkvMerge mkvMerge = new MkvMerge(); mkvMerge.SetJob(job); _worker.DoWork += mkvMerge.DemuxSubtitle; Log.Info("mkvMerge.DemuxSubtitle()"); }
/// <summary> /// Execute a BDSup2Sub demux process. /// This should only be called from the UI thread. /// </summary> /// <param name="encodeQueueTask"> /// The encodeQueueTask. /// </param> public override void Start(EncodeInfo encodeQueueTask) { try { if (IsEncoding) { encodeQueueTask.ExitCode = -1; throw new Exception("BDSup2Sub is already running"); } IsEncoding = true; _currentTask = encodeQueueTask; var query = GenerateCommandLine(); var cliPath = _appConfig.JavaInstallPath; var cliStart = new ProcessStartInfo(cliPath, query) { WorkingDirectory = _appConfig.DemuxLocation, CreateNoWindow = true, UseShellExecute = false, RedirectStandardOutput = true }; EncodeProcess = new Process { StartInfo = cliStart }; Log.Info($"start parameter: {cliPath} {query}"); EncodeProcess.Start(); _startTime = DateTime.Now; EncodeProcess.OutputDataReceived += EncodeProcessDataReceived; EncodeProcess.BeginOutputReadLine(); _encoderProcessId = EncodeProcess.Id; // Set the encoder process exit trigger if (_encoderProcessId != -1) { EncodeProcess.EnableRaisingEvents = true; EncodeProcess.Exited += EncodeProcessExited; } EncodeProcess.PriorityClass = _appConfig.GetProcessPriority(); // Fire the Encode Started Event InvokeEncodeStarted(EventArgs.Empty); } catch (Exception exc) { Log.Error(exc); _currentTask.ExitCode = -1; IsEncoding = false; InvokeEncodeCompleted(new EncodeCompletedEventArgs(false, exc, exc.Message)); } }
private static void GetSubOrVideoStep(EncodeInfo job) { if (job.VideoStream != null) { switch (job.CompletedStep) { case EncodingStep.Demux: case EncodingStep.EncodeAudio: case EncodingStep.EncodeVideo: case EncodingStep.DemuxSubtitle: SubtitleInfo sub = job.SubtitleStreams.FirstOrDefault(subInfo => subInfo.NeedConversion); int demuxSubtitleIndex = job.SubtitleStreams.FindIndex(info => info.RawStream == false); if (job.VideoProfile.Type != ProfileType.Copy && !job.VideoStream.Encoded) { job.NextStep = EncodingStep.IndexVideo; } else if (demuxSubtitleIndex > -1) { job.NextStep = EncodingStep.DemuxSubtitle; job.StreamId = demuxSubtitleIndex; } else if (((AppSettings.JavaInstalled && AppSettings.BDSup2SubInstalled) || job.EncodingProfile.OutFormat == OutputType.OutputMp4) && sub != null) { job.NextStep = EncodingStep.ProcessSubtitle; job.StreamId = job.SubtitleStreams.IndexOf(sub); } else if (job.EncodingProfile.OutFormat == OutputType.OutputDvd) { job.NextStep = EncodingStep.PreMuxResult; } else { job.NextStep = EncodingStep.MuxResult; } break; case EncodingStep.ProcessSubtitle: if (job.EncodingProfile.OutFormat == OutputType.OutputDvd) { job.NextStep = EncodingStep.PreMuxResult; } else { job.NextStep = EncodingStep.MuxResult; } break; } } else { job.NextStep = job.EncodingProfile.OutFormat == OutputType.OutputDvd ? EncodingStep.PreMuxResult : EncodingStep.MuxResult; } }
/// <summary> /// Execute a ffmpeg crop detection process. /// This should only be called from the UI thread. /// </summary> /// <param name="encodeQueueTask"> /// The encodeQueueTask. /// </param> public override void Start(EncodeInfo encodeQueueTask) { try { if (IsEncoding) { encodeQueueTask.ExitCode = -1; throw new Exception("ffmpeg is already running"); } IsEncoding = true; _currentTask = encodeQueueTask; var query = GenerateCommandLine(); var cliPath = Path.Combine(_appConfig.ToolsPath, Executable); var cliStart = new ProcessStartInfo(cliPath, query) { WorkingDirectory = _appConfig.DemuxLocation, CreateNoWindow = true, UseShellExecute = false, RedirectStandardError = true, }; DecodeProcess = new Process { StartInfo = cliStart }; Log.Info($"start parameter: ffmpeg {query}"); DecodeProcess.Start(); _startTime = DateTime.Now; DecodeProcess.ErrorDataReceived += DecodeProcessDataReceived; DecodeProcess.BeginErrorReadLine(); _decoderProcessId = DecodeProcess.Id; if (_decoderProcessId != -1) { DecodeProcess.EnableRaisingEvents = true; DecodeProcess.Exited += DecodeProcessExited; } DecodeProcess.PriorityClass = _appConfig.GetProcessPriority(); // Fire the Encode Started Event InvokeEncodeStarted(EventArgs.Empty); } catch (Exception exc) { Log.Error(exc); _currentTask.ExitCode = -1; IsEncoding = false; InvokeEncodeCompleted(new EncodeCompletedEventArgs(false, exc, exc.Message)); } }
private void EncodeCompleted(object sender, EncodeCompletedEventArgs args) { _finishedSteps++; _currentEncoder.EncodeCompleted -= EncodeCompleted; _currentEncoder.EncodeStarted -= EncodeStarted; _currentEncoder.EncodeStatusChanged -= EncoderProgressStatus; _currentEncoder = null; DeleteTempFiles(); if (_currentJob != null && _currentJob.ExitCode == 0) { InvokeQueueStatusChanged(new QueueProgressEventArgs { JobName = string.Empty, AverageFrameRate = 0f, CurrentFrameRate = 0f, CurrentFrame = 0, TotalFrames = 0, ElapsedTime = new TimeSpan(), EstimatedTimeLeft = new TimeSpan(), PercentComplete = 0, TotalPercentComplete = (_finishedSteps * _fullTaskPercent), Pass = 0, }); GetNextStep(); if (_currentJob.NextStep == EncodingStep.Done && _queueList.IndexOf(_currentJob) < _queueList.Count - 1) { _currentJob = GetNextJob(); GetNextStep(); } else if (_currentJob.NextStep == EncodingStep.Done && _queueList.IndexOf(_currentJob) == _queueList.Count - 1) { InvokeQueueCompleted(new QueueCompletedEventArgs(true, null, string.Empty)); return; } ExecuteNextStep(); } else { var currentJob = _currentJob; var exitCode = -1; if (currentJob != null) { exitCode = currentJob.ExitCode; } InvokeQueueCompleted(new QueueCompletedEventArgs(false, new ApplicationException("Encoder exited with code " + exitCode), "Encoder exited with code " + exitCode)); } }
/// <summary> /// Generates commandline used for encoding an audio stream to AC-3 format. /// </summary> /// <param name="jobInfo">Container which holds all encoding profiles</param> /// <param name="inFile">Path to inputfile, can be "-" when using pipes</param> /// <param name="outFile">Path to outputfile</param> /// <returns>Commandline arguments</returns> public static string GenerateAC3EncodeLine(EncodeInfo jobInfo, string inFile, string outFile) { StringBuilder sb = new StringBuilder(); if (string.CompareOrdinal(inFile, "-") == 0) { sb.Append(" -i -"); } else { sb.AppendFormat("-i \"{0}\"", inFile); } sb.Append(" -c:a ac3"); int bitrate; int channels; bool drc; // safety check, should always be true if (jobInfo.AudioProfile.Type == ProfileType.AC3) { AC3Profile audProfile = (AC3Profile)jobInfo.AudioProfile; bitrate = audProfile.Bitrate; channels = audProfile.OutputChannels; drc = audProfile.ApplyDynamicRangeCompression; } else { return(string.Empty); } if (bitrate > 10 && jobInfo.EncodingProfile.OutFormat == OutputType.OutputDvd) { bitrate = 10; // limit DVD Audio Bitrate to 448 kbit/s } bitrate = BitrateList[bitrate]; sb.AppendFormat(" -b:a {0:0}k", bitrate); if (channels == 2 || channels == 3) { sb.Append(" -dsur_mode 1"); } if (drc) { sb.Append(" -dialnorm -27"); } sb.AppendFormat(" -vn -y \"{0}\"", outFile); return(sb.ToString()); }
private void AddJob(EncodeInfo inJob) { try { JobCollection.Add(inJob); NotifyOfPropertyChange(() => JobCollection); } catch (Exception ex) { Log.Error(ex); } }
private void DoDump(EncodeInfo job) { switch (job.Input) { case InputType.InputDvd: MPlayer mplayer = new MPlayer(); mplayer.SetJob(job); _worker.DoWork += mplayer.DoDump; Log.Info("MPlayer.DoDump()"); break; } }
/// <summary> /// Creates a new AviSynth script /// </summary> /// <param name="task"></param> /// <param name="resizeTo"></param> public void GenerateAviSynthScript(EncodeInfo task, Size resizeTo) { var sub = task.SubtitleStreams.FirstOrDefault(item => item.HardSubIntoVideo); var subFile = string.Empty; var keepOnlyForced = false; if (sub != null) { subFile = sub.TempFile; keepOnlyForced = sub.KeepOnlyForcedCaptions; } var avs = new AviSynthGenerator(_appConfig); if ((task.EncodingProfile.OutFormat == OutputType.OutputBluRay) || (task.EncodingProfile.OutFormat == OutputType.OutputAvchd)) { task.AviSynthScript = avs.Generate(task.VideoStream, false, 0f, resizeTo, StereoEncoding.None, new StereoVideoInfo(), false, subFile, keepOnlyForced, _appConfig.Use64BitEncoders && _appConfig.UseFfmpegScaling); } else { task.AviSynthScript = avs.Generate(task.VideoStream, false, 0f, resizeTo, task.EncodingProfile.StereoType, task.StereoVideoStream, false, subFile, keepOnlyForced, _appConfig.Use64BitEncoders && _appConfig.UseFfmpegScaling); if (!string.IsNullOrEmpty(avs.StereoConfigFile)) { task.AviSynthStereoConfig = avs.StereoConfigFile; } } }
private void DoEncodeAudio(EncodeInfo job) { FfMpeg ffmpeg = new FfMpeg(); OggEnc oggEnc = new OggEnc(); Lame lame = new Lame(); NeroAACEnc aacEnc = new NeroAACEnc(); switch (job.AudioProfile.Type) { case ProfileType.AC3: ffmpeg.SetJob(job); _worker.DoWork += ffmpeg.DoEncodeAc3; Log.Info("ffmpeg.DoEncodeAC3()"); break; case ProfileType.OGG: oggEnc.SetJob(job); _worker.DoWork += oggEnc.DoEncode; Log.Info("oggenc.DoEncode()"); break; case ProfileType.AAC: aacEnc.SetJob(job); _worker.DoWork += aacEnc.DoEncode; Log.Info("NeroAacEnc.DoEncode()"); break; case ProfileType.MP3: lame.SetJob(job); _worker.DoWork += lame.DoEncode; Log.Info("lame.DoEncode()"); break; case ProfileType.Copy: if (job.EncodingProfile.OutFormat == OutputType.OutputDvd && !Processing.CheckAudioDvdCompatible(job.AudioStreams[job.StreamId])) { ffmpeg.SetJob(job); _worker.DoWork += ffmpeg.DoEncodeAc3; Log.Info("ffmpeg.DoEncodeAC3()"); } break; } }
/// <summary> /// Generates commandline used for encoding an audio stream to AC-3 format. /// </summary> /// <param name="jobInfo">Container which holds all encoding profiles</param> /// <param name="inFile">Path to inputfile, can be "-" when using pipes</param> /// <param name="outFile">Path to outputfile</param> /// <returns>Commandline arguments</returns> public static string GenerateAC3EncodeLine(EncodeInfo jobInfo, string inFile, string outFile) { StringBuilder sb = new StringBuilder(); if (string.CompareOrdinal(inFile, "-") == 0) sb.Append(" -i -"); else sb.AppendFormat("-i \"{0}\"", inFile); sb.Append(" -c:a ac3"); int bitrate = 10; int channels = 0; bool drc = false; // safety check, should always be true if (jobInfo.AudioProfile.Type == ProfileType.AC3) { AC3Profile audProfile = (AC3Profile) jobInfo.AudioProfile; bitrate = audProfile.Bitrate; channels = audProfile.OutputChannels; drc = audProfile.ApplyDynamicRangeCompression; } else return string.Empty; if (bitrate > 10 && jobInfo.EncodingProfile.OutFormat == OutputType.OutputDvd) bitrate = 10; // limit DVD Audio Bitrate to 448 kbit/s bitrate = BitrateList[bitrate]; sb.AppendFormat(" -b:a {0:0}k", bitrate); if (channels == 2 || channels == 3) sb.Append(" -dsur_mode 1"); if (drc) sb.Append(" -dialnorm -27"); sb.AppendFormat(" -vn -y \"{0}\"", outFile); return sb.ToString(); }
private void DoProcessSubtitle(EncodeInfo job) { BdSup2SubTool subtool = new BdSup2SubTool(); TextSubtitleConverter converter = new TextSubtitleConverter(); switch (job.EncodingProfile.OutFormat) { case OutputType.OutputMp4: converter.SetJob(job); _worker.DoWork += converter.DoProcess; Log.Info("TextSubtitleConverter.DoProcess()"); break; default: subtool.SetJob(job); _worker.DoWork += subtool.DoProcess; Log.Info("BDSup2SubTool.DoProcess()"); break; } }
/// <summary> /// Get output resolution for encode job /// </summary> /// <param name="encodeInfo"></param> /// <returns></returns> public static Size GetTargetSize(EncodeInfo encodeInfo) { var resizeTo = new Size { Width = encodeInfo.VideoStream.Width, Height = encodeInfo.VideoStream.Height }; if ((!encodeInfo.VideoStream.CropRect.IsEmpty) && (!encodeInfo.EncodingProfile.KeepInputResolution)) { resizeTo.Height = encodeInfo.VideoStream.CropRect.Height; resizeTo.Width = encodeInfo.VideoStream.CropRect.Width; } if ((encodeInfo.EncodingProfile.OutFormat == OutputType.OutputBluRay) || (encodeInfo.EncodingProfile.OutFormat == OutputType.OutputAvchd)) { resizeTo = GetVideoDimensions(encodeInfo.VideoStream.PicSize, encodeInfo.VideoStream.AspectRatio, encodeInfo.EncodingProfile.OutFormat); } else if ((!encodeInfo.EncodingProfile.KeepInputResolution) && (encodeInfo.EncodingProfile.TargetWidth > 0)) { resizeTo.Width = encodeInfo.EncodingProfile.TargetWidth; if (!encodeInfo.VideoStream.CropRect.IsEmpty) { var aspectRatio = (double)encodeInfo.VideoStream.CropRect.Width / encodeInfo.VideoStream.CropRect.Height; resizeTo.Height = (int)Math.Ceiling(resizeTo.Width / aspectRatio); } else { resizeTo.Height = (int)Math.Ceiling(resizeTo.Width / encodeInfo.VideoStream.AspectRatio); } int temp; Math.DivRem(resizeTo.Height, 2, out temp); resizeTo.Height += temp; Math.DivRem(resizeTo.Width, 2, out temp); resizeTo.Width += temp; } return(resizeTo); }
private void CreateJob(string fileName) { var inJob = new EncodeInfo { InputFile = fileName, Input = _processingService.DetectInputType(fileName) }; if ((string.IsNullOrEmpty(inJob.InputFile)) || (inJob.Input == InputType.InputUndefined)) { return; } var streamSelect = new StreamSelectViewModel(_configService, _shellViewModel, WindowManager, _processingService) { JobInfo = inJob, }; if (WindowManager.ShowDialog(streamSelect, settings: new Dictionary <string, object> { { "ShowInTaskbar", false }, { "ResizeMode", ResizeMode.CanMinimize }, { "Title", "Select Streams" } }) != true) { return; } try { _processingService.CheckSubtitles(inJob); _processingService.CheckStreamLimit(inJob); SetOutput(inJob); SetInOutTemp(inJob); AddJob(inJob); } catch (Exception ex) { Log.Error(ex); } }
public static Size GetTargetSize(EncodeInfo encodeInfo) { Size resizeTo = new Size {Width = encodeInfo.VideoStream.Width, Height = encodeInfo.VideoStream.Height}; if ((!encodeInfo.VideoStream.CropRect.IsEmpty) && (!encodeInfo.EncodingProfile.KeepInputResolution)) { resizeTo.Height = encodeInfo.VideoStream.CropRect.Height; resizeTo.Width = encodeInfo.VideoStream.CropRect.Width; } if ((encodeInfo.EncodingProfile.OutFormat == OutputType.OutputBluRay) || (encodeInfo.EncodingProfile.OutFormat == OutputType.OutputAvchd)) resizeTo = Processing.GetVideoDimensions(encodeInfo.VideoStream.PicSize, encodeInfo.VideoStream.AspectRatio, encodeInfo.EncodingProfile.OutFormat); else if ((!encodeInfo.EncodingProfile.KeepInputResolution) && (encodeInfo.EncodingProfile.TargetWidth > 0)) { resizeTo.Width = encodeInfo.EncodingProfile.TargetWidth; if (!encodeInfo.VideoStream.CropRect.IsEmpty) { double aspectRatio = (double) encodeInfo.VideoStream.CropRect.Width/ encodeInfo.VideoStream.CropRect.Height; resizeTo.Height = (int) Math.Ceiling(resizeTo.Width/aspectRatio); } else { resizeTo.Height = (int) Math.Ceiling(resizeTo.Width/encodeInfo.VideoStream.AspectRatio); } int temp; Math.DivRem(resizeTo.Height, 2, out temp); resizeTo.Height += temp; Math.DivRem(resizeTo.Width, 2, out temp); resizeTo.Width += temp; } return resizeTo; }
/// <summary> /// Sets job for processing /// </summary> /// <param name="job">Job to process</param> public void SetJob(EncodeInfo job) { _jobInfo = job; }
/// <summary> /// Generates commandline for the eac3to executable /// </summary> /// <param name="jobInfo">Job entry to process</param> /// <returns>commandline arguments</returns> public static string GenerateDemuxLine(ref EncodeInfo jobInfo) { StringBuilder sb = new StringBuilder(); string inputFile; int startstream = 0; string ext; string formattedExt; // generate output filename depending input file given if (jobInfo.Input == InputType.InputDvd) { inputFile = jobInfo.DumpOutput; jobInfo.VideoStream.TempFile = Path.ChangeExtension(jobInfo.DumpOutput, "demuxed.mkv"); } else { inputFile = string.IsNullOrEmpty(jobInfo.TempInput) ? jobInfo.InputFile : jobInfo.TempInput; jobInfo.VideoStream.TempFile = string.IsNullOrEmpty(jobInfo.TempInput) ? Processing.CreateTempFile( string.IsNullOrEmpty(jobInfo.TempOutput) ? jobInfo.JobName : jobInfo.TempOutput, "demuxed.mkv") : Processing.CreateTempFile(jobInfo.TempInput, "demuxed.mkv"); } sb.AppendFormat("\"{0}\" {1:g}:\"{2}\" ", inputFile, jobInfo.VideoStream.StreamId + startstream, jobInfo.VideoStream.TempFile); // on stereo sources, decide if stream for right eye should be extracted if (jobInfo.StereoVideoStream.RightStreamId > 0 && jobInfo.EncodingProfile.StereoType != StereoEncoding.None) { jobInfo.StereoVideoStream.RightTempFile = Processing.CreateTempFile(jobInfo.VideoStream.TempFile, "right.h264"); jobInfo.StereoVideoStream.LeftTempFile = Processing.CreateTempFile(jobInfo.VideoStream.TempFile, "left.h264"); sb.AppendFormat("{0:g}:\"{1}\" {2:g}:\"{3}\" ", jobInfo.StereoVideoStream.LeftStreamId, jobInfo.StereoVideoStream.LeftTempFile, jobInfo.StereoVideoStream.RightStreamId, jobInfo.StereoVideoStream.RightTempFile); } // if input source is dvd, increment stream id to match eac2to stream counting if (jobInfo.Input == InputType.InputDvd) startstream++; // process all audio streams for (int i = 0; i < jobInfo.AudioStreams.Count; i++) { AudioInfo item = jobInfo.AudioStreams[i]; // get file extension for selected stream based on format and format profile ext = StreamFormat.GetFormatExtension(item.Format, item.FormatProfile, false); string core = string.Empty; // extract only core audio data for dvd output if (jobInfo.EncodingProfile.OutFormat == OutputType.OutputDvd && jobInfo.AudioProfile.Type == ProfileType.Copy) { if (string.CompareOrdinal(ext, "dtshd") == 0) { core = "-core"; ext = "dts"; } else if (string.CompareOrdinal(ext, "truehd") == 0) { core = "-core"; ext = "ac3"; } } formattedExt = string.Format("demuxed.{0:g}.{1}.{2}", item.StreamId, item.LangCode, ext); switch (jobInfo.Input) { case InputType.InputDvd: item.TempFile = Processing.CreateTempFile(jobInfo.DumpOutput, formattedExt); break; default: item.TempFile = string.IsNullOrEmpty(jobInfo.TempInput) ? Processing.CreateTempFile( string.IsNullOrEmpty(jobInfo.TempOutput) ? jobInfo.JobName : jobInfo.TempOutput, formattedExt) : Processing.CreateTempFile(jobInfo.TempInput, formattedExt); break; } sb.AppendFormat("{0:g}:\"{1}\" {2} ", item.Id + startstream, item.TempFile, core); jobInfo.AudioStreams[i] = item; } // process all subtitle streams for (int i = 0; i < jobInfo.SubtitleStreams.Count; i++) { SubtitleInfo item = jobInfo.SubtitleStreams[i]; ext = StreamFormat.GetFormatExtension(item.Format, String.Empty, false); formattedExt = string.Format("demuxed.{0:g}.{1}.{2}", item.StreamId, item.LangCode, ext); switch (jobInfo.Input) { case InputType.InputDvd: item.TempFile = Processing.CreateTempFile(jobInfo.DumpOutput, formattedExt); break; default: item.TempFile = string.IsNullOrEmpty(jobInfo.TempInput) ? Processing.CreateTempFile( string.IsNullOrEmpty(jobInfo.TempOutput) ? jobInfo.JobName : jobInfo.TempOutput, formattedExt) : Processing.CreateTempFile(jobInfo.TempInput, formattedExt); break; } sb.AppendFormat("{0:g}:\"{1}\" ", item.Id + startstream, item.TempFile); jobInfo.SubtitleStreams[i] = item; } // add logfile to tempfiles list for deletion jobInfo.TempFiles.Add( jobInfo.VideoStream.TempFile.Substring(0, jobInfo.VideoStream.TempFile.LastIndexOf('.')) + " - Log.txt"); if (jobInfo.Input == InputType.InputDvd) jobInfo.TempFiles.Add(jobInfo.DumpOutput); sb.Append("-progressNumbers -no2ndpass "); return sb.ToString(); }