Пример #1
0
        private void RunJob(string jobName)
        {
            this.resetEvent.Reset();

            EncodeJob job = EncodeJobsPersist.GetJob("Normal");

            if (job.SourceType == SourceType.VideoFolder)
            {
                job.SourcePath = Path.Combine(Environment.CurrentDirectory, Path.GetFileName(job.SourcePath));
            }

            if (job.SourceType == SourceType.File)
            {
                job.SourcePath = Path.Combine(Environment.CurrentDirectory, Path.GetFileName(job.SourcePath));
            }

            string extension;

            if (job.EncodingProfile.OutputFormat == Container.Mkv)
            {
                extension = ".mkv";
            }
            else
            {
                extension = ".mp4";
            }

            job.OutputPath = Path.Combine(OutputVideoDirectory, jobName + extension);

            var instance = new HandBrakeInstance();

            instance.Initialize(0);
            instance.ScanCompleted += (sender, e) =>
            {
                this.resetEvent.Set();
            };

            instance.StartScan(job.SourcePath, 10);
            this.resetEvent.WaitOne();

            this.resetEvent.Reset();
            instance.EncodeCompleted += (sender, e) =>
            {
                Assert.IsFalse(e.Error);
                this.resetEvent.Set();
            };

            instance.StartEncode(job);
            this.resetEvent.WaitOne();

            Assert.IsTrue(File.Exists(job.OutputPath));

            var fileInfo = new FileInfo(job.OutputPath);

            Assert.IsTrue(fileInfo.Length > 1024);
        }
Пример #2
0
        static void Main(string[] args)
        {
            instance = new HandBrakeInstance();

            instance.Initialize(verbosity: 1);
            instance.ScanCompleted += Instance_ScanCompleted;
            instance.StartScan(srcPath, previewCount: 10);

            Console.ReadLine();
        }
Пример #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="LibScan"/> class.
        /// </summary>
        public LibScan()
        {
            logging = new StringBuilder();

            instance = ServiceManager.HandBrakeInstance;
            instance.Initialize(1);
            instance.ScanProgress  += this.InstanceScanProgress;
            instance.ScanCompleted += this.InstanceScanCompleted;

            HandBrakeUtils.MessageLogged += this.HandBrakeInstanceMessageLogged;
            HandBrakeUtils.ErrorLogged   += this.HandBrakeInstanceErrorLogged;
        }
Пример #4
0
        public void ScanNextJob()
        {
            EncodeJobViewModel jobVM = itemsToScan[currentJobIndex];

            var onDemandInstance = new HandBrakeInstance();

            onDemandInstance.Initialize(Config.LogVerbosity);
            onDemandInstance.ScanProgress += (o, e) =>
            {
                lock (this.currentJobIndexLock)
                {
                    this.currentJobProgress = e.Progress;
                    this.RaisePropertyChanged(() => this.Progress);
                }
            };
            onDemandInstance.ScanCompleted += (o, e) =>
            {
                jobVM.HandBrakeInstance = onDemandInstance;

                if (onDemandInstance.Titles.Count > 0)
                {
                    Title titleToEncode = Utilities.GetFeatureTitle(onDemandInstance.Titles, onDemandInstance.FeatureTitle);

                    jobVM.Job.Title        = titleToEncode.TitleNumber;
                    jobVM.Job.Length       = titleToEncode.Duration;
                    jobVM.Job.ChapterStart = 1;
                    jobVM.Job.ChapterEnd   = titleToEncode.Chapters.Count;
                }

                lock (this.currentJobIndexLock)
                {
                    this.currentJobIndex++;
                    this.currentJobProgress = 0;
                    this.RaisePropertyChanged(() => this.Progress);

                    if (this.ScanFinished)
                    {
                        DispatchService.BeginInvoke(() =>
                        {
                            this.CancelCommand.Execute(null);
                        });
                    }
                    else
                    {
                        this.ScanNextJob();
                    }
                }
            };

            onDemandInstance.StartScan(jobVM.Job.SourcePath, Config.PreviewCount, 0);
        }
Пример #5
0
        /// <summary>
        /// Gets the scanInstance.
        /// </summary>
        /// <param name="verbosity">
        /// The verbosity.
        /// </param>
        /// <returns>
        /// The <see cref="IHandBrakeInstance"/>.
        /// </returns>
        public static IHandBrakeInstance GetScanInstance(int verbosity)
        {
            if (scanInstance != null)
            {
                scanInstance.Dispose();
                scanInstance = null;
            }

            HandBrakeInstance newInstance = new HandBrakeInstance();

            newInstance.Initialize(verbosity);
            scanInstance = newInstance;

            return(scanInstance);
        }
Пример #6
0
        /// <summary>
        /// The get encode instance.
        /// </summary>
        /// <param name="verbosity">
        /// The verbosity.
        /// </param>
        /// <param name="configuration">
        /// The configuration.
        /// </param>
        /// <returns>
        /// The <see cref="IHandBrakeInstance"/>.
        /// </returns>
        public static IHandBrakeInstance GetPreviewInstance(int verbosity, HBConfiguration configuration)
        {
            if (previewInstance != null)
            {
                previewInstance.Dispose();
                previewInstance = null;
            }

            HandBrakeInstance newInstance = new HandBrakeInstance();

            newInstance.Initialize(verbosity);
            previewInstance = newInstance;

            HandBrakeUtils.SetDvdNav(!configuration.IsDvdNavDisabled);

            return(previewInstance);
        }
