/// <summary> /// Initializes a new instance of the <see cref="AudioDefaultsViewModel"/> class. /// </summary> /// <param name="task"> /// The task. /// </param> public AudioDefaultsViewModel(EncodeTask task) { this.Task = task; this.AudioBehaviours = new AudioBehaviours(); this.SelectedAvailableToMove = new BindingList<string>(); this.SelectedLangaugesToMove = new BindingList<string>(); this.AvailableLanguages = new BindingList<string>(); this.AudioEncoders = EnumHelper<AudioEncoder>.GetEnumList(); this.Setup((Preset)null, task); }
/// <summary> /// Gets a value indicating whether M4v extension is required. /// </summary> /// <param name="task"> /// The task. /// </param> /// <returns> /// The <see cref="bool"/> to indicate if this task requires m4v extension /// </returns> public static bool RequiresM4v(EncodeTask task) { if (task.OutputFormat == OutputFormat.Mp4) { bool audio = task.AudioTracks.Any( item => item.Encoder == AudioEncoder.Ac3Passthrough || item.Encoder == AudioEncoder.Ac3 || item.Encoder == AudioEncoder.DtsPassthrough || item.Encoder == AudioEncoder.Passthrough); bool subtitles = task.SubtitleTracks.Any(track => track.SubtitleType != SubtitleType.VobSub); return audio || subtitles; } return false; }
/// <summary> /// Initializes a new instance of the <see cref="AudioDefaultsViewModel"/> class. /// </summary> /// <param name="task"> /// The task. /// </param> public AudioDefaultsViewModel(EncodeTask task) { this.Task = task; this.AudioBehaviours = new AudioBehaviours(); this.SelectedAvailableToMove = new BindingList<string>(); this.SelectedLangaugesToMove = new BindingList<string>(); this.AvailableLanguages = new BindingList<string>(); this.AudioEncoders = EnumHelper<AudioEncoder>.GetEnumList(); this.Mixdowns = new BindingList<HBMixdown>(HandBrakeEncoderHelpers.Mixdowns); this.SampleRates = new ObservableCollection<string> { "Auto" }; foreach (var item in HandBrakeEncoderHelpers.AudioSampleRates) { this.SampleRates.Add(item.Name); } this.Setup((Preset)null, task); }
/// <summary> /// The setup languages. /// </summary> /// <param name="preset"> /// The preset. /// </param> /// <param name="task"> /// The task. /// </param> public void Setup(Preset preset, EncodeTask task) { // Reset this.AudioBehaviours = new AudioBehaviours(); // Setup for this Encode Task. this.Task = task; IDictionary<string, string> langList = LanguageUtilities.MapLanguages(); langList = (from entry in langList orderby entry.Key ascending select entry).ToDictionary(pair => pair.Key, pair => pair.Value); this.AvailableLanguages.Clear(); foreach (string item in langList.Keys) { this.AvailableLanguages.Add(item); } // Handle the Preset, if it's not null. if (preset == null) { return; } AudioBehaviours behaviours = preset.AudioTrackBehaviours.Clone(); if (behaviours != null) { this.AudioBehaviours.SelectedBehaviour = behaviours.SelectedBehaviour; this.AudioBehaviours.SelectedTrackDefaultBehaviour = behaviours.SelectedTrackDefaultBehaviour; foreach (AudioBehaviourTrack item in preset.AudioTrackBehaviours.BehaviourTracks) { this.BehaviourTracks.Add(new AudioBehaviourTrack(item)); } this.NotifyOfPropertyChange(() => this.BehaviourTracks); foreach (string selectedItem in behaviours.SelectedLangauges) { this.AvailableLanguages.Remove(selectedItem); this.AudioBehaviours.SelectedLangauges.Add(selectedItem); } } this.task.AllowedPassthruOptions = new AllowedPassthru(preset.Task.AllowedPassthruOptions); this.NotifyOfPropertyChange(() => this.AudioAllowMP3Pass); this.NotifyOfPropertyChange(() => this.AudioAllowAACPass); this.NotifyOfPropertyChange(() => this.AudioAllowAC3Pass); this.NotifyOfPropertyChange(() => this.AudioAllowEAC3Pass); this.NotifyOfPropertyChange(() => this.AudioAllowDTSPass); this.NotifyOfPropertyChange(() => this.AudioAllowDTSHDPass); this.NotifyOfPropertyChange(() => this.AudioAllowTrueHDPass); this.NotifyOfPropertyChange(() => this.AudioAllowFlacPass); this.NotifyOfPropertyChange(() => this.AudioEncoderFallback); }
/// <summary> /// Initializes a new instance of the <see cref="EncodeTask"/> class. /// Copy Constructor /// </summary> /// <param name="task"> /// The task. /// </param> public EncodeTask(EncodeTask task) { this.AdvancedEncoderOptions = task.AdvancedEncoderOptions; this.AllowedPassthruOptions = new AllowedPassthru(task.AllowedPassthruOptions); this.Anamorphic = task.Anamorphic; this.Angle = task.Angle; this.AudioTracks = new ObservableCollection<AudioTrack>(); foreach (AudioTrack track in task.AudioTracks) { this.AudioTracks.Add(new AudioTrack(track, true)); } this.ChapterNames = new ObservableCollection<ChapterMarker>(); foreach (ChapterMarker track in task.ChapterNames) { this.ChapterNames.Add(new ChapterMarker(track)); } this.ChapterMarkersFilePath = task.ChapterMarkersFilePath; this.Cropping = new Cropping(task.Cropping); this.CustomDecomb = task.CustomDecomb; this.CustomDeinterlace = task.CustomDeinterlace; this.CustomDenoise = task.CustomDenoise; this.CustomDetelecine = task.CustomDetelecine; this.Deblock = task.Deblock; this.Decomb = task.Decomb; this.Deinterlace = task.Deinterlace; this.DeinterlaceFilter = task.DeinterlaceFilter; this.Denoise = task.Denoise; this.DenoisePreset = task.DenoisePreset; this.DenoiseTune = task.DenoiseTune; this.Destination = task.Destination; this.Detelecine = task.Detelecine; this.DisplayWidth = task.DisplayWidth; this.EndPoint = task.EndPoint; this.Framerate = task.Framerate; this.FramerateMode = task.FramerateMode; this.Grayscale = task.Grayscale; this.HasCropping = task.HasCropping; this.Height = task.Height; this.IncludeChapterMarkers = task.IncludeChapterMarkers; this.IPod5GSupport = task.IPod5GSupport; this.KeepDisplayAspect = task.KeepDisplayAspect; this.MaxHeight = task.MaxHeight; this.MaxWidth = task.MaxWidth; this.Modulus = task.Modulus; this.OptimizeMP4 = task.OptimizeMP4; this.OutputFormat = task.OutputFormat; this.PixelAspectX = task.PixelAspectX; this.PixelAspectY = task.PixelAspectY; this.PointToPointMode = task.PointToPointMode; this.Quality = task.Quality; this.Source = task.Source; this.StartPoint = task.StartPoint; this.SubtitleTracks = new ObservableCollection<SubtitleTrack>(); foreach (SubtitleTrack subtitleTrack in task.SubtitleTracks) { this.SubtitleTracks.Add(new SubtitleTrack(subtitleTrack)); } this.Title = task.Title; this.TurboFirstPass = task.TurboFirstPass; this.TwoPass = task.TwoPass; this.VideoBitrate = task.VideoBitrate; this.VideoEncoder = task.VideoEncoder; this.VideoEncodeRateType = task.VideoEncodeRateType; this.Width = task.Width; this.VideoLevel = task.VideoLevel; this.VideoProfile = task.VideoProfile; this.VideoPreset = task.VideoPreset; this.VideoTunes = task.VideoTunes; this.ExtraAdvancedArguments = task.ExtraAdvancedArguments; this.ShowAdvancedTab = task.ShowAdvancedTab; }
/// <summary> /// Set the selected preset /// </summary> /// <param name="preset"> /// The preset. /// </param> /// <param name="encodeTask"> /// The task. /// </param> public void SetPreset(Preset preset, EncodeTask encodeTask) { this.Task = encodeTask; }
/// <summary> /// Update all the UI controls based on the encode task passed in. /// </summary> /// <param name="encodeTask"> /// The task. /// </param> public void UpdateTask(EncodeTask encodeTask) { this.Task = encodeTask; }
/// <summary> /// Setup the window after a scan. /// </summary> /// <param name="source"> /// The source. /// </param> /// <param name="selectedTitle"> /// The selected title. /// </param> /// <param name="currentPreset"> /// The Current preset /// </param> /// <param name="encodeTask"> /// The task. /// </param> public void SetSource(Source source, Title selectedTitle, Preset currentPreset, EncodeTask encodeTask) { this.Task = encodeTask; }
/// <summary> /// Function which generates the filename and path automatically based on /// the Source Name, DVD title and DVD Chapters /// </summary> /// <param name="task"> /// The task. /// </param> /// <param name="sourceOrLabelName"> /// The Source or Label Name /// </param> /// <param name="presetName"> /// The preset Name. /// </param> /// <returns> /// The Generated FileName /// </returns> public static string AutoName(EncodeTask task, string sourceOrLabelName, Preset presetName) { IUserSettingService userSettingService = IoC.Get <IUserSettingService>(); if (task.Destination == null) { task.Destination = string.Empty; } string autoNamePath = string.Empty; if (task.Title != 0) { // Get the Source Name and remove any invalid characters string sourceName = Path.GetInvalidFileNameChars().Aggregate(sourceOrLabelName, (current, character) => current.Replace(character.ToString(), string.Empty)); // Remove Underscores if (userSettingService.GetUserSetting <bool>(UserSettingConstants.AutoNameRemoveUnderscore)) { sourceName = sourceName.Replace("_", " "); } if (userSettingService.GetUserSetting <bool>(UserSettingConstants.RemovePunctuation)) { sourceName = sourceName.Replace("-", string.Empty); sourceName = sourceName.Replace(",", string.Empty); sourceName = sourceName.Replace(".", string.Empty); } // Switch to "Title Case" if (userSettingService.GetUserSetting <bool>(UserSettingConstants.AutoNameTitleCase)) { sourceName = sourceName.ToTitleCase(); } // Get the Selected Title Number string dvdTitle = task.Title.ToString(); // Get the Chapter Start and Chapter End Numbers string chapterStart = task.StartPoint.ToString(); string chapterFinish = task.EndPoint.ToString(); string combinedChapterTag = chapterStart; if (chapterFinish != chapterStart && chapterFinish != string.Empty) { combinedChapterTag = chapterStart + "-" + chapterFinish; } // Local method to check if we have a creation time in the meta data. If not, fall back to source file creation time. DateTime obtainCreateDateObject() { var rd = task.MetaData.ReleaseDate; if (DateTime.TryParse(rd, out var d)) { return(d); } try { return(File.GetCreationTime(task.Source)); } catch (Exception e) { if (e is UnauthorizedAccessException || e is PathTooLongException || e is NotSupportedException) { // Suspect the most likely concerns trying to grab the creation date in which we would want to swallow exception. return(default(DateTime)); } throw e; } } var creationDateTime = obtainCreateDateObject(); string createDate = creationDateTime.Date.ToShortDateString().Replace('/', '-'); string createTime = creationDateTime.ToString("HH-mm"); /* * File Name */ string destinationFilename; if (userSettingService.GetUserSetting <string>(UserSettingConstants.AutoNameFormat) != string.Empty) { destinationFilename = userSettingService.GetUserSetting <string>(UserSettingConstants.AutoNameFormat); destinationFilename = destinationFilename .RegexReplace(Constants.Source, sourceName) .RegexReplace(Constants.Title, dvdTitle) .RegexReplace(Constants.Chapters, combinedChapterTag) .RegexReplace(Constants.Date, DateTime.Now.Date.ToShortDateString().Replace('/', '-')) .RegexReplace(Constants.Time, DateTime.Now.ToString("HH-mm")) .RegexReplace(Constants.CretaionDate, createDate) .RegexReplace(Constants.CreationTime, createTime); if (task.VideoEncodeRateType == VideoEncodeRateType.ConstantQuality) { destinationFilename = destinationFilename.Replace(Constants.Quality, task.Quality.ToString()); destinationFilename = destinationFilename.Replace(Constants.Bitrate, string.Empty); } else { destinationFilename = destinationFilename.Replace( Constants.Bitrate, task.VideoBitrate.ToString()); destinationFilename = destinationFilename.Replace(Constants.Quality, string.Empty); } } else { destinationFilename = sourceName + "_T" + dvdTitle + "_C" + combinedChapterTag; } /* * File Extension */ if (task.OutputFormat == OutputFormat.Mp4) { switch (userSettingService.GetUserSetting <int>(UserSettingConstants.UseM4v, typeof(int))) { case 0: // Automatic destinationFilename += task.IncludeChapterMarkers || MP4Helper.RequiresM4v(task) ? ".m4v" : ".mp4"; break; case 1: // Always MP4 destinationFilename += ".mp4"; break; case 2: // Always M4V destinationFilename += ".m4v"; break; } } else if (task.OutputFormat == OutputFormat.Mkv) { destinationFilename += ".mkv"; } /* * File Destination Path */ // If there is an auto name path, use it... if (userSettingService.GetUserSetting <string>(UserSettingConstants.AutoNamePath).Trim().StartsWith("{source_path}") && !string.IsNullOrEmpty(task.Source)) { string savedPath = userSettingService.GetUserSetting <string>(UserSettingConstants.AutoNamePath).Trim().Replace("{source_path}\\", string.Empty).Replace("{source_path}", string.Empty); string directory = Directory.Exists(task.Source) ? task.Source : Path.GetDirectoryName(task.Source); string requestedPath = Path.Combine(directory, savedPath); autoNamePath = Path.Combine(requestedPath, destinationFilename); if (autoNamePath == task.Source) { // Append out_ to files that already exist or is the source file autoNamePath = Path.Combine(Path.GetDirectoryName(task.Source), "output_" + destinationFilename); } } else if (userSettingService.GetUserSetting <string>(UserSettingConstants.AutoNamePath).Contains("{source_folder_name}") && !string.IsNullOrEmpty(task.Source)) { // Second Case: We have a Path, with "{source_folder}" in it, therefore we need to replace it with the folder name from the source. string path = Path.GetDirectoryName(task.Source); if (!string.IsNullOrEmpty(path)) { string[] filesArray = path.Split(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar); string sourceFolder = filesArray[filesArray.Length - 1]; autoNamePath = Path.Combine(userSettingService.GetUserSetting <string>(UserSettingConstants.AutoNamePath).Replace("{source_folder_name}", sourceFolder), destinationFilename); } } else if (!task.Destination.Contains(Path.DirectorySeparatorChar.ToString())) { // Third case: If the destination box doesn't already contain a path, make one. if (userSettingService.GetUserSetting <string>(UserSettingConstants.AutoNamePath).Trim() != string.Empty && userSettingService.GetUserSetting <string>(UserSettingConstants.AutoNamePath).Trim() != "Click 'Browse' to set the default location") { autoNamePath = Path.Combine(userSettingService.GetUserSetting <string>(UserSettingConstants.AutoNamePath), destinationFilename); } else { // ...otherwise, output to the source directory autoNamePath = null; } } else { // Otherwise, use the path that is already there. // Use the path and change the file extension to match the previous destination autoNamePath = Path.Combine(Path.GetDirectoryName(task.Destination), destinationFilename); } } return(autoNamePath); }
/// <summary> /// Edit a Queue Task /// </summary> /// <param name="task"> /// The task. /// </param> public void EditQueueJob(EncodeTask task) { // Rescan the source to make sure it's still valid this.queueEditTask = task; this.scanService.Scan(task.Source, task.Title, QueueEditAction, HBConfigurationFactory.Create()); }
/// <summary> /// Initializes a new instance of the <see cref="EncodeTask"/> class. /// Copy Constructor /// </summary> /// <param name="task"> /// The task. /// </param> public EncodeTask(EncodeTask task) { this.AdvancedEncoderOptions = task.AdvancedEncoderOptions; this.AllowedPassthruOptions = new AllowedPassthru(task.AllowedPassthruOptions); this.Anamorphic = task.Anamorphic; this.Angle = task.Angle; this.AudioTracks = new ObservableCollection <AudioTrack>(); foreach (AudioTrack track in task.AudioTracks) { this.AudioTracks.Add(new AudioTrack(track, true)); } this.ChapterNames = new ObservableCollection <ChapterMarker>(); foreach (ChapterMarker track in task.ChapterNames) { this.ChapterNames.Add(new ChapterMarker(track)); } this.ChapterMarkersFilePath = task.ChapterMarkersFilePath; this.Cropping = new Cropping(task.Cropping); this.CustomDecomb = task.CustomDecomb; this.CustomDeinterlace = task.CustomDeinterlace; this.CustomDenoise = task.CustomDenoise; this.CustomDetelecine = task.CustomDetelecine; this.Deblock = task.Deblock; this.Decomb = task.Decomb; this.Deinterlace = task.Deinterlace; this.DeinterlaceFilter = task.DeinterlaceFilter; this.Denoise = task.Denoise; this.DenoisePreset = task.DenoisePreset; this.DenoiseTune = task.DenoiseTune; this.Destination = task.Destination; this.Detelecine = task.Detelecine; this.DisplayWidth = task.DisplayWidth; this.EndPoint = task.EndPoint; this.Framerate = task.Framerate; this.FramerateMode = task.FramerateMode; this.Grayscale = task.Grayscale; this.HasCropping = task.HasCropping; this.Height = task.Height; this.IncludeChapterMarkers = task.IncludeChapterMarkers; this.IPod5GSupport = task.IPod5GSupport; this.KeepDisplayAspect = task.KeepDisplayAspect; this.MaxHeight = task.MaxHeight; this.MaxWidth = task.MaxWidth; this.Modulus = task.Modulus; this.OptimizeMP4 = task.OptimizeMP4; this.OutputFormat = task.OutputFormat; this.PixelAspectX = task.PixelAspectX; this.PixelAspectY = task.PixelAspectY; this.PointToPointMode = task.PointToPointMode; this.Quality = task.Quality; this.Source = task.Source; this.StartPoint = task.StartPoint; this.SubtitleTracks = new ObservableCollection <SubtitleTrack>(); foreach (SubtitleTrack subtitleTrack in task.SubtitleTracks) { this.SubtitleTracks.Add(new SubtitleTrack(subtitleTrack)); } this.Title = task.Title; this.TurboFirstPass = task.TurboFirstPass; this.TwoPass = task.TwoPass; this.VideoBitrate = task.VideoBitrate; this.VideoEncoder = task.VideoEncoder; this.VideoEncodeRateType = task.VideoEncodeRateType; this.Width = task.Width; this.VideoLevel = task.VideoLevel; this.VideoProfile = task.VideoProfile; this.VideoPreset = task.VideoPreset; this.VideoTunes = new List <VideoTune>(task.VideoTunes); this.ExtraAdvancedArguments = task.ExtraAdvancedArguments; this.ShowAdvancedTab = task.ShowAdvancedTab; }
public EncodeTask(EncodeTask task) { /* Source */ this.Source = task.Source; this.StartPoint = task.StartPoint; this.Title = task.Title; this.Angle = task.Angle; this.EndPoint = task.EndPoint; this.PointToPointMode = task.PointToPointMode; /* Audio */ this.AudioPassthruOptions = new AllowedPassthru(task.AudioPassthruOptions); this.AudioTracks = new ObservableCollection <AudioTrack>(); foreach (AudioTrack track in task.AudioTracks) { this.AudioTracks.Add(new AudioTrack(track, true)); } /* Chapters */ this.ChapterNames = new ObservableCollection <ChapterMarker>(); foreach (ChapterMarker track in task.ChapterNames) { this.ChapterNames.Add(new ChapterMarker(track)); } this.IncludeChapterMarkers = task.IncludeChapterMarkers; this.ChapterMarkersFilePath = task.ChapterMarkersFilePath; /* Subtitles */ this.SubtitleTracks = new ObservableCollection <SubtitleTrack>(); foreach (SubtitleTrack subtitleTrack in task.SubtitleTracks) { this.SubtitleTracks.Add(new SubtitleTrack(subtitleTrack)); } /* Filter Settings */ this.CustomDeinterlaceSettings = task.CustomDeinterlaceSettings; this.CustomDenoise = task.CustomDenoise; this.CustomDetelecine = task.CustomDetelecine; this.CustomCombDetect = task.CustomCombDetect; this.CombDetect = task.CombDetect; this.DeblockPreset = task.DeblockPreset; this.DeblockTune = task.DeblockTune; this.CustomDeblock = task.CustomDeblock; this.DeinterlacePreset = task.DeinterlacePreset; this.DeinterlaceFilter = task.DeinterlaceFilter; this.Denoise = task.Denoise; this.DenoisePreset = task.DenoisePreset; this.DenoiseTune = task.DenoiseTune; this.Destination = task.Destination; this.Detelecine = task.Detelecine; this.Sharpen = task.Sharpen; this.SharpenPreset = task.SharpenPreset; this.SharpenTune = task.SharpenTune; this.SharpenCustom = task.SharpenCustom; this.Colourspace = task.Colourspace; this.CustomColourspace = task.CustomColourspace; this.ChromaSmooth = task.ChromaSmooth; this.ChromaSmoothTune = task.ChromaSmoothTune; this.CustomChromaSmooth = task.CustomChromaSmooth; this.Grayscale = task.Grayscale; /* Picture Settings*/ this.DisplayWidth = task.DisplayWidth; this.MaxHeight = task.MaxHeight; this.MaxWidth = task.MaxWidth; this.Width = task.Width; this.Height = task.Height; this.AllowUpscaling = task.AllowUpscaling; this.OptimalSize = task.OptimalSize; this.HasCropping = task.HasCropping; this.PixelAspectX = task.PixelAspectX; this.PixelAspectY = task.PixelAspectY; this.Cropping = new Cropping(task.Cropping); this.Padding = task.Padding; this.FlipVideo = task.FlipVideo; this.Rotation = task.Rotation; this.Anamorphic = task.Anamorphic; this.KeepDisplayAspect = task.KeepDisplayAspect; /* Video */ this.Quality = task.Quality; this.Framerate = task.Framerate; this.FramerateMode = task.FramerateMode; this.TurboFirstPass = task.TurboFirstPass; this.TwoPass = task.TwoPass; this.VideoBitrate = task.VideoBitrate; this.VideoEncoder = task.VideoEncoder; this.VideoEncodeRateType = task.VideoEncodeRateType; this.VideoLevel = task.VideoLevel; this.VideoProfile = task.VideoProfile; this.VideoPreset = task.VideoPreset; this.VideoTunes = new List <VideoTune>(task.VideoTunes); this.ExtraAdvancedArguments = task.ExtraAdvancedArguments; /* Container */ this.IPod5GSupport = task.IPod5GSupport; this.OutputFormat = task.OutputFormat; this.OptimizeMP4 = task.OptimizeMP4; /* Other */ this.MetaData = new MetaData(task.MetaData); }
private static string CheckAndHandleFilenameCollisions(string autoNamePath, string destinationFilename, EncodeTask task, IUserSettingService userSettingService) { AutonameFileCollisionBehaviour behaviour = (AutonameFileCollisionBehaviour)userSettingService.GetUserSetting <int>(UserSettingConstants.AutonameFileCollisionBehaviour, typeof(int)); string prefix = string.Empty, postfix = string.Empty; switch (behaviour) { case AutonameFileCollisionBehaviour.Postfix: postfix = userSettingService.GetUserSetting <string>(UserSettingConstants.AutonameFilePrePostString); break; case AutonameFileCollisionBehaviour.Prefix: prefix = userSettingService.GetUserSetting <string>(UserSettingConstants.AutonameFilePrePostString); break; } string extension = Path.GetExtension(destinationFilename); string filenameWithoutExt = Path.GetFileNameWithoutExtension(destinationFilename); if (behaviour != AutonameFileCollisionBehaviour.AppendNumber) { if (autoNamePath?.ToLower() == task.Source?.ToLower()) { autoNamePath = Path.Combine(Path.GetDirectoryName(task.Source), prefix + filenameWithoutExt + postfix + extension); int counter = 0; while (File.Exists(autoNamePath)) { counter = counter + 1; string appendedNumber = string.Format("({0})", counter); autoNamePath = Path.Combine(Path.GetDirectoryName(task.Source), prefix + filenameWithoutExt + postfix + appendedNumber + extension); } } } else { int counter = 0; while (File.Exists(autoNamePath)) { counter = counter + 1; string appendedNumber = string.Format("({0})", counter); autoNamePath = Path.Combine(Path.GetDirectoryName(task.Source), filenameWithoutExt + appendedNumber + extension); } } return(autoNamePath); }
public void Start(EncodeTask task, HBConfiguration configuration, string basePresetName) { try { // Sanity Checking and Setup if (this.IsEncoding) { throw new GeneralApplicationException(Resources.Queue_AlreadyEncoding, Resources.Queue_AlreadyEncodingSolution, null); } // Setup this.startTime = DateTime.Now; this.currentTask = task; this.currentConfiguration = configuration; if (this.userSettingService.GetUserSetting <bool>(UserSettingConstants.ProcessIsolationEnabled)) { this.InitLogging(task.IsPreviewEncode); } else { this.encodeLogService = this.logInstanceManager.MasterLogInstance; this.encodeLogService.Reset(); } if (this.instance != null) { // Cleanup try { this.instance.EncodeCompleted -= this.InstanceEncodeCompleted; this.instance.EncodeProgress -= this.InstanceEncodeProgress; this.instance.Dispose(); this.instance = null; } catch (Exception exc) { this.ServiceLogMessage("Failed to cleanup previous instance: " + exc); } } this.ServiceLogMessage("Starting Encode ..."); if (!string.IsNullOrEmpty(basePresetName)) { this.TimedLogMessage(string.Format("base preset: {0}", basePresetName)); } int verbosity = this.userSettingService.GetUserSetting <int>(UserSettingConstants.Verbosity); // Prevent port stealing if multiple jobs start at the same time. lock (portLock) { this.instance = task.IsPreviewEncode ? HandBrakeInstanceManager.GetPreviewInstance(verbosity, this.userSettingService) : HandBrakeInstanceManager.GetEncodeInstance(verbosity, configuration, this.encodeLogService, userSettingService); this.instance.EncodeCompleted += this.InstanceEncodeCompleted; this.instance.EncodeProgress += this.InstanceEncodeProgress; this.IsEncoding = true; this.isPreviewInstance = task.IsPreviewEncode; // Verify the Destination Path Exists, and if not, create it. this.VerifyEncodeDestinationPath(task); // Get an EncodeJob object for the Interop Library this.instance.StartEncode(EncodeTaskFactory.Create(task, configuration, hbFunctionsProvider.GetHbFunctionsWrapper())); } // Fire the Encode Started Event this.InvokeEncodeStarted(System.EventArgs.Empty); } catch (Exception exc) { this.IsEncoding = false; this.ServiceLogMessage("Failed to start encoding ..." + Environment.NewLine + exc); this.InvokeEncodeCompleted(new EventArgs.EncodeCompletedEventArgs(false, exc, "Unable to start encoding", this.currentTask.Source, this.currentTask.Destination, null, 0)); } }