Пример #1
0
        private void GeneratePreviewImpl()
        {
            this.job = this.mainViewModel.EncodeJob;

            this.PreviewPercentComplete = 0;
            this.EncodeState            = PreviewEncodeState.EncodeStarting;
            this.cancelPending          = false;
            this.encodeCancelled        = false;

            this.SetPreviewFilePath();

            this.job.OutputPath = this.previewFilePath;

            if (this.job.Subtitles?.SourceSubtitles != null)
            {
                SourceSubtitle scanTrack = this.job.Subtitles.SourceSubtitles.FirstOrDefault(s => s.TrackNumber == 0);
                if (scanTrack != null)
                {
                    this.job.Subtitles.SourceSubtitles.Remove(scanTrack);
                }
            }

            this.encodeProxy = Utilities.CreateEncodeProxy();
            this.encodeProxy.EncodeStarted += (o, e) =>
            {
                DispatchUtilities.BeginInvoke(() =>
                {
                    this.EncodeState = PreviewEncodeState.Encoding;
                    if (this.cancelPending)
                    {
                        this.CancelPreviewImpl();
                    }
                });
            };
            this.encodeProxy.EncodeProgress += (o, e) =>
            {
                double totalWeight;
                double completeWeight;
                if (e.PassCount == 1)
                {
                    // Single pass, no subtitle scan
                    totalWeight    = 1;
                    completeWeight = e.FractionComplete;
                }
                else if (e.PassCount == 2 && e.PassId <= 0)
                {
                    // Single pass with subtitle scan
                    totalWeight = 1 + SubtitleScanCost;
                    if (e.PassId == -1)
                    {
                        // In subtitle scan
                        completeWeight = e.FractionComplete * SubtitleScanCost;
                    }
                    else
                    {
                        // In normal pass
                        completeWeight = SubtitleScanCost + e.FractionComplete;
                    }
                }
                else if (e.PassCount == 2 && e.PassId >= 1)
                {
                    // Two normal passes
                    totalWeight = 2;

                    if (e.PassId == 1)
                    {
                        // First pass
                        completeWeight = e.FractionComplete;
                    }
                    else
                    {
                        // Second pass
                        completeWeight = 1 + e.FractionComplete;
                    }
                }
                else
                {
                    // Two normal passes with subtitle scan
                    totalWeight = 2 + SubtitleScanCost;

                    if (e.PassId == -1)
                    {
                        // In subtitle scan
                        completeWeight = e.FractionComplete * SubtitleScanCost;
                    }
                    else if (e.PassId == 1)
                    {
                        // First normal pass
                        completeWeight = SubtitleScanCost + e.FractionComplete;
                    }
                    else
                    {
                        // Second normal pass
                        completeWeight = SubtitleScanCost + 1 + e.FractionComplete;
                    }
                }


                double fractionComplete = completeWeight / totalWeight;
                this.PreviewPercentComplete = fractionComplete * 100;
            };
            this.encodeProxy.EncodeCompleted += (o, e) =>
            {
                DispatchUtilities.BeginInvoke(() =>
                {
                    this.EncodeState = PreviewEncodeState.NotEncoding;

                    if (this.encodeCancelled)
                    {
                        this.logger.Log("Cancelled preview clip generation");
                    }
                    else
                    {
                        if (e.Error)
                        {
                            this.logger.Log(PreviewRes.PreviewClipGenerationFailedTitle);
                            Utilities.MessageBox.Show(PreviewRes.PreviewClipGenerationFailedMessage);
                        }
                        else
                        {
                            var previewFileInfo = new FileInfo(this.previewFilePath);
                            this.logger.Log("Finished preview clip generation. Size: " + Utilities.FormatFileSize(previewFileInfo.Length));

                            this.PlayPreview();
                        }
                    }
                });
            };

            this.logger.Log("Generating preview clip");
            this.logger.Log("  Path: " + this.job.OutputPath);
            this.logger.Log("  Title: " + this.job.Title);
            this.logger.Log("  Preview #: " + this.SelectedPreview);

            this.encodeProxy.StartEncode(this.job, this.logger, true, this.SelectedPreview, this.PreviewSeconds, this.job.Length.TotalSeconds);
        }
Пример #2
0
		private void StartEncode()
		{
			VCJob job = this.CurrentJob.Job;

			var encodeLogger = new Logger(this.logger, Path.GetFileName(job.OutputPath));
			this.CurrentJob.Logger = encodeLogger;

			encodeLogger.Log("Starting job " + this.taskNumber + "/" + this.totalTasks);
			encodeLogger.Log("  Path: " + job.SourcePath);
			encodeLogger.Log("  Title: " + job.Title);

			switch (job.RangeType)
			{
				case VideoRangeType.All:
					encodeLogger.Log("  Range: All");
					break;
				case VideoRangeType.Chapters:
					encodeLogger.Log("  Chapters: " + job.ChapterStart + "-" + job.ChapterEnd);
					break;
				case VideoRangeType.Seconds:
					encodeLogger.Log("  Seconds: " + job.SecondsStart + "-" + job.SecondsEnd);
					break;
				case VideoRangeType.Frames:
					encodeLogger.Log("  Frames: " + job.FramesStart + "-" + job.FramesEnd);
					break;
			}

			this.encodeProxy = Utilities.CreateEncodeProxy();
			this.encodeProxy.EncodeProgress += this.OnEncodeProgress;
			this.encodeProxy.EncodeCompleted += this.OnEncodeCompleted;
			this.encodeProxy.EncodeStarted += this.OnEncodeStarted;

			string destinationDirectory = Path.GetDirectoryName(this.CurrentJob.Job.OutputPath);
			if (!Directory.Exists(destinationDirectory))
			{
				try
				{
					Directory.CreateDirectory(destinationDirectory);
				}
				catch (IOException exception)
				{
					Utilities.MessageBox.Show(
						string.Format(MainRes.DirectoryCreateErrorMessage, exception),
						MainRes.DirectoryCreateErrorTitle,
						MessageBoxButton.OK,
						MessageBoxImage.Error);
				}
			}

			this.currentJobEta = TimeSpan.Zero;
			this.EncodeQueue[0].ReportEncodeStart(this.totalTasks == 1);
			this.encodeProxy.StartEncode(this.CurrentJob.Job, encodeLogger, false, 0, 0, 0);

			this.StopEncodeCommand.RaiseCanExecuteChanged();
			this.PauseCommand.RaiseCanExecuteChanged();
		}