Beispiel #1
0
        /// <summary>
        /// The create video.
        /// </summary>
        /// <param name="job">
        /// The job.
        /// </param>
        /// <param name="configuration">
        /// The configuration.
        /// </param>
        /// <returns>
        /// The <see cref="Video"/>.
        /// </returns>
        private static Video CreateVideo(EncodeTask job, HBConfiguration configuration)
        {
            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.Id;
            }

            string advancedOptions = job.ShowAdvancedTab ? job.AdvancedEncoderOptions : string.Empty;

            if (!string.IsNullOrEmpty(advancedOptions))
            {
                video.Options = advancedOptions;
            }
            else
            {
                video.Level   = job.VideoLevel != null ? job.VideoLevel.ShortName : null;
                video.Options = job.ExtraAdvancedArguments;
                video.Preset  = job.VideoPreset != null ? job.VideoPreset.ShortName : null;
                video.Profile = job.VideoProfile != null ? job.VideoProfile.ShortName : null;

                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 = job.Quality;
            }
            if (job.VideoEncodeRateType == VideoEncodeRateType.AverageBitrate)
            {
                video.Bitrate = job.VideoBitrate;
                video.TwoPass = job.TwoPass;
                video.Turbo   = job.TurboFirstPass;
            }

            video.OpenCL = configuration.ScalingMode == VideoScaler.BicubicCl;

            video.QSV.Decode = SystemInfo.IsQsvAvailable && !configuration.DisableQuickSyncDecoding;

            // The use of the QSV decoder is configurable for non QSV encoders.
            if (video.QSV.Decode && job.VideoEncoder != VideoEncoder.QuickSync && job.VideoEncoder != VideoEncoder.QuickSyncH265)
            {
                video.QSV.Decode = configuration.UseQSVDecodeForNonQSVEnc;
            }

            return(video);
        }
Beispiel #2
0
        /// <summary>
        /// The create audio.
        /// </summary>
        /// <param name="job">
        /// The job.
        /// </param>
        /// <returns>
        /// The <see cref="Audio"/>.
        /// </returns>
        private static Audio CreateAudio(EncodeTask job)
        {
            Audio audio = new Audio();

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

            if (job.AllowedPassthruOptions.AudioAllowAACPass)
            {
                copyMaskList.Add(NativeConstants.HB_ACODEC_AAC_PASS);
            }
            if (job.AllowedPassthruOptions.AudioAllowAC3Pass)
            {
                copyMaskList.Add(NativeConstants.HB_ACODEC_AC3_PASS);
            }
            if (job.AllowedPassthruOptions.AudioAllowDTSHDPass)
            {
                copyMaskList.Add(NativeConstants.HB_ACODEC_DCA_HD_PASS);
            }
            if (job.AllowedPassthruOptions.AudioAllowDTSPass)
            {
                copyMaskList.Add(NativeConstants.HB_ACODEC_DCA_PASS);
            }
            if (job.AllowedPassthruOptions.AudioAllowEAC3Pass)
            {
                copyMaskList.Add(NativeConstants.HB_ACODEC_EAC3_PASS);
            }
            if (job.AllowedPassthruOptions.AudioAllowFlacPass)
            {
                copyMaskList.Add(NativeConstants.HB_ACODEC_FLAC_PASS);
            }
            if (job.AllowedPassthruOptions.AudioAllowMP3Pass)
            {
                copyMaskList.Add(NativeConstants.HB_ACODEC_MP3_PASS);
            }
            if (job.AllowedPassthruOptions.AudioAllowTrueHDPass)
            {
                copyMaskList.Add(NativeConstants.HB_ACODEC_TRUEHD_PASS);
            }
            audio.CopyMask = copyMaskList.ToArray();

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

            audio.FallbackEncoder = audioEncoder.Id;

            audio.AudioList = new List <HandBrake.ApplicationServices.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);

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

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

                HandBrake.ApplicationServices.Interop.Json.Encode.AudioTrack audioTrack = new HandBrake.ApplicationServices.Interop.Json.Encode.AudioTrack
                {
                    Track             = (item.Track.HasValue ? item.Track.Value : 0) - 1,
                    DRC               = item.DRC,
                    Encoder           = encoder.Id,
                    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);
        }