Exemple #1
0
        private Audio CreateAudio(EncodeTask job)
        {
            Audio audio = new Audio();

            List <string> copyMaskList = new List <string>();

            if (job.AudioPassthruOptions.AudioAllowAACPass)
            {
                copyMaskList.Add(EnumHelper <AudioEncoder> .GetShortName(AudioEncoder.AacPassthru));
            }
            if (job.AudioPassthruOptions.AudioAllowAC3Pass)
            {
                copyMaskList.Add(EnumHelper <AudioEncoder> .GetShortName(AudioEncoder.Ac3Passthrough));
            }
            if (job.AudioPassthruOptions.AudioAllowDTSHDPass)
            {
                copyMaskList.Add(EnumHelper <AudioEncoder> .GetShortName(AudioEncoder.DtsHDPassthrough));
            }
            if (job.AudioPassthruOptions.AudioAllowDTSPass)
            {
                copyMaskList.Add(EnumHelper <AudioEncoder> .GetShortName(AudioEncoder.DtsPassthrough));
            }
            if (job.AudioPassthruOptions.AudioAllowEAC3Pass)
            {
                copyMaskList.Add(EnumHelper <AudioEncoder> .GetShortName(AudioEncoder.EAc3Passthrough));
            }
            if (job.AudioPassthruOptions.AudioAllowFlacPass)
            {
                copyMaskList.Add(EnumHelper <AudioEncoder> .GetShortName(AudioEncoder.FlacPassthru));
            }
            if (job.AudioPassthruOptions.AudioAllowMP3Pass)
            {
                copyMaskList.Add(EnumHelper <AudioEncoder> .GetShortName(AudioEncoder.Mp3Passthru));
            }
            if (job.AudioPassthruOptions.AudioAllowTrueHDPass)
            {
                copyMaskList.Add(EnumHelper <AudioEncoder> .GetShortName(AudioEncoder.TrueHDPassthrough));
            }
            if (job.AudioPassthruOptions.AudioAllowMP2Pass)
            {
                copyMaskList.Add(EnumHelper <AudioEncoder> .GetShortName(AudioEncoder.Mp2Passthru));
            }

            audio.CopyMask = copyMaskList.ToArray();

            HBAudioEncoder audioEncoder = HandBrakeEncoderHelpers.GetAudioEncoder(EnumHelper <AudioEncoder> .GetShortName(job.AudioPassthruOptions.AudioEncoderFallback));

            audio.FallbackEncoder = audioEncoder?.ShortName;

            Validate.NotNull(audio.FallbackEncoder, string.Format("Unrecognized audio encoder: {0} \n", job.AudioPassthruOptions.AudioEncoderFallback));

            audio.AudioList = new List <HandBrake.Interop.Interop.Json.Encode.AudioTrack>();
            foreach (AudioTrack item in job.AudioTracks)
            {
                HBAudioEncoder encoder = HandBrakeEncoderHelpers.GetAudioEncoder(EnumHelper <AudioEncoder> .GetShortName(item.Encoder));
                Validate.NotNull(encoder, "Unrecognized audio encoder:" + item.Encoder);

                if (item.IsPassthru && (item.ScannedTrack.Codec & encoder.Id) == 0)
                {
                    // We have an unsupported passthru. Rather than let libhb drop the track, switch it to the fallback.
                    encoder = HandBrakeEncoderHelpers.GetAudioEncoder(EnumHelper <AudioEncoder> .GetShortName(job.AudioPassthruOptions.AudioEncoderFallback));
                }

                HBMixdown mixdown = HandBrakeEncoderHelpers.GetMixdown(item.MixDown);

                HBRate sampleRate = HandBrakeEncoderHelpers.AudioSampleRates.FirstOrDefault(s => s.Name == item.SampleRate.ToString(CultureInfo.InvariantCulture));

                HandBrake.Interop.Interop.Json.Encode.AudioTrack audioTrack = new HandBrake.Interop.Interop.Json.Encode.AudioTrack
                {
                    Track             = (item.Track.HasValue ? item.Track.Value : 0) - 1,
                    DRC               = item.DRC,
                    Encoder           = encoder.ShortName,
                    Gain              = item.Gain,
                    Mixdown           = mixdown != null ? mixdown.Id : -1,
                    NormalizeMixLevel = false,
                    Samplerate        = sampleRate != null ? sampleRate.Rate : 0,
                    Name              = !string.IsNullOrEmpty(item.TrackName) ? item.TrackName : null,
                };

                if (!item.IsPassthru)
                {
                    if (item.EncoderRateType == AudioEncoderRateType.Quality)
                    {
                        audioTrack.Quality = item.Quality;
                    }

                    if (item.EncoderRateType == AudioEncoderRateType.Bitrate)
                    {
                        audioTrack.Bitrate = item.Bitrate;
                    }
                }

                audio.AudioList.Add(audioTrack);
            }

            return(audio);
        }
