Example #1
0
 private void HandlePresetListsForSave(List <Preset> processList, Dictionary <string, HBPresetCategory> presetCategories, List <HBPreset> uncategorisedPresets)
 {
     foreach (Preset item in processList)
     {
         if (string.IsNullOrEmpty(item.Category))
         {
             uncategorisedPresets.Add(JsonPresetFactory.CreateHbPreset(item, HBConfigurationFactory.Create()));
         }
         else
         {
             HBPreset preset = JsonPresetFactory.CreateHbPreset(item, HBConfigurationFactory.Create());
             if (presetCategories.ContainsKey(item.Category))
             {
                 presetCategories[item.Category].ChildrenArray.Add(preset);
             }
             else
             {
                 presetCategories[item.Category] = new HBPresetCategory
                 {
                     ChildrenArray = new List <HBPreset> {
                         preset
                     },
                     Folder     = true,
                     PresetName = item.Category,
                     Type       = item.IsBuildIn ? 0 : 1
                 };
             }
         }
     }
 }
        /// <summary>
        /// Encode and play a sample
        /// </summary>
        public void Play()
        {
            try
            {
                this.IsEncoding = true;
                if (File.Exists(this.CurrentlyPlaying))
                {
                    File.Delete(this.CurrentlyPlaying);
                }
            }
            catch (Exception)
            {
                this.IsEncoding = false;
                this.errorService.ShowMessageBox(Resources.StaticPreview_UnableToDeletePreview,
                                                 Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);
            }

            if (this.Task == null || string.IsNullOrEmpty(Task.Source))
            {
                this.errorService.ShowMessageBox(Resources.StaticPreviewViewModel_ScanFirst,
                                                 Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            EncodeTask encodeTask = new EncodeTask(this.Task)
            {
                PreviewEncodeDuration = this.Duration,
                PreviewEncodeStartAt  = this.SelectedPreviewImage,
                PointToPointMode      = PointToPointMode.Preview
            };

            // Filename handling.
            if (string.IsNullOrEmpty(encodeTask.Destination))
            {
                string filename = Path.ChangeExtension(Path.GetTempFileName(), encodeTask.OutputFormat == OutputFormat.Mkv ? "m4v" : "mkv");
                encodeTask.Destination = filename;
                this.CurrentlyPlaying  = filename;
            }
            else
            {
                string directory       = Path.GetDirectoryName(encodeTask.Destination) ?? string.Empty;
                string filename        = Path.GetFileNameWithoutExtension(encodeTask.Destination);
                string extension       = Path.GetExtension(encodeTask.Destination);
                string previewFilename = string.Format("{0}_preview{1}", filename, extension);
                string previewFullPath = Path.Combine(directory, previewFilename);
                encodeTask.Destination = previewFullPath;
                this.CurrentlyPlaying  = previewFullPath;
            }

            // Setup the encode task as a preview encode
            encodeTask.IsPreviewEncode       = true;
            encodeTask.PreviewEncodeStartAt  = this.SelectedPreviewImage + 1;
            encodeTask.PreviewEncodeDuration = this.Duration;
            QueueTask task = new QueueTask(encodeTask, HBConfigurationFactory.Create(), this.ScannedSource.ScanPath);

            ThreadPool.QueueUserWorkItem(this.CreatePreview, task);
        }
        /// <summary>
        /// Encode and play a sample
        /// </summary>
        public void Play()
        {
            try
            {
                this.IsEncoding = true;
                if (File.Exists(this.CurrentlyPlaying))
                {
                    File.Delete(this.CurrentlyPlaying);
                }
            }
            catch (Exception)
            {
                this.IsEncoding = false;
                this.errorService.ShowMessageBox("Unable to delete previous preview file. You may need to restart the application.",
                                                 Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);
            }

            if (this.Task == null || string.IsNullOrEmpty(Task.Source))
            {
                this.errorService.ShowMessageBox("You must first scan a source and setup your encode before creating a preview.",
                                                 Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            EncodeTask encodeTask = new EncodeTask(this.Task)
            {
                PreviewEncodeDuration = this.Duration,
                PreviewEncodeStartAt  = this.SelectedPreviewImage,
                PointToPointMode      = PointToPointMode.Preview
            };

            // Filename handling.
            if (string.IsNullOrEmpty(encodeTask.Destination))
            {
                string filename = Path.ChangeExtension(Path.GetTempFileName(), encodeTask.OutputFormat == OutputFormat.Mkv ? "m4v" : "mkv");
                encodeTask.Destination = filename;
                this.CurrentlyPlaying  = filename;
            }
            else
            {
                string directory       = Path.GetDirectoryName(encodeTask.Destination) ?? string.Empty;
                string filename        = Path.GetFileNameWithoutExtension(encodeTask.Destination);
                string extension       = Path.GetExtension(encodeTask.Destination);
                string previewFilename = string.Format("{0}_preview{1}", filename, extension);
                string previewFullPath = Path.Combine(directory, previewFilename);
                encodeTask.Destination = previewFullPath;
                this.CurrentlyPlaying  = previewFullPath;
            }

            // Setup the encode task as a preview encode
            encodeTask.IsPreviewEncode       = true;
            encodeTask.PreviewEncodeStartAt  = this.SelectedPreviewImage; // TODO 0 and 1 mean the same. Need to fix this as it knocks the video out of sync with the still preview.
            encodeTask.PreviewEncodeDuration = this.Duration;
            QueueTask task = new QueueTask(encodeTask, HBConfigurationFactory.Create(), this.ScannedSource.ScanPath);

            ThreadPool.QueueUserWorkItem(this.CreatePreview, task);
        }
 /// <summary>
 /// Start a Scan
 /// </summary>
 /// <param name="filename">
 /// The filename.
 /// </param>
 /// <param name="title">
 /// The title.
 /// </param>
 public void StartScan(string filename, int title)
 {
     if (!string.IsNullOrEmpty(filename))
     {
         this.scanService.Scan(
             filename,
             title,
             null,
             HBConfigurationFactory.Create());
     }
 }
Example #5
0
        public void ExportCliJson(string exportPath)
        {
            List <QueueTask>  jobs      = this.queue.Where(item => item.Status != QueueItemStatus.Completed).ToList();
            List <EncodeTask> workUnits = jobs.Select(job => job.Task).ToList();
            HBConfiguration   config    = HBConfigurationFactory.Create(); // Default to current settings for now. These will hopefully go away in the future.

            string json = this.GetQueueJson(workUnits, config);

            using (var strm = new StreamWriter(exportPath, false))
            {
                strm.Write(json);
                strm.Close();
                strm.Dispose();
            }
        }
Example #6
0
        /// <summary>
        /// Get a Preview image for the current job and preview number.
        /// </summary>
        /// <param name="job">
        /// The job.
        /// </param>
        /// <param name="preview">
        /// The preview.
        /// </param>
        /// <returns>
        /// The <see cref="BitmapImage"/>.
        /// </returns>
        public BitmapImage GetPreview(EncodeTask job, int preview)
        {
            if (this.instance == null)
            {
                return(null);
            }

            BitmapImage bitmapImage = null;

            try
            {
                EncodeTaskFactory factory    = new EncodeTaskFactory(this.userSettingService);
                JsonEncodeObject  jobDict    = factory.Create(job, HBConfigurationFactory.Create());
                RawPreviewData    bitmapData = this.instance.GetPreview(jobDict, preview);
                bitmapImage = BitmapUtilities.ConvertToBitmapImage(BitmapUtilities.ConvertByteArrayToBitmap(bitmapData));
            }
            catch (AccessViolationException e)
            {
                Debug.WriteLine(e);
            }

            return(bitmapImage);
        }
        public void UpdatePreviewFrame()
        {
            // Don't preview for small images.
            if (this.Task.Anamorphic == Anamorphic.Loose && this.Task.Width < 32)
            {
                PreviewNotAvailable = true;
                return;
            }

            if ((this.Task.Anamorphic == Anamorphic.None || this.Task.Anamorphic == Anamorphic.Custom) && (this.Task.Width < 32 || this.Task.Height < 32))
            {
                PreviewNotAvailable = true;
                return;
            }

            BitmapImage image = null;

            try
            {
                image = this.scanService.GetPreview(this.Task, this.SelectedPreviewImage, HBConfigurationFactory.Create());
            }
            catch (Exception exc)
            {
                PreviewNotAvailable = true;
            }

            if (image != null)
            {
                PreviewNotAvailable = false;
                this.Width          = (int)Math.Ceiling(image.Width);
                this.Height         = (int)Math.Ceiling(image.Height);
                this.PreviewImage   = image;
            }
        }
Example #8
0
        private void UpdatePreviewFrame()
        {
            // Don't preview for small images.
            if (this.Task.Anamorphic == Anamorphic.Loose && this.Task.Width < 32)
            {
                this.PreviewNotAvailable  = true;
                this.IsPreviewInfoVisible = false;
                this.NotifyOfPropertyChange(() => this.IsPreviewInfoVisible);
                return;
            }

            if ((this.Task.Anamorphic == Anamorphic.None || this.Task.Anamorphic == Anamorphic.Custom) && (this.Task.Width < 32 || this.Task.Height < 32))
            {
                this.PreviewNotAvailable = true;
                return;
            }

            BitmapImage image = null;

            try
            {
                image = this.scanService.GetPreview(this.Task, this.selectedPreview - 1, HBConfigurationFactory.Create());
            }
            catch (Exception exc)
            {
                this.PreviewNotAvailable = true;
                Debug.WriteLine(exc);
            }

            if (image != null)
            {
                this.PreviewNotAvailable  = false;
                this.PreviewImage         = image;
                this.MaxWidth             = (int)image.Width;
                this.MaxHeight            = (int)image.Height;
                this.IsPreviewInfoVisible = true;
                this.NotifyOfPropertyChange(() => this.IsPreviewInfoVisible);
                this.NotifyOfPropertyChange(() => this.PreviewImage);
                this.NotifyOfPropertyChange(() => this.MaxWidth);
                this.NotifyOfPropertyChange(() => this.MaxHeight);
            }
        }
Example #9
0
        /// <summary>
        /// Update the preset files
        /// </summary>
        private void SavePresetFiles()
        {
            try
            {
                // Verify Directories.
                string directory = Path.GetDirectoryName(this.presetFile);
                if (directory != null && !Directory.Exists(directory))
                {
                    Directory.CreateDirectory(directory);
                }

                // Organise the Presets list into Json Equivalent objects.
                Dictionary <string, PresetCategory> presetCategories = new Dictionary <string, PresetCategory>();
                List <HBPreset> uncategorisedPresets = new List <HBPreset>();

                // Handle User Presets first.
                foreach (Preset item in this.flatPresetList.Values.OrderBy(o => o.IsBuildIn))
                {
                    if (string.IsNullOrEmpty(item.Category))
                    {
                        uncategorisedPresets.Add(JsonPresetFactory.CreateHbPreset(item, HBConfigurationFactory.Create()));
                    }
                    else
                    {
                        HBPreset preset = JsonPresetFactory.CreateHbPreset(item, HBConfigurationFactory.Create());
                        if (presetCategories.ContainsKey(item.Category))
                        {
                            presetCategories[item.Category].ChildrenArray.Add(preset);
                        }
                        else
                        {
                            presetCategories[item.Category] = new PresetCategory
                            {
                                ChildrenArray = new List <HBPreset> {
                                    preset
                                },
                                Folder     = true,
                                PresetName = item.Category,
                                Type       = item.IsBuildIn ? 0 : 1
                            };
                        }
                    }
                }

                // Wrap the categories in a container.
                JsonSerializerSettings settings = new JsonSerializerSettings {
                    MissingMemberHandling = MissingMemberHandling.Ignore
                };
                PresetTransportContainer container = new PresetTransportContainer(
                    Constants.PresetVersionMajor,
                    Constants.PresetVersionMinor,
                    Constants.PresetVersionMicro)
                {
                    PresetList = new List <object>()
                };
                container.PresetList.AddRange(presetCategories.Values);
                container.PresetList.AddRange(uncategorisedPresets);

                // Write the preset container out to file.
                using (FileStream strm = new FileStream(this.presetFile, FileMode.Create, FileAccess.Write))
                {
                    string presetsJson = JsonConvert.SerializeObject(container, Formatting.Indented, settings);
                    using (StreamWriter writer = new StreamWriter(strm))
                    {
                        writer.WriteLine(presetsJson);
                    }
                }
            }
            catch (Exception exc)
            {
                Debug.WriteLine(exc);
                throw new GeneralApplicationException("Unable to write to the presets file.", "The details section below may indicate why this error has occurred.", exc);
            }
        }
        /// <summary>
        /// Encode and play a sample
        /// </summary>
        public void Play()
        {
            try
            {
                this.IsEncoding = true;
                if (File.Exists(this.CurrentlyPlaying))
                {
                    File.Delete(this.CurrentlyPlaying);
                }
            }
            catch (Exception)
            {
                this.IsEncoding = false;
                this.errorService.ShowMessageBox(Resources.StaticPreview_UnableToDeletePreview,
                                                 Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);
            }

            if (this.Task == null || string.IsNullOrEmpty(Task.Source))
            {
                this.errorService.ShowMessageBox(Resources.StaticPreviewViewModel_ScanFirst,
                                                 Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            EncodeTask encodeTask = new EncodeTask(this.Task)
            {
                PreviewEncodeDuration = this.Duration,
                PreviewEncodeStartAt  = this.SelectedPreviewImage,
                PointToPointMode      = PointToPointMode.Preview
            };

            // Filename handling.
            if (string.IsNullOrEmpty(encodeTask.Destination))
            {
                string formatExtension;
                switch (encodeTask.OutputFormat)
                {
                case OutputFormat.WebM:
                    formatExtension = "webm";
                    break;

                case OutputFormat.Mp4:
                    formatExtension = "m4v";
                    break;

                case OutputFormat.Mkv:
                default:
                    formatExtension = "mkv";
                    break;
                }
                string filename = Path.ChangeExtension(Path.GetTempFileName(), formatExtension);
                encodeTask.Destination = filename;
                this.CurrentlyPlaying  = filename;
            }
            else
            {
                string directory       = Path.GetDirectoryName(encodeTask.Destination) ?? string.Empty;
                string filename        = Path.GetFileNameWithoutExtension(encodeTask.Destination);
                string extension       = Path.GetExtension(encodeTask.Destination);
                string previewFilename = string.Format("{0}_preview{1}", filename, extension);
                string previewFullPath = Path.Combine(directory, previewFilename);
                encodeTask.Destination = previewFullPath;
                this.CurrentlyPlaying  = previewFullPath;
            }

            // Setup the encode task as a preview encode
            encodeTask.IsPreviewEncode       = true;
            encodeTask.PreviewEncodeStartAt  = this.SelectedPreviewImage + 1;
            encodeTask.PreviewEncodeDuration = this.Duration;

            SubtitleTrack scanTrack = null;

            foreach (var track in encodeTask.SubtitleTracks)
            {
                if (track.SourceTrack != null && track.SourceTrack.SubtitleType == SubtitleType.ForeignAudioSearch)
                {
                    scanTrack = track;
                    break;
                }
            }

            if (scanTrack != null)
            {
                encodeTask.SubtitleTracks.Remove(scanTrack);
            }

            QueueTask task = new QueueTask(encodeTask, HBConfigurationFactory.Create(), this.ScannedSource.ScanPath, null);

            ThreadPool.QueueUserWorkItem(this.CreatePreview, task);
        }