// -------------------------------------------------------------------------------------------------------------------- // // This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. // // // Video Encoder Converter // // -------------------------------------------------------------------------------------------------------------------- namespace HandBrakeWPF.Converters.Video { using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Windows.Data; using HandBrake.ApplicationServices.Utilities; using HandBrake.ApplicationServices.Interop.Model.Encoding; using HandBrakeWPF.Utilities; using EncodeTask = HandBrakeWPF.Services.Encode.Model.EncodeTask; using OutputFormat = HandBrakeWPF.Services.Encode.Model.Models.OutputFormat; /// /// Video Encoder Converter /// public class VideoEncoderConverter : IMultiValueConverter { /// /// Gets a list of Video encoders OR returns the string name of an encoder depending on the input. /// /// /// The values. /// /// /// The target type. /// /// /// The parameter. /// /// /// The culture. /// /// /// IEnumberable VideoEncoder or String encoder name. /// public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { if (values.Count() == 2) { List encoders = EnumHelper.GetEnumList().ToList(); EncodeTask task = values[1] as EncodeTask; if (task != null && task.OutputFormat != OutputFormat.Mkv) { encoders.Remove(VideoEncoder.Theora); encoders.Remove(VideoEncoder.VP8); } if (!SystemInfo.IsQsvAvailableH264) { encoders.Remove(VideoEncoder.QuickSync); } if (!SystemInfo.IsQsvAvailableH265) { encoders.Remove(VideoEncoder.QuickSyncH265); } return EnumHelper.GetEnumDisplayValuesSubset(encoders); } if (values[0].GetType() == typeof(VideoEncoder)) { return EnumHelper.GetDisplay((VideoEncoder)values[0]); } return null; } /// /// Convert from a string name, to enum value. /// /// /// The value. /// /// /// The target types. /// /// /// The parameter. /// /// /// The culture. /// /// /// Returns the video encoder enum item. /// public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) { string name = value as string; if (!string.IsNullOrEmpty(name)) { return new object[] { EnumHelper.GetValue(name)}; } return null; } } }