Ejemplo n.º 1
0
        /// <summary>
        /// Add the encode settings to the preset
        /// </summary>
        /// <param name="xmlWriter">
        /// The xml writer.
        /// </param>
        /// <param name="parsed">
        /// The parsed.
        /// </param>
        /// <param name="preset">
        /// The preset.
        /// </param>
        private static void AddEncodeSettings(XmlTextWriter xmlWriter, EncodeTask parsed, Preset preset)
        {
            AddEncodeElement(xmlWriter, "ChapterMarkers", "integer", parsed.IncludeChapterMarkers ? "1" : "0");
            AddEncodeElement(xmlWriter, "Default", "integer", "0");
            AddEncodeElement(xmlWriter, "FileFormat", "string", Converters.GetFileFormat(parsed.OutputFormat) + " file");
            AddBooleanElement(xmlWriter, "Folder", false);
            AddEncodeElement(xmlWriter, "Mp4HttpOptimize", "integer", parsed.OptimizeMP4 ? "1" : "0");
            AddEncodeElement(xmlWriter, "Mp4LargeFile", "integer", parsed.LargeFile ? "1" : "0");
            AddEncodeElement(xmlWriter, "Mp4iPodCompatible", "integer", parsed.IPod5GSupport ? "1" : "0");
            AddEncodeElement(xmlWriter, "PictureAutoCrop", "integer", "1");
            AddEncodeElement(xmlWriter, "PictureBottomCrop", "integer", parsed.Cropping.Bottom.ToString());

            // Filters
            AddEncodeElement(xmlWriter, "PictureDeblock", "integer", parsed.Deblock.ToString());

            switch (parsed.Decomb)
            {
            case Decomb.Off:
                AddEncodeElement(xmlWriter, "PictureDecomb", "integer", "0");
                AddEncodeElement(xmlWriter, "PictureDecombCustom", "string", string.Empty);
                break;

            case Decomb.Default:
                AddEncodeElement(xmlWriter, "PictureDecomb", "integer", "1");
                AddEncodeElement(xmlWriter, "PictureDecombCustom", "string", string.Empty);
                break;

            default:
                AddEncodeElement(xmlWriter, "PictureDecomb", "integer", "2");
                AddEncodeElement(xmlWriter, "PictureDecombCustom", "string", parsed.CustomDecomb);
                break;
            }
            AddEncodeElement(xmlWriter, "PictureDecombDeinterlace", "integer", parsed.Decomb != Decomb.Off ? "0" : "1");

            switch (parsed.Deinterlace)
            {
            case Deinterlace.Off:
                AddEncodeElement(xmlWriter, "PictureDeinterlace", "integer", "0");
                AddEncodeElement(xmlWriter, "PictureDeinterlaceCustom", "string", string.Empty);
                break;

            case Deinterlace.Fast:
                AddEncodeElement(xmlWriter, "PictureDeinterlace", "integer", "1");
                AddEncodeElement(xmlWriter, "PictureDeinterlaceCustom", "string", string.Empty);
                break;

            case Deinterlace.Slow:
                AddEncodeElement(xmlWriter, "PictureDeinterlace", "integer", "2");
                AddEncodeElement(xmlWriter, "PictureDeinterlaceCustom", "string", string.Empty);
                break;

            case Deinterlace.Slower:
                AddEncodeElement(xmlWriter, "PictureDeinterlace", "integer", "3");
                AddEncodeElement(xmlWriter, "PictureDeinterlaceCustom", "string", string.Empty);
                break;

            default:
                AddEncodeElement(xmlWriter, "PictureDeinterlace", "integer", "4");
                AddEncodeElement(xmlWriter, "PictureDeinterlaceCustom", "string", parsed.CustomDeinterlace);
                break;
            }

            switch (parsed.Denoise)
            {
            case Denoise.Off:
                AddEncodeElement(xmlWriter, "PictureDenoise", "integer", "0");
                AddEncodeElement(xmlWriter, "PictureDenoiseCustom", "string", string.Empty);
                break;

            case Denoise.Weak:
                AddEncodeElement(xmlWriter, "PictureDenoise", "integer", "1");
                AddEncodeElement(xmlWriter, "PictureDenoiseCustom", "string", string.Empty);
                break;

            case Denoise.Medium:
                AddEncodeElement(xmlWriter, "PictureDenoise", "integer", "2");
                AddEncodeElement(xmlWriter, "PictureDenoiseCustom", "string", string.Empty);
                break;

            case Denoise.Strong:
                AddEncodeElement(xmlWriter, "PictureDenoise", "integer", "3");
                AddEncodeElement(xmlWriter, "PictureDenoiseCustom", "string", string.Empty);
                break;

            default:
                AddEncodeElement(xmlWriter, "PictureDenoise", "integer", "4");
                AddEncodeElement(xmlWriter, "PictureDenoiseCustom", "string", parsed.CustomDenoise);
                break;
            }

            int detelecine;

            switch (parsed.Detelecine)
            {
            case Detelecine.Off:
                detelecine = 0;
                break;

            case Detelecine.Default:
                detelecine = 2;
                break;

            default:
                detelecine = 1;
                break;
            }

            AddEncodeElement(xmlWriter, "PictureDetelecine", "integer", detelecine.ToString());
            AddEncodeElement(xmlWriter, "PictureDetelecineCustom", "string", detelecine == 1 ? parsed.CustomDecomb : string.Empty);

            // Picture Settings
            AddEncodeElement(xmlWriter, "PictureHeight", "integer", parsed.Height.ToString());
            AddEncodeElement(xmlWriter, "PictureKeepRatio", "integer", parsed.KeepDisplayAspect ? "1" : "0");
            AddEncodeElement(xmlWriter, "PictureLeftCrop", "integer", parsed.Cropping.Left.ToString());
            AddEncodeElement(xmlWriter, "PictureModulus", "integer", parsed.Modulus.ToString());
            AddEncodeElement(xmlWriter, "PicturePAR", "integer", ((int)parsed.Anamorphic).ToString());
            AddEncodeElement(xmlWriter, "PictureRightCrop", "integer", parsed.Cropping.Right.ToString());
            AddEncodeElement(xmlWriter, "PictureTopCrop", "integer", parsed.Cropping.Top.ToString());
            AddEncodeElement(xmlWriter, "PictureWidth", "integer", parsed.Width.ToString());

            // Preset Information
            AddEncodeElement(xmlWriter, "PresetBuildNumber", "string", Properties.Settings.Default.HandBrakeBuild.ToString());
            AddEncodeElement(xmlWriter, "PresetDescription", "string", "No Description");
            AddEncodeElement(xmlWriter, "PresetName", "string", preset.Name);
            AddEncodeElement(xmlWriter, "Type", "integer", "1"); // 1 is user preset, 0 is built in

            // Preset Settings
            AddEncodeElement(xmlWriter, "UsesMaxPictureSettings", "integer", (parsed.MaxWidth != 0 || parsed.MaxHeight != 0) ? "1" : "0");
            AddEncodeElement(xmlWriter, "UsesPictureFilters", "integer", "1");
            AddEncodeElement(xmlWriter, "UsesPictureSettings", "integer", "2");

            // Video Settings
            AddEncodeElement(xmlWriter, "VideoAvgBitrate", "string", parsed.VideoBitrate.ToString());
            AddEncodeElement(xmlWriter, "VideoEncoder", "string", EnumHelper <Enum> .GetDescription(parsed.VideoEncoder));
            AddEncodeElement(xmlWriter, "VideoFramerate", "string", parsed.Framerate.ToString());
            AddEncodeElement(xmlWriter, "VideFrameratePFR", "integer", parsed.FramerateMode == FramerateMode.PFR ? "1" : "0");
            AddEncodeElement(xmlWriter, "VideoGrayScale", "integer", parsed.Grayscale ? "1" : "0");
            AddEncodeElement(xmlWriter, "VideoQualitySlider", "real", parsed.Quality.ToString());

            int videoQualityType = 0;

            if (parsed.VideoBitrate != null)
            {
                videoQualityType = 1;
            }
            else if (parsed.Quality != null)
            {
                videoQualityType = 2;
            }

            AddEncodeElement(xmlWriter, "VideoQualityType", "integer", videoQualityType.ToString());
            AddEncodeElement(xmlWriter, "VideoTargetSize", "string", string.Empty);
            AddEncodeElement(xmlWriter, "VideoTurboTwoPass", "integer", parsed.TurboFirstPass ? "1" : "0");
            AddEncodeElement(xmlWriter, "VideoTwoPass", "integer", parsed.TwoPass ? "1" : "0");

            // x264 string
            AddEncodeElement(xmlWriter, "x264Option", "string", parsed.AdvancedEncoderOptions);
        }