/// <summary> /// Start with a LibHb EncodeJob Object /// </summary> /// <param name="task"> /// The task. /// </param> /// <param name="configuration"> /// The configuration. /// </param> public void Start(EncodeTask task, HBConfiguration configuration) { try { // Sanity Checking and Setup if (this.IsEncoding) { throw new GeneralApplicationException("HandBrake is already encoding a file.", "Please stop the current encode. If the problem persists, please restart HandBrake.", null); } // Setup this.startTime = DateTime.Now; this.currentTask = task; this.currentConfiguration = configuration; // Create a new HandBrake instance // Setup the HandBrake Instance HandBrakeUtils.MessageLogged += this.HandBrakeInstanceMessageLogged; HandBrakeUtils.ErrorLogged += this.HandBrakeInstanceErrorLogged; this.instance = task.IsPreviewEncode ? HandBrakeInstanceManager.GetPreviewInstance(configuration.Verbosity) : HandBrakeInstanceManager.GetEncodeInstance(configuration.Verbosity); this.instance.EncodeCompleted += this.InstanceEncodeCompleted; this.instance.EncodeProgress += this.InstanceEncodeProgress; this.IsEncoding = true; this.isPreviewInstance = task.IsPreviewEncode; this.SetupLogging(task.IsPreviewEncode); // Verify the Destination Path Exists, and if not, create it. this.VerifyEncodeDestinationPath(task); this.ServiceLogMessage("Starting Encode ..."); // Get an EncodeJob object for the Interop Library this.instance.StartEncode(EncodeFactory.Create(task, configuration)); // 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 HandBrakeWPF.Services.Encode.EventArgs.EncodeCompletedEventArgs(false, exc, "Unable to start encoding", task.Source)); } }
/// <summary> /// Start with a LibHb EncodeJob Object /// </summary> /// <param name="job"> /// The job. /// </param> public void Start(QueueTask job) { // Setup this.startTime = DateTime.Now; this.currentTask = job; // Create a new HandBrake instance // Setup the HandBrake Instance HandBrakeUtils.MessageLogged += this.HandBrakeInstanceMessageLogged; HandBrakeUtils.ErrorLogged += this.HandBrakeInstanceErrorLogged; this.instance = HandBrakeInstanceManager.GetEncodeInstance(job.Configuration.Verbosity); this.instance.EncodeCompleted += this.InstanceEncodeCompleted; this.instance.EncodeProgress += this.InstanceEncodeProgress; try { // Sanity Checking and Setup if (this.IsEncoding) { throw new Exception("HandBrake is already encoding."); } this.IsEncoding = true; // Enable logging if required. try { this.SetupLogging(job, true); } catch (Exception) { this.IsEncoding = false; throw; } // Verify the Destination Path Exists, and if not, create it. this.VerifyEncodeDestinationPath(job); // We have to scan the source again but only the title so the HandBrake instance is initialised correctly. // Since the UI sends the crop params down, we don't have to do all the previews. this.instance.ScanCompleted += delegate { // Process into internal structures. this.scannedSource = new Source { Titles = LibScan.ConvertTitles(this.instance.Titles, this.instance.FeatureTitle) }; // TODO work around the bad Internal API. this.ScanCompleted(job, this.instance); }; HandBrakeUtils.SetDvdNav(!job.Configuration.IsDvdNavDisabled); ServiceLogMessage("Scanning title for encoding ... "); this.instance.StartScan(job.ScannedSourcePath, job.Configuration.PreviewScanCount, TimeSpan.FromSeconds(job.Configuration.MinScanDuration), job.Task.Title); } catch (Exception exc) { ServiceLogMessage("Scan Failed ... " + Environment.NewLine + exc); this.InvokeEncodeCompleted(new EventArgs.EncodeCompletedEventArgs(false, exc, "An Error has occured.", this.currentTask.Task.Destination)); } }
/// <summary> /// Start with a LibHb EncodeJob Object /// </summary> /// <param name="task"> /// The task. /// </param> /// <param name="configuration"> /// The configuration. /// </param> public void Start(EncodeTask task, HBConfiguration configuration) { 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; // Create a new HandBrake instance // Setup the HandBrake Instance this.log.Reset(); // Reset so we have a clean log for the start of the encode. this.ServiceLogMessage("Starting Encode ..."); HandBrakeUtils.SetDvdNav(!configuration.IsDvdNavDisabled); this.instance = task.IsPreviewEncode ? HandBrakeInstanceManager.GetPreviewInstance(configuration.Verbosity) : HandBrakeInstanceManager.GetEncodeInstance(configuration.Verbosity); 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(EncodeFactory.Create(task, configuration)); // 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", task.Source, null, 0)); } }
/// <summary> /// Start with a LibHb EncodeJob Object /// </summary> /// <param name="task"> /// The task. /// </param> /// <param name="configuration"> /// The configuration. /// </param> public void Start(EncodeTask task, HBConfiguration configuration) { try { // Setup this.startTime = DateTime.Now; this.currentTask = task; this.currentConfiguration = configuration; // Create a new HandBrake instance // Setup the HandBrake Instance HandBrakeUtils.MessageLogged += this.HandBrakeInstanceMessageLogged; HandBrakeUtils.ErrorLogged += this.HandBrakeInstanceErrorLogged; this.instance = HandBrakeInstanceManager.GetEncodeInstance(configuration.Verbosity); this.instance.EncodeCompleted += this.InstanceEncodeCompleted; this.instance.EncodeProgress += this.InstanceEncodeProgress; // Sanity Checking and Setup if (this.IsEncoding) { throw new Exception("HandBrake is already encoding."); } this.IsEncoding = true; this.SetupLogging(); // Verify the Destination Path Exists, and if not, create it. this.VerifyEncodeDestinationPath(task); this.ServiceLogMessage("Starting Encode ..."); // Get an EncodeJob object for the Interop Library this.instance.StartEncode(EncodeFactory.Create(task, configuration)); // Fire the Encode Started Event this.InvokeEncodeStarted(System.EventArgs.Empty); // Set the Process Priority switch (configuration.ProcessPriority) { case "Realtime": Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.RealTime; break; case "High": Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.High; break; case "Above Normal": Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.AboveNormal; break; case "Normal": Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.Normal; break; case "Low": Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.Idle; break; default: Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.BelowNormal; break; } } catch (Exception exc) { this.IsEncoding = false; this.ServiceLogMessage("Failed to start encoding ..." + Environment.NewLine + exc); this.InvokeEncodeCompleted(new HandBrakeWPF.Services.Encode.EventArgs.EncodeCompletedEventArgs(false, exc, "Unable to start encoding", task.Source)); } }