From: sr55 Date: Sat, 4 Apr 2015 21:09:12 +0000 (+0000) Subject: WinGui: Adding Subtitle Burn-in Behaviour Support. X-Git-Tag: 1.0.0~1295 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=343ffe36398605c25349cc5d49a043706d42f6b5;p=handbrake WinGui: Adding Subtitle Burn-in Behaviour Support. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@7052 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- diff --git a/win/CS/HandBrake.ApplicationServices/Services/Encode/Factories/EncodeFactory.cs b/win/CS/HandBrake.ApplicationServices/Services/Encode/Factories/EncodeFactory.cs index bebfeca18..2ec14a1e2 100644 --- a/win/CS/HandBrake.ApplicationServices/Services/Encode/Factories/EncodeFactory.cs +++ b/win/CS/HandBrake.ApplicationServices/Services/Encode/Factories/EncodeFactory.cs @@ -257,10 +257,10 @@ namespace HandBrake.ApplicationServices.Services.Encode.Factories } else { - video.Level = job.VideoLevel.ShortName; + video.Level = job.VideoLevel != null ? job.VideoLevel.ShortName : null; video.Options = job.ExtraAdvancedArguments; - video.Preset = job.VideoPreset.ShortName; - video.Profile = job.VideoProfile.ShortName; + video.Preset = job.VideoPreset != null ? job.VideoPreset.ShortName : null; + video.Profile = job.VideoProfile != null ? job.VideoProfile.ShortName : null; } if (job.VideoEncodeRateType == VideoEncodeRateType.ConstantQuality) video.Quality = job.Quality; diff --git a/win/CS/HandBrakeWPF/Converters/Subtitles/SubtitleBurnInBehaviourConverter.cs b/win/CS/HandBrakeWPF/Converters/Subtitles/SubtitleBurnInBehaviourConverter.cs new file mode 100644 index 000000000..76be941bc --- /dev/null +++ b/win/CS/HandBrakeWPF/Converters/Subtitles/SubtitleBurnInBehaviourConverter.cs @@ -0,0 +1,91 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// +// +// Subtitle Behaviour Converter +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrakeWPF.Converters.Subtitles +{ + using System; + using System.ComponentModel; + using System.Globalization; + using System.Linq; + using System.Windows.Data; + + using HandBrake.ApplicationServices.Utilities; + + using HandBrakeWPF.Model.Subtitles; + + /// + /// Subtitle Behaviour Converter + /// + public class SubtitleBurnInBehaviourConverter : IValueConverter + { + /// + /// The convert. + /// + /// + /// The value. + /// + /// + /// The target type. + /// + /// + /// The parameter. + /// + /// + /// The culture. + /// + /// + /// The . + /// + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value != null && value.GetType() == typeof(BindingList)) + { + return + new BindingList( + EnumHelper.GetEnumDisplayValues(typeof(SubtitleBurnInBehaviourModes)).ToList()); + } + + if (value != null && value.GetType() == typeof(SubtitleBehaviourModes)) + { + return EnumHelper.GetDisplay((SubtitleBurnInBehaviourModes)value); + } + + return null; + } + + /// + /// The convert back. + /// + /// + /// The value. + /// + /// + /// The target type. + /// + /// + /// The parameter. + /// + /// + /// The culture. + /// + /// + /// The . + /// + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + string name = value as string; + if (!string.IsNullOrEmpty(name)) + { + return EnumHelper.GetValue(name); + } + + return null; + } + } +} diff --git a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj index dd5ee90ed..f8e754663 100644 --- a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj +++ b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj @@ -139,6 +139,7 @@ + @@ -150,6 +151,7 @@ + diff --git a/win/CS/HandBrakeWPF/Model/Subtitles/SubtitleBehaviours.cs b/win/CS/HandBrakeWPF/Model/Subtitles/SubtitleBehaviours.cs index 8570f00e7..db5b7eb39 100644 --- a/win/CS/HandBrakeWPF/Model/Subtitles/SubtitleBehaviours.cs +++ b/win/CS/HandBrakeWPF/Model/Subtitles/SubtitleBehaviours.cs @@ -19,25 +19,11 @@ namespace HandBrakeWPF.Model.Subtitles /// public class SubtitleBehaviours : PropertyChangedBase { - /// - /// The selected behaviour. - /// private SubtitleBehaviourModes selectedBehaviour; - - /// - /// The selected langauges. - /// private BindingList selectedLangauges; - - /// - /// The add foreign audio scan track. - /// private bool addForeignAudioScanTrack; - - /// - /// The add closed captions. - /// private bool addClosedCaptions; + private SubtitleBurnInBehaviourModes selectedBurnInBehaviour; /// /// Initializes a new instance of the class. @@ -45,6 +31,7 @@ namespace HandBrakeWPF.Model.Subtitles public SubtitleBehaviours() { this.SelectedBehaviour = SubtitleBehaviourModes.None; + this.SelectedBurnInBehaviour = SubtitleBurnInBehaviourModes.None; this.SelectedLangauges = new BindingList(); } @@ -57,6 +44,7 @@ namespace HandBrakeWPF.Model.Subtitles public SubtitleBehaviours(SubtitleBehaviours behaviours) { this.SelectedBehaviour = behaviours.selectedBehaviour; + this.SelectedBurnInBehaviour = behaviours.selectedBurnInBehaviour; this.SelectedLangauges = new BindingList(behaviours.SelectedLangauges.ToList()); } @@ -80,6 +68,26 @@ namespace HandBrakeWPF.Model.Subtitles } } + /// + /// Gets or sets the selected burn in behaviour. + /// + public SubtitleBurnInBehaviourModes SelectedBurnInBehaviour + { + get + { + return this.selectedBurnInBehaviour; + } + set + { + if (value == this.selectedBurnInBehaviour) + { + return; + } + this.selectedBurnInBehaviour = value; + this.NotifyOfPropertyChange(() => this.SelectedBurnInBehaviour); + } + } + /// /// Gets or sets the selected langages. /// @@ -151,6 +159,7 @@ namespace HandBrakeWPF.Model.Subtitles SubtitleBehaviours cloned = new SubtitleBehaviours { SelectedBehaviour = this.selectedBehaviour, + SelectedBurnInBehaviour = this.selectedBurnInBehaviour, SelectedLangauges = new BindingList(), AddClosedCaptions = this.addClosedCaptions, AddForeignAudioScanTrack = this.addForeignAudioScanTrack, diff --git a/win/CS/HandBrakeWPF/Model/Subtitles/SubtitleBurnInBehaviourModes.cs b/win/CS/HandBrakeWPF/Model/Subtitles/SubtitleBurnInBehaviourModes.cs new file mode 100644 index 000000000..174b4a5e8 --- /dev/null +++ b/win/CS/HandBrakeWPF/Model/Subtitles/SubtitleBurnInBehaviourModes.cs @@ -0,0 +1,31 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// +// +// The subtitle behaviours modes. +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrakeWPF.Model.Subtitles +{ + using System.ComponentModel.DataAnnotations; + + /// + /// The subtitle behaviours modes. + /// + public enum SubtitleBurnInBehaviourModes + { + [Display(Name = "None")] + None = 0, + + [Display(Name = "Foreign Audio Track")] + ForeignAudio, + + [Display(Name = "First Track")] + FirstTrack, + + [Display(Name = "Foreign Audio Preferred, else First")] + ForeignAudioPreferred, + } +} diff --git a/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs b/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs index 5c4097933..3f26afe6e 100644 --- a/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs +++ b/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs @@ -900,6 +900,18 @@ namespace HandBrakeWPF.Properties { } } + /// + /// Looks up a localized string similar to None - Only tracks where the container does not support the format will be burned in. + ///Foreign Audio Track - The Foreign Audio track will be burned in if available. + ///First Track - The first track will be burned in. + ///Foreign Audio Preferred, else First - If the foreign audio track exists, it will be burned in, otherwise the first track will be chosen.. + /// + public static string Subtitles_BurnInBehaviourModes { + get { + return ResourceManager.GetString("Subtitles_BurnInBehaviourModes", resourceCulture); + } + } + /// /// Looks up a localized string similar to Updated. /// diff --git a/win/CS/HandBrakeWPF/Properties/Resources.resx b/win/CS/HandBrakeWPF/Properties/Resources.resx index 2a3222d1d..2bc82bd71 100644 --- a/win/CS/HandBrakeWPF/Properties/Resources.resx +++ b/win/CS/HandBrakeWPF/Properties/Resources.resx @@ -556,4 +556,10 @@ Please use the 'Extra Options' box on the 'Video' tab to input any additional en You cannot overwrite the source file you want to convert. Please choose a different filename. + + None - Only tracks where the container does not support the format will be burned in. +Foreign Audio Track - The Foreign Audio track will be burned in if available. +First Track - The first track will be burned in. +Foreign Audio Preferred, else First - If the foreign audio track exists, it will be burned in, otherwise the first track will be chosen. + \ No newline at end of file diff --git a/win/CS/HandBrakeWPF/ViewModels/SubtitlesViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/SubtitlesViewModel.cs index 425417cf1..33aa86be1 100644 --- a/win/CS/HandBrakeWPF/ViewModels/SubtitlesViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/SubtitlesViewModel.cs @@ -192,6 +192,17 @@ namespace HandBrakeWPF.ViewModels } } + /// + /// Gets the subtitle burn in behaviour mode list. + /// + public BindingList SubtitleBurnInBehaviourModeList + { + get + { + return new BindingList(EnumHelper.GetEnumList().ToList()); + } + } + /// /// Gets or sets AvailableLanguages. /// @@ -418,6 +429,62 @@ namespace HandBrakeWPF.ViewModels break; } + // Burn In Behaviour + if (this.Task.SubtitleTracks.Count >= 1) + { + bool burnInSet = false; + switch (this.SubtitleBehaviours.SelectedBurnInBehaviour) + { + case SubtitleBurnInBehaviourModes.None: + // Do Nothing. Only tracks where the container requires it will be burned in. + break; + case SubtitleBurnInBehaviourModes.ForeignAudio: + foreach (var track in this.Task.SubtitleTracks) + { + // Set the Foreign Audio Track to burned-in + if (track.SourceTrack.SubtitleType == SubtitleType.ForeignAudioSearch) + { + track.Burned = true; + this.SetBurnedToFalseForAllExcept(track); + break; + } + } + break; + case SubtitleBurnInBehaviourModes.FirstTrack: + foreach (var track in this.Task.SubtitleTracks) + { + // Set the first track. + if (!burnInSet && track.SourceTrack.SubtitleType != SubtitleType.ForeignAudioSearch) + { + burnInSet = true; + track.Burned = true; + this.SetBurnedToFalseForAllExcept(track); + } + } + break; + case SubtitleBurnInBehaviourModes.ForeignAudioPreferred: + foreach (var track in this.Task.SubtitleTracks) + { + // Set the first track. + if (!burnInSet) + { + burnInSet = true; + track.Burned = true; + this.SetBurnedToFalseForAllExcept(track); + } + + // But if there is a foreign audio track, prefer this to the first. + if (track.SourceTrack.SubtitleType == SubtitleType.ForeignAudioSearch) + { + track.Burned = true; + this.SetBurnedToFalseForAllExcept(track); + break; + } + } + break; + } + } + // Add all closed captions if enabled. if (this.SubtitleBehaviours.AddClosedCaptions) { @@ -491,6 +558,14 @@ namespace HandBrakeWPF.ViewModels this.SubtitleBehaviours.SelectedLangauges.Clear(); } + /// + /// Reload the audio tracks based on the defaults. + /// + public void ReloadDefaults() + { + this.AutomaticSubtitleSelection(); + } + #endregion #region Implemented Interfaces @@ -592,9 +667,17 @@ namespace HandBrakeWPF.ViewModels SourceTrack = source, }; - if ((source.SubtitleType == SubtitleType.PGS || source.SubtitleType == SubtitleType.ForeignAudioSearch) - && this.Task != null - && this.Task.OutputFormat == OutputFormat.Mp4) + + // Burn-in Behaviours + if (this.SubtitleBehaviours.SelectedBurnInBehaviour == SubtitleBurnInBehaviourModes.ForeignAudio + || this.SubtitleBehaviours.SelectedBurnInBehaviour == SubtitleBurnInBehaviourModes.ForeignAudioPreferred) + { + track.Burned = true; + this.SetBurnedToFalseForAllExcept(track); + } + + // For MP4, PGS Subtitles must be burned in. + if (!track.Burned && (source.SubtitleType == SubtitleType.PGS) && this.Task != null && this.Task.OutputFormat == OutputFormat.Mp4) { if (track.CanBeBurned) { @@ -670,6 +753,7 @@ namespace HandBrakeWPF.ViewModels { // Step 1, Set the behaviour mode this.SubtitleBehaviours.SelectedBehaviour = SubtitleBehaviourModes.None; + this.SubtitleBehaviours.SelectedBurnInBehaviour = SubtitleBurnInBehaviourModes.None; this.SubtitleBehaviours.AddClosedCaptions = false; this.SubtitleBehaviours.AddForeignAudioScanTrack = false; this.SubtitleBehaviours.SelectedLangauges.Clear(); @@ -689,6 +773,7 @@ namespace HandBrakeWPF.ViewModels if (preset != null && preset.SubtitleTrackBehaviours != null) { this.SubtitleBehaviours.SelectedBehaviour = preset.SubtitleTrackBehaviours.SelectedBehaviour; + this.SubtitleBehaviours.SelectedBurnInBehaviour = preset.SubtitleTrackBehaviours.SelectedBurnInBehaviour; this.SubtitleBehaviours.AddClosedCaptions = preset.SubtitleTrackBehaviours.AddClosedCaptions; this.SubtitleBehaviours.AddForeignAudioScanTrack = preset.SubtitleTrackBehaviours.AddForeignAudioScanTrack; diff --git a/win/CS/HandBrakeWPF/Views/SubtitlesView.xaml b/win/CS/HandBrakeWPF/Views/SubtitlesView.xaml index de2418ed7..cccbaf790 100644 --- a/win/CS/HandBrakeWPF/Views/SubtitlesView.xaml +++ b/win/CS/HandBrakeWPF/Views/SubtitlesView.xaml @@ -11,6 +11,7 @@ xmlns:splitButton="clr-namespace:HandBrakeWPF.Controls.SplitButton" xmlns:helpers="clr-namespace:HandBrakeWPF.Helpers" xmlns:subtitles="clr-namespace:HandBrakeWPF.Converters.Subtitles" + xmlns:Properties="clr-namespace:HandBrakeWPF.Properties" d:DesignHeight="350" d:DesignWidth="500" mc:Ignorable="d" @@ -18,6 +19,15 @@ + + + + @@ -71,6 +81,13 @@ Margin="0,0,10,0" cal:Message.Attach="[Event Click] = [Action ShowSubtitleDefaultsPanel]" Content="{Binding SwitchDisplayTitle}" /> + +