Exemple #2
0
        private Video CreateVideo(EncodeTask job)
        {
            Video video = new Video();

            HBVideoEncoder videoEncoder = HandBrakeEncoderHelpers.VideoEncoders.FirstOrDefault(e => e.ShortName == EnumHelper <VideoEncoder> .GetShortName(job.VideoEncoder));

            Validate.NotNull(videoEncoder, "Video encoder " + job.VideoEncoder + " not recognized.");
            if (videoEncoder != null)
            {
                video.Encoder = videoEncoder.ShortName;
            }

            video.Level   = job.VideoLevel?.ShortName;
            video.Preset  = job.VideoPreset?.ShortName;
            video.Profile = job.VideoProfile?.ShortName;

            if (job.VideoTunes != null && job.VideoTunes.Count > 0)
            {
                foreach (var item in job.VideoTunes)
                {
                    video.Tune += string.IsNullOrEmpty(video.Tune) ? item.ShortName : "," + item.ShortName;
                }
            }

            if (job.VideoEncodeRateType == VideoEncodeRateType.ConstantQuality)
            {
                video.Quality = (decimal?)job.Quality;
            }

            if (job.VideoEncodeRateType == VideoEncodeRateType.AverageBitrate)
            {
                video.Bitrate = job.VideoBitrate;
                video.TwoPass = job.TwoPass;
                video.Turbo   = job.TurboFirstPass;
            }


            bool enableQuickSyncDecoding  = userSettingService.GetUserSetting <bool>(UserSettingConstants.EnableQuickSyncDecoding);
            bool useQSVDecodeForNonQSVEnc = userSettingService.GetUserSetting <bool>(UserSettingConstants.UseQSVDecodeForNonQSVEnc);
            bool enableQsvLowPower        = userSettingService.GetUserSetting <bool>(UserSettingConstants.EnableQuickSyncLowPower);

            video.QSV.Decode = HandBrakeHardwareEncoderHelper.IsQsvAvailable && enableQuickSyncDecoding;

            // The use of the QSV decoder is configurable for non QSV encoders.
            if (video.QSV.Decode && !VideoEncoderHelpers.IsQuickSync(job.VideoEncoder))
            {
                video.QSV.Decode = useQSVDecodeForNonQSVEnc;
            }

            video.Options = job.ExtraAdvancedArguments;

            if (HandBrakeHardwareEncoderHelper.IsQsvAvailable && (HandBrakeHardwareEncoderHelper.QsvHardwareGeneration > 6) && VideoEncoderHelpers.IsQuickSync(job.VideoEncoder))
            {
                if (enableQsvLowPower && !video.Options.Contains("lowpower"))
                {
                    video.Options = string.IsNullOrEmpty(video.Options) ? "lowpower=1" : string.Concat(video.Options, ":lowpower=1");
                }
                else if (!enableQsvLowPower && !video.Options.Contains("lowpower"))
                {
                    video.Options = string.IsNullOrEmpty(video.Options) ? "lowpower=0" : string.Concat(video.Options, ":lowpower=0");
                }
            }

            return(video);
        }