Пример #7
0
        public void StartScan(string path, IAppLogger logger)
        {
            var onDemandInstance = new HandBrakeInstance();

            onDemandInstance.Initialize(Config.LogVerbosity);
            onDemandInstance.ScanProgress += (o, e) =>
            {
                this.ScanProgress?.Invoke(this, new EventArgs <float>((float)e.Progress));
            };
            onDemandInstance.ScanCompleted += (o, e) =>
            {
                this.ScanCompleted?.Invoke(this, new EventArgs <string>(onDemandInstance.TitlesJson));
                onDemandInstance.Dispose();
            };

            onDemandInstance.StartScan(path, Config.PreviewCount, TimeSpan.FromSeconds(Config.MinimumTitleLengthSeconds), 0);
        }
        /// <summary>
        /// Gets the scanInstance.
        /// </summary>
        /// <param name="verbosity">
        /// The verbosity.
        /// </param>
        /// <returns>
        /// The <see cref="IHandBrakeInstance"/>.
        /// </returns>
        public static IHandBrakeInstance GetScanInstance(int verbosity)
        {
            if (!HandBrakeUtils.IsInitialised())
            {
                throw new Exception("Please call Init before Using!");
            }

            if (scanInstance != null)
            {
                scanInstance.Dispose();
                scanInstance = null;
            }

            HandBrakeInstance newInstance = new HandBrakeInstance();

            newInstance.Initialize(verbosity, noHardware);
            scanInstance = newInstance;

            return(scanInstance);
        }
        /// <summary>
        /// The get encode instance.
        /// </summary>
        /// <param name="verbosity">
        /// The verbosity.
        /// </param>
        /// <param name="userSettingService">
        /// The user Setting Service.
        /// </param>
        /// <returns>
        /// The <see cref="IHandBrakeInstance"/>.
        /// </returns>
        public static IHandBrakeInstance GetPreviewInstance(int verbosity, IUserSettingService userSettingService)
        {
            if (!HandBrakeUtils.IsInitialised())
            {
                throw new Exception("Please call Init before Using!");
            }

            if (previewInstance != null)
            {
                previewInstance.Dispose();
                previewInstance = null;
            }

            HandBrakeInstance newInstance = new HandBrakeInstance();

            newInstance.Initialize(verbosity, noHardware);
            previewInstance = newInstance;

            HandBrakeUtils.SetDvdNav(!userSettingService.GetUserSetting <bool>(UserSettingConstants.DisableLibDvdNav));

            return(previewInstance);
        }
Пример #10
0
        /// <summary>
        /// The get encode instance.
        /// </summary>
        /// <param name="verbosity">
        /// The verbosity.
        /// </param>
        /// <param name="configuration">
        /// The configuration.
        /// </param>
        /// <returns>
        /// The <see cref="IHandBrakeInstance"/>.
        /// </returns>
        public static IHandBrakeInstance GetPreviewInstance(int verbosity, HBConfiguration configuration)
        {
            if (!HandBrakeUtils.IsInitialised())
            {
                throw new Exception("Please call Init before Using!");
            }

            if (previewInstance != null)
            {
                previewInstance.Dispose();
                previewInstance = null;
            }

            HandBrakeInstance newInstance = new HandBrakeInstance();

            newInstance.Initialize(verbosity, noHardware);
            previewInstance = newInstance;

            HandBrakeUtils.SetDvdNav(!configuration.IsDvdNavDisabled);

            return(previewInstance);
        }
Пример #11
0
        public Task Encode(string originalFile, string outputFile, int start, int end,
                           IProgress <EncodeProgress> encodeProgresss,
                           CancellationToken cancelToken)
        {
            var taskCompletionSource = new TaskCompletionSource <bool>();

            var instance = new HandBrakeInstance();

            instance.Initialize(1);

            instance.ScanCompleted += (o, args) =>
            {
                try
                {
                    if (start >= end)
                    {
                        throw new Exception("Invalid start and end times.");
                    }
                    var sourceTitle = instance.Titles.TitleList.FirstOrDefault();
                    if (sourceTitle == null)
                    {
                        throw new Exception("Could not read input video.");
                    }

                    var settings = GetDefaultSettings();
                    settings.Destination.File = outputFile;
                    dynamic resolution = settings.Filters.FilterList.First(filter => filter.ID == 11).Settings;

                    resolution.width            = sourceTitle.Geometry.Width;
                    resolution.height           = sourceTitle.Geometry.Height;
                    settings.Source.Range.Start = start * 90000;
                    settings.Source.Range.End   = end * 90000;

                    settings.Source.Path = originalFile;

                    cancelToken.Register(() => instance.StopEncode());

                    instance.StartEncode(settings);
                }
                catch (Exception e)
                {
                    taskCompletionSource.TrySetException(e);
                }
            };

            instance.EncodeProgress += (o, args) => NewMeth(args, encodeProgresss);

            instance.EncodeCompleted += (o, args) =>
            {
                try
                {
                    if (args.Error)
                    {
                        if (cancelToken.IsCancellationRequested)
                        {
                            throw new Exception("Encoding was canceled");
                        }
                        throw new Exception("Encoding failed. I don't know why 'cause this API kinda sucks");
                    }
                    taskCompletionSource.TrySetResult(true);
                }
                catch (Exception e)
                {
                    taskCompletionSource.TrySetException(e);
                }
            };

            instance.StartScan(originalFile, 1, TimeSpan.Zero, 1);

            return(taskCompletionSource.Task);
        }