예제 #1
0
        private static string AudioSettingsQuery(EncodeTask task)
        {
            string query = string.Empty;

            List <AudioTrack> audioTracks = task.AudioTracks;

            List <int>          tracks      = new List <int>();
            List <AudioEncoder> codecs      = new List <AudioEncoder>();
            List <Mixdown>      mixdowns    = new List <Mixdown>();
            List <double>       samplerates = new List <double>();
            List <int>          bitrates    = new List <int>();
            List <double>       drcs        = new List <double>();

            // No Audio
            if (audioTracks.Count == 0)
            {
                query += " -a none ";
            }

            // Gather information about each audio track and store them in the declared lists.
            foreach (AudioTrack track in audioTracks)
            {
                if (track.Track == null)
                {
                    continue;
                }

                tracks.Add(track.Track.Value);

                // Audio Codec (-E)
                codecs.Add(track.Encoder);

                // Audio Mixdown (-6)
                mixdowns.Add(track.MixDown);

                // Sample Rate (-R)
                samplerates.Add(track.SampleRate);

                // Audio Bitrate (-B)
                bitrates.Add(track.Bitrate);

                // DRC (-D)
                drcs.Add(track.DRC);
            }

            // Audio Track (-a)
            string audioItems = string.Empty;
            bool   firstLoop  = true;

            foreach (int item in tracks)
            {
                if (firstLoop)
                {
                    audioItems = item.ToString();
                    firstLoop  = false;
                }
                else
                {
                    audioItems += "," + item;
                }
            }
            if (audioItems.Trim() != String.Empty)
            {
                query += " -a " + audioItems;
            }
            firstLoop  = true;
            audioItems = string.Empty; // Reset for another pass.

            // Audio Codec (-E)
            foreach (AudioEncoder item in codecs)
            {
                if (firstLoop)
                {
                    audioItems = Converters.GetCliAudioEncoder(item);
                    firstLoop  = false;
                }
                else
                {
                    audioItems += "," + item;
                }
            }
            if (audioItems.Trim() != String.Empty)
            {
                query += " -E " + audioItems;
            }
            firstLoop  = true;
            audioItems = string.Empty; // Reset for another pass.

            // Audio Mixdown (-6)
            foreach (Mixdown item in mixdowns)
            {
                if (firstLoop)
                {
                    audioItems = Converters.GetCliMixDown(item);
                    firstLoop  = false;
                }
                else
                {
                    audioItems += "," + item;
                }
            }
            if (audioItems.Trim() != String.Empty)
            {
                query += " -6 " + audioItems;
            }
            firstLoop  = true;
            audioItems = string.Empty; // Reset for another pass.

            // Sample Rate (-R)
            foreach (double item in samplerates)
            {
                if (firstLoop)
                {
                    audioItems = item.ToString();
                    firstLoop  = false;
                }
                else
                {
                    audioItems += "," + item;
                }
            }
            if (audioItems.Trim() != String.Empty)
            {
                query += " -R " + audioItems;
            }
            firstLoop  = true;
            audioItems = string.Empty; // Reset for another pass.

            // Audio Bitrate (-B)
            foreach (int item in bitrates)
            {
                if (firstLoop)
                {
                    audioItems = item.ToString();
                    firstLoop  = false;
                }
                else
                {
                    audioItems += "," + item;
                }
            }
            if (audioItems.Trim() != String.Empty)
            {
                query += " -B " + audioItems;
            }
            firstLoop  = true;
            audioItems = string.Empty; // Reset for another pass.

            // DRC (-D)
            foreach (var itm in drcs)
            {
                string item = itm.ToString(new CultureInfo("en-US"));
                if (firstLoop)
                {
                    audioItems = item;
                    firstLoop  = false;
                }
                else
                {
                    audioItems += "," + item;
                }
            }
            if (audioItems.Trim() != String.Empty)
            {
                query += " -D " + audioItems;
            }

            return(query);
        }
예제 #2
0
        /// <summary>
        /// Takes in a query which can be in any order and parses it.
        /// All varibles are then set so they can be used elsewhere.
        /// </summary>
        /// <param name="input">A ClI Query</param>
        /// <returns>A Parsed Query</returns>
        public static EncodeTask Parse(string input)
        {
            var parsed = new EncodeTask();

            #region Regular Expressions

            // Source
            Match title    = Regex.Match(input, @"-t ([0-9]*)");
            Match chapters = Regex.Match(input, @"-c ([0-9-]*)");

            // Output Settings
            Match format    = Regex.Match(input, @"-f ([a-zA-Z0-9]*)");
            Match grayscale = Regex.Match(input, @" -g");
            Match largerMp4 = Regex.Match(input, @" -4");
            Match ipodAtom  = Regex.Match(input, @" -I");

            // Picture Settings Tab
            Match width     = Regex.Match(input, @"-w ([0-9]*)");
            Match height    = Regex.Match(input, @"-l ([0-9]*)");
            Match maxWidth  = Regex.Match(input, @"-X ([0-9]*)");
            Match maxHeight = Regex.Match(input, @"-Y ([0-9]*)");
            Match crop      = Regex.Match(input, @"--crop ([0-9]*):([0-9]*):([0-9]*):([0-9]*)");

            Match looseAnamorphic  = Regex.Match(input, @"--loose-anamorphic");
            Match strictAnamorphic = Regex.Match(input, @"--strict-anamorphic");
            Match customAnamorphic = Regex.Match(input, @"--custom-anamorphic");

            Match keepDisplayAsect = Regex.Match(input, @"--keep-display-aspect");
            Match displayWidth     = Regex.Match(input, @"--display-width ([0-9]*)");
            Match pixelAspect      = Regex.Match(input, @"--pixel-aspect ([0-9]*):([0-9]*)");
            Match modulus          = Regex.Match(input, @"--modulus ([0-9]*)");

            // Picture Settings - Filters
            Match decomb          = Regex.Match(input, @" --decomb");
            Match decombValue     = Regex.Match(input, @" --decomb=\""([a-zA-Z0-9.:]*)\""");
            Match deinterlace     = Regex.Match(input, @"--deinterlace=\""([a-zA-Z0-9.:]*)\""");
            Match denoise         = Regex.Match(input, @"--denoise=\""([a-zA-Z0-9.:]*)\""");
            Match deblock         = Regex.Match(input, @"--deblock=([0-9:]*)");
            Match detelecine      = Regex.Match(input, @"--detelecine");
            Match detelecineValue = Regex.Match(input, @" --detelecine=\""([a-zA-Z0-9.:]*)\""");

            // Video Settings Tab
            Match videoEncoder   = Regex.Match(input, @"-e ([a-zA-Z0-9]*)");
            Match videoFramerate = Regex.Match(input, @"-r ([0-9.]*)");
            Match videoBitrate   = Regex.Match(input, @"-b ([0-9]*)");
            Match videoQuality   = Regex.Match(input, @"-q ([0-9.]*)");
            Match twoPass        = Regex.Match(input, @" -2");
            Match turboFirstPass = Regex.Match(input, @" -T");
            Match optimizeMP4    = Regex.Match(input, @" -O");
            Match pfr            = Regex.Match(input, @" --pfr");
            Match vfr            = Regex.Match(input, @" --vfr");
            Match cfr            = Regex.Match(input, @" --cfr");

            // Audio Settings Tab
            Match noAudio          = Regex.Match(input, @"-a none");
            Match audioTracks      = Regex.Match(input, @"-a ([0-9,]*)");
            Match audioTrackMixes  = Regex.Match(input, @"-6 ([0-9a-zA-Z,]*)");
            Match audioEncoders    = Regex.Match(input, @"-E ([a-zA-Z0-9+,:]*)");
            Match audioBitrates    = Regex.Match(input, @"-B ([0-9a-zA-Z,]*)");  // Auto = a-z
            Match audioSampleRates = Regex.Match(input, @"-R ([0-9a-zA-Z.,]*)"); // Auto = a-z
            Match drcValues        = Regex.Match(input, @"-D ([0-9.,]*)");
            Match gainValues       = Regex.Match(input, @"--gain=([0-9.,-]*)");

            // Chapters Tab
            Match chapterMarkers         = Regex.Match(input, @" -m");
            Match chapterMarkersFileMode = Regex.Match(input, @"--markers");

            // Advanced Tab
            Match advanced = Regex.Match(input, @"-x ([.,/a-zA-Z0-9=:-]*)");

            #endregion

            #region Set Varibles

            try
            {
                #region Source Tab

                if (title.Success)
                {
                    parsed.Title = int.Parse(title.ToString().Replace("-t ", string.Empty));
                }

                if (chapters.Success)
                {
                    parsed.PointToPointMode = PointToPointMode.Chapters;
                    string[] actTitles = chapters.ToString().Replace("-c ", string.Empty).Split('-');
                    parsed.StartPoint = int.Parse(actTitles[0]);
                    if (actTitles.Length > 1)
                    {
                        parsed.EndPoint = int.Parse(actTitles[1]);
                    }

                    if ((parsed.StartPoint == 1) && (parsed.EndPoint == 0))
                    {
                        parsed.EndPoint = parsed.StartPoint;
                    }
                }

                #endregion

                #region Output Settings

                if (format.Success)
                {
                    parsed.OutputFormat = Converters.GetFileFormat(format.Groups[1].ToString());
                }
                parsed.LargeFile     = largerMp4.Success;
                parsed.IPod5GSupport = ipodAtom.Success;
                parsed.OptimizeMP4   = optimizeMP4.Success;

                #endregion

                #region Picture Tab

                if (width.Success)
                {
                    parsed.Width = int.Parse(width.Groups[0].Value.Replace("-w ", string.Empty));
                }

                if (height.Success)
                {
                    parsed.Height = int.Parse(height.Groups[0].Value.Replace("-l ", string.Empty));
                }

                if (maxWidth.Success)
                {
                    parsed.MaxWidth = int.Parse(maxWidth.Groups[0].Value.Replace("-X ", string.Empty));
                }

                if (maxHeight.Success)
                {
                    parsed.MaxHeight = int.Parse(maxHeight.Groups[0].Value.Replace("-Y ", string.Empty));
                }

                if (crop.Success)
                {
                    try
                    {
                        string   values        = crop.ToString().Replace("--crop ", string.Empty);
                        string[] actCropValues = values.Split(':');
                        parsed.Cropping = new Cropping(
                            int.Parse(actCropValues[0]),
                            int.Parse(actCropValues[1]),
                            int.Parse(actCropValues[2]),
                            int.Parse(actCropValues[3]));
                        parsed.HasCropping = true;
                    }
                    catch (Exception)
                    {
                        parsed.Cropping    = null;
                        parsed.HasCropping = false;
                        // No need to do anything.
                    }
                }

                if (strictAnamorphic.Success)
                {
                    parsed.Anamorphic = Anamorphic.Strict;
                }
                else if (looseAnamorphic.Success)
                {
                    parsed.Anamorphic = Anamorphic.Loose;
                }
                else if (customAnamorphic.Success)
                {
                    parsed.Anamorphic = Anamorphic.Custom;
                }
                else
                {
                    parsed.Anamorphic = Anamorphic.None;
                }

                parsed.KeepDisplayAspect = keepDisplayAsect.Success;

                if (displayWidth.Success)
                {
                    parsed.DisplayWidth =
                        double.Parse(displayWidth.Groups[0].Value.Replace("--display-width ", string.Empty), Culture);
                }

                if (pixelAspect.Success)
                {
                    parsed.PixelAspectX = int.Parse(pixelAspect.Groups[1].Value.Replace("--pixel-aspect ", string.Empty));
                }

                if (pixelAspect.Success && pixelAspect.Groups.Count >= 3)
                {
                    parsed.PixelAspectY = int.Parse(pixelAspect.Groups[2].Value.Replace("--pixel-aspect ", string.Empty));
                }

                if (modulus.Success)
                {
                    parsed.Modulus = int.Parse(modulus.Groups[0].Value.Replace("--modulus ", string.Empty));
                }

                #endregion

                #region Filters

                parsed.Decomb = Decomb.Off;
                if (decomb.Success)
                {
                    parsed.Decomb = Decomb.Default;
                    if (decombValue.Success)
                    {
                        parsed.CustomDecomb = decombValue.ToString().Replace("--decomb=", string.Empty).Replace("\"", string.Empty);
                    }
                }

                parsed.Deinterlace = Deinterlace.Off;
                if (deinterlace.Success)
                {
                    switch (deinterlace.ToString().Replace("--deinterlace=", string.Empty).Replace("\"", string.Empty).ToLower())
                    {
                    case "fast":
                        parsed.Deinterlace = Deinterlace.Fast;
                        break;

                    case "slow":
                        parsed.Deinterlace = Deinterlace.Slow;
                        break;

                    case "slower":
                        parsed.Deinterlace = Deinterlace.Slower;
                        break;

                    default:
                        parsed.Deinterlace       = Deinterlace.Custom;
                        parsed.CustomDeinterlace = deinterlace.ToString().Replace("--deinterlace=", string.Empty).Replace("\"", string.Empty).ToLower();
                        break;
                    }
                }

                parsed.Denoise = Denoise.Off;
                if (denoise.Success)
                {
                    switch (denoise.ToString().Replace("--denoise=", string.Empty).Replace("\"", string.Empty))
                    {
                    case "weak":
                        parsed.Denoise = Denoise.Weak;
                        break;

                    case "medium":
                        parsed.Denoise = Denoise.Medium;
                        break;

                    case "strong":
                        parsed.Denoise = Denoise.Strong;
                        break;

                    default:
                        parsed.Denoise       = Denoise.Custom;
                        parsed.CustomDenoise = denoise.ToString().Replace("--denoise=", string.Empty).Replace("\"", string.Empty);
                        break;
                    }
                }

                parsed.Deblock = 0;
                if (deblock.Success)
                {
                    int dval;
                    int.TryParse(deblock.ToString().Replace("--deblock=", string.Empty), out dval);
                    parsed.Deblock = dval;
                }

                parsed.Detelecine = Detelecine.Off;
                if (detelecine.Success)
                {
                    parsed.Detelecine = Detelecine.Default;
                    if (detelecineValue.Success)
                    {
                        parsed.CustomDetelecine = detelecineValue.ToString().Replace("--detelecine=", string.Empty).Replace("\"", string.Empty);
                        parsed.Detelecine       = Detelecine.Custom;
                    }
                }

                #endregion

                #region Video Settings Tab

                parsed.VideoEncoder = Converters.GetVideoEncoder(videoEncoder.ToString().Replace("-e ", string.Empty));

                if (videoFramerate.Success)
                {
                    double fps;
                    double.TryParse(videoFramerate.Groups[1].ToString(), out fps);
                    parsed.Framerate = fps;
                }

                if (pfr.Success)
                {
                    parsed.FramerateMode = FramerateMode.PFR;
                }
                else if (cfr.Success)
                {
                    parsed.FramerateMode = FramerateMode.CFR;
                }
                else
                {
                    parsed.FramerateMode = FramerateMode.VFR; // Default to VFR
                }
                parsed.Grayscale      = grayscale.Success;
                parsed.TwoPass        = twoPass.Success;
                parsed.TurboFirstPass = turboFirstPass.Success;

                if (videoBitrate.Success)
                {
                    parsed.VideoEncodeRateType = VideoEncodeRateType.AverageBitrate;
                    parsed.VideoBitrate        = int.Parse(videoBitrate.ToString().Replace("-b ", string.Empty));
                }

                if (videoQuality.Success)
                {
                    float quality = float.Parse(videoQuality.ToString().Replace("-q ", string.Empty), Culture);
                    parsed.Quality = quality;
                }

                #endregion

                #region Audio Tab

                // Find out how many tracks we need to add by checking how many encoders or audio tracks are selected.
                int encoderCount = 0;
                if (audioEncoders.Success)
                {
                    string[] audioDataCounters = audioEncoders.ToString().Replace("-E ", string.Empty).Split(',');
                    encoderCount = audioDataCounters.Length;
                }

                // Get the data from the regular expression results
                string[] trackData        = null;
                string[] trackMixes       = null;
                string[] trackEncoders    = null;
                string[] trackBitrates    = null;
                string[] trackSamplerates = null;
                string[] trackDRCvalues   = null;
                string[] trackGainValues  = null;

                if (audioTracks.Success)
                {
                    trackData = audioTracks.ToString().Replace("-a ", string.Empty).Split(',');
                }
                if (audioTrackMixes.Success)
                {
                    trackMixes = audioTrackMixes.ToString().Replace("-6 ", string.Empty).Split(',');
                }
                if (audioEncoders.Success)
                {
                    trackEncoders = audioEncoders.ToString().Replace("-E ", string.Empty).Split(',');
                }
                if (audioBitrates.Success)
                {
                    trackBitrates = audioBitrates.ToString().Replace("-B ", string.Empty).Split(',');
                }
                if (audioSampleRates.Success)
                {
                    trackSamplerates = audioSampleRates.ToString().Replace("-R ", string.Empty).Split(',');
                }
                if (drcValues.Success)
                {
                    trackDRCvalues = drcValues.ToString().Replace("-D ", string.Empty).Split(',');
                }
                if (gainValues.Success)
                {
                    trackGainValues = gainValues.ToString().Replace("--gain=", string.Empty).Split(',');
                }

                // Create new Audio Track Classes and store them in the ArrayList
                List <AudioTrack> allAudioTrackInfo = new List <AudioTrack>();
                for (int x = 0; x < encoderCount; x++)
                {
                    AudioTrack track = new AudioTrack();
                    //if (trackData != null)
                    //    if (trackData.Length >= (x + 1)) // Audio Track
                    //        track.ScannedTrack = trackData[x].Trim();

                    if (trackMixes != null)
                    {
                        if (trackMixes.Length >= (x + 1)) // Audio Mix
                        {
                            track.MixDown = Converters.GetAudioMixDown(Converters.GetMixDown(trackMixes[x].Trim()));
                        }
                    }

                    if (trackEncoders != null)
                    {
                        if (trackEncoders.Length >= (x + 1)) // Audio Mix
                        {
                            track.Encoder = Converters.GetAudioEncoderFromCliString(trackEncoders[x].Trim());
                        }
                    }

                    if (trackBitrates != null)
                    {
                        if (trackBitrates.Length >= (x + 1)) // Audio Encoder
                        {
                            track.Bitrate = int.Parse(trackBitrates[x].Trim() == "auto" ? "0" : trackBitrates[x].Trim());
                        }
                    }

                    if (trackSamplerates != null)
                    {
                        if (trackSamplerates.Length >= (x + 1)) // Audio SampleRate
                        {
                            track.SampleRate = double.Parse(trackSamplerates[x].Replace("Auto", "0").Trim(), Culture);
                        }
                    }

                    if (trackDRCvalues != null)
                    {
                        if (trackDRCvalues.Length >= (x + 1)) // Audio DRC Values
                        {
                            track.DRC = double.Parse(trackDRCvalues[x].Trim(), Culture);
                        }
                    }

                    if (trackGainValues != null)
                    {
                        if (trackGainValues.Length >= (x + 1)) // Audio DRC Values
                        {
                            track.Gain = int.Parse(trackGainValues[x].Trim());
                        }
                    }

                    allAudioTrackInfo.Add(track);
                }

                parsed.AudioTracks = allAudioTrackInfo;

                #endregion

                #region Chapters Tab

                if (chapterMarkersFileMode.Success || chapterMarkers.Success)
                {
                    parsed.IncludeChapterMarkers = true;
                }

                #endregion

                #region Advanced and other

                if (advanced.Success)
                {
                    parsed.AdvancedEncoderOptions = advanced.ToString().Replace("-x ", string.Empty);
                }

                #endregion
            }
            catch (Exception exc)
            {
                throw new Exception("An error has occured in the QueryParser Utility.", exc);
            }

            #endregion

            return(parsed);
        }
예제 #3
0
        /// <summary>
        /// Takes in a query which can be in any order and parses it.
        /// All varibles are then set so they can be used elsewhere.
        /// </summary>
        /// <param name="input">A ClI Query</param>
        /// <returns>A Parsed Query</returns>
        public static EncodeTask Parse(string input)
        {
            var parsed = new EncodeTask();

            #region Regular Expressions

            // Source
            Match title    = Regex.Match(input, @"-t ([0-9]+)");
            Match chapters = Regex.Match(input, @"-c ([0-9-]+)");

            // Output Settings
            Match format    = Regex.Match(input, @"-f ([a-zA-Z0-9]+)");
            Match grayscale = Regex.Match(input, @" -g");
            Match ipodAtom  = Regex.Match(input, @" -I");

            // Picture Settings Tab
            Match width     = Regex.Match(input, @"-w ([0-9]+)");
            Match height    = Regex.Match(input, @"-l ([0-9]+)");
            Match maxWidth  = Regex.Match(input, @"-X ([0-9]+)");
            Match maxHeight = Regex.Match(input, @"-Y ([0-9]+)");
            Match crop      = Regex.Match(input, @"--crop ([0-9]*):([0-9]*):([0-9]*):([0-9]*)");

            Match looseAnamorphic  = Regex.Match(input, @"--loose-anamorphic");
            Match strictAnamorphic = Regex.Match(input, @"--strict-anamorphic");
            Match customAnamorphic = Regex.Match(input, @"--custom-anamorphic");

            Match keepDisplayAsect = Regex.Match(input, @"--keep-display-aspect");
            Match displayWidth     = Regex.Match(input, @"--display-width ([0-9]*)");
            Match pixelAspect      = Regex.Match(input, @"--pixel-aspect ([0-9]*):([0-9]*)");
            Match modulus          = Regex.Match(input, @"--modulus ([0-9]*)");

            // Picture Settings - Filters
            Match decomb          = Regex.Match(input, @" --decomb");
            Match decombValue     = Regex.Match(input, @" --decomb=([a-zA-Z0-9.:""\\]*)");
            Match deinterlace     = Regex.Match(input, @"--deinterlace=\""([a-zA-Z0-9.:]*)\""");
            Match denoise         = Regex.Match(input, @"--denoise=\""([a-zA-Z0-9.:]*)\""");
            Match nlmeans         = Regex.Match(input, @"--nlmeans=\""([a-zA-Z0-9.:]*)\""");
            Match nlmeansTune     = Regex.Match(input, @"--nlmeans-tune=\""([a-zA-Z0-9.:]*)\""");
            Match deblock         = Regex.Match(input, @"--deblock=([0-9:]*)");
            Match detelecine      = Regex.Match(input, @"--detelecine");
            Match detelecineValue = Regex.Match(input, @" --detelecine=\""([a-zA-Z0-9.:]*)\""");

            // Video Settings Tab
            Match videoEncoder   = Regex.Match(input, @"-e ([a-zA-Z0-9]+)");
            Match videoFramerate = Regex.Match(input, @"-r ([0-9.]+)");
            Match videoBitrate   = Regex.Match(input, @"-b ([0-9]+)");
            Match videoQuality   = Regex.Match(input, @"-q ([0-9.]+)");
            Match twoPass        = Regex.Match(input, @" -2");
            Match turboFirstPass = Regex.Match(input, @" -T");
            Match optimizeMP4    = Regex.Match(input, @" -O");
            Match pfr            = Regex.Match(input, @" --pfr");
            Match cfr            = Regex.Match(input, @" --cfr");

            // Audio Settings Tab
            Match audioTrackMixes  = Regex.Match(input, @"-6 ([0-9a-zA-Z,]+)");
            Match audioEncoders    = Regex.Match(input, @"-E ([a-zA-Z0-9+,:\*]+)");
            Match audioBitrates    = Regex.Match(input, @"-B ([0-9a-zA-Z,]+)");  // Auto = a-z
            Match audioSampleRates = Regex.Match(input, @"-R ([0-9a-zA-Z.,]+)"); // Auto = a-z
            Match drcValues        = Regex.Match(input, @"-D ([0-9.,]+)");
            Match gainValues       = Regex.Match(input, @"--gain=([0-9.,-]+)");
            Match fallbackEncoder  = Regex.Match(input, @"--audio-fallback([a-zA-Z0-9:=\s ]*)");
            Match allowedPassthru  = Regex.Match(input, @"--audio-copy-mask([a-zA-Z0-9:,=\s ]*)");

            // Chapters Tab
            Match chapterMarkers         = Regex.Match(input, @" -m");
            Match chapterMarkersFileMode = Regex.Match(input, @"--markers");

            // Advanced Tab
            Match advanced    = Regex.Match(input, @"-x ([.,/a-zA-Z0-9=:-]*)");
            Match x264Preset  = Regex.Match(input, @"--x264-preset([=a-zA-Z0-9\s ]*)");
            Match x264Tune    = Regex.Match(input, @"--x264-tune([=,a-zA-Z0-9\s ]*)");
            Match h264Profile = Regex.Match(input, @"--h264-profile([=a-zA-Z0-9\s ]*)");
            Match x264Profile = Regex.Match(input, @"--x264-profile([=a-zA-Z0-9\s ]*)");
            Match h264Level   = Regex.Match(input, @"--h264-level([=a-zA-Z0-9.\s ]*)");

            Match x265Profile = Regex.Match(input, @"--x265-profile([=a-zA-Z0-9\s ]*)");
            Match x265Tune    = Regex.Match(input, @"--x265-tune([=,a-zA-Z0-9\s ]*)");
            Match x265Preset  = Regex.Match(input, @"--x265-preset([=a-zA-Z0-9\s ]*)");
            #endregion

            #region Set Varibles

            try
            {
                #region Source Tab

                if (title.Success)
                {
                    parsed.Title = int.Parse(title.ToString().Replace("-t ", string.Empty));
                }

                if (chapters.Success)
                {
                    parsed.PointToPointMode = PointToPointMode.Chapters;
                    string[] actTitles = chapters.ToString().Replace("-c ", string.Empty).Split('-');
                    parsed.StartPoint = int.Parse(actTitles[0]);
                    if (actTitles.Length > 1)
                    {
                        parsed.EndPoint = int.Parse(actTitles[1]);
                    }

                    if ((parsed.StartPoint == 1) && (parsed.EndPoint == 0))
                    {
                        parsed.EndPoint = parsed.StartPoint;
                    }
                }

                #endregion

                #region Output Settings

                if (format.Success)
                {
                    parsed.OutputFormat = Converters.GetFileFormat(format.Groups[1].ToString());
                }
                parsed.IPod5GSupport = ipodAtom.Success;
                parsed.OptimizeMP4   = optimizeMP4.Success;

                #endregion

                #region Picture Tab

                if (width.Success)
                {
                    parsed.Width = int.Parse(width.Groups[0].Value.Replace("-w ", string.Empty));
                }

                if (height.Success)
                {
                    parsed.Height = int.Parse(height.Groups[0].Value.Replace("-l ", string.Empty));
                }

                if (maxWidth.Success)
                {
                    parsed.MaxWidth = int.Parse(maxWidth.Groups[0].Value.Replace("-X ", string.Empty));
                }

                if (maxHeight.Success)
                {
                    parsed.MaxHeight = int.Parse(maxHeight.Groups[0].Value.Replace("-Y ", string.Empty));
                }

                if (crop.Success)
                {
                    try
                    {
                        string   values        = crop.ToString().Replace("--crop ", string.Empty);
                        string[] actCropValues = values.Split(':');
                        parsed.Cropping = new Cropping(
                            int.Parse(actCropValues[0]),
                            int.Parse(actCropValues[1]),
                            int.Parse(actCropValues[2]),
                            int.Parse(actCropValues[3]));
                        parsed.HasCropping = true;
                    }
                    catch (Exception)
                    {
                        parsed.Cropping    = null;
                        parsed.HasCropping = false;
                        // No need to do anything.
                    }
                }

                if (strictAnamorphic.Success)
                {
                    parsed.Anamorphic = Anamorphic.Strict;
                }
                else if (looseAnamorphic.Success)
                {
                    parsed.Anamorphic = Anamorphic.Loose;
                }
                else if (customAnamorphic.Success)
                {
                    parsed.Anamorphic = Anamorphic.Custom;
                }
                else
                {
                    parsed.Anamorphic = Anamorphic.None;
                }

                parsed.KeepDisplayAspect = keepDisplayAsect.Success;

                if (displayWidth.Success)
                {
                    parsed.DisplayWidth =
                        double.Parse(displayWidth.Groups[0].Value.Replace("--display-width ", string.Empty), Culture);
                }

                if (pixelAspect.Success)
                {
                    parsed.PixelAspectX = int.Parse(pixelAspect.Groups[1].Value.Replace("--pixel-aspect ", string.Empty));
                }

                if (pixelAspect.Success && pixelAspect.Groups.Count >= 3)
                {
                    parsed.PixelAspectY = int.Parse(pixelAspect.Groups[2].Value.Replace("--pixel-aspect ", string.Empty));
                }

                if (modulus.Success)
                {
                    parsed.Modulus = int.Parse(modulus.Groups[0].Value.Replace("--modulus ", string.Empty));
                }

                #endregion

                #region Filters

                parsed.Decomb = Decomb.Off;
                if (decomb.Success)
                {
                    parsed.Decomb = Decomb.Default;
                    if (decombValue.Success)
                    {
                        string value = decombValue.ToString().Replace("--decomb=", string.Empty).Replace("\"", string.Empty).Trim();

                        if (value == "bob")
                        {
                            parsed.Decomb = Decomb.Bob;
                        }
                        else if (value == "fast")
                        {
                            parsed.Decomb = Decomb.Fast;
                        }
                        else
                        {
                            parsed.CustomDecomb = value;
                            parsed.Decomb       = parsed.CustomDecomb == "7:2:6:9:1:80" ? Decomb.Fast : Decomb.Custom;
                        }
                    }
                }

                parsed.Deinterlace = Deinterlace.Off;
                if (deinterlace.Success)
                {
                    switch (deinterlace.ToString().Replace("--deinterlace=", string.Empty).Replace("\"", string.Empty).ToLower())
                    {
                    case "fast":
                        parsed.Deinterlace = Deinterlace.Fast;
                        break;

                    case "slow":
                        parsed.Deinterlace = Deinterlace.Slow;
                        break;

                    case "slower":
                        parsed.Deinterlace = Deinterlace.Slower;
                        break;

                    case "bob":
                        parsed.Deinterlace = Deinterlace.Bob;
                        break;

                    default:
                        parsed.Deinterlace       = Deinterlace.Custom;
                        parsed.CustomDeinterlace = deinterlace.ToString().Replace("--deinterlace=", string.Empty).Replace("\"", string.Empty).ToLower();
                        break;
                    }
                }

                parsed.Denoise = Denoise.Off;
                if (denoise.Success)
                {
                    parsed.Denoise = Denoise.hqdn3d;
                    switch (denoise.ToString().Replace("--denoise=", string.Empty).Replace("\"", string.Empty))
                    {
                    case "weak":
                        parsed.DenoisePreset = DenoisePreset.Weak;
                        break;

                    case "medium":
                        parsed.DenoisePreset = DenoisePreset.Medium;
                        break;

                    case "strong":
                        parsed.DenoisePreset = DenoisePreset.Strong;
                        break;

                    default:
                        parsed.DenoisePreset = DenoisePreset.Custom;
                        parsed.CustomDenoise = denoise.ToString().Replace("--denoise=", string.Empty).Replace("\"", string.Empty);
                        break;
                    }
                }

                if (nlmeans.Success)
                {
                    parsed.Denoise = Denoise.NlMeans;
                    switch (nlmeans.ToString().Replace("--nlmeans=", string.Empty).Replace("\"", string.Empty))
                    {
                    case "ultralight":
                        parsed.DenoisePreset = DenoisePreset.Ultralight;
                        break;

                    case "light":
                        parsed.DenoisePreset = DenoisePreset.Light;
                        break;

                    case "medium":
                        parsed.DenoisePreset = DenoisePreset.Medium;
                        break;

                    case "strong":
                        parsed.DenoisePreset = DenoisePreset.Strong;
                        break;
                    }

                    if (nlmeansTune.Success)
                    {
                        switch (nlmeansTune.ToString().Replace("--nlmeans-tune=", string.Empty).Replace("\"", string.Empty))
                        {
                        case "animation":
                            parsed.DenoiseTune = DenoiseTune.Animation;
                            break;

                        case "film":
                            parsed.DenoiseTune = DenoiseTune.Film;
                            break;

                        case "grain":
                            parsed.DenoiseTune = DenoiseTune.Grain;
                            break;

                        case "highmotion":
                            parsed.DenoiseTune = DenoiseTune.HighMotion;
                            break;
                        }
                    }
                }

                parsed.Deblock = 0;
                if (deblock.Success)
                {
                    int dval;
                    int.TryParse(deblock.ToString().Replace("--deblock=", string.Empty), out dval);
                    parsed.Deblock = dval;
                }

                parsed.Detelecine = Detelecine.Off;
                if (detelecine.Success)
                {
                    parsed.Detelecine = Detelecine.Default;
                    if (detelecineValue.Success)
                    {
                        parsed.CustomDetelecine = detelecineValue.ToString().Replace("--detelecine=", string.Empty).Replace("\"", string.Empty);
                        parsed.Detelecine       = Detelecine.Custom;
                    }
                }

                #endregion

                #region Video Settings Tab

                parsed.VideoEncoder = videoEncoder.Success
                                          ? Converters.GetVideoEncoder(videoEncoder.ToString().Replace("-e ", string.Empty))
                                          : VideoEncoder.FFMpeg;

                if (videoFramerate.Success)
                {
                    double fps;
                    double.TryParse(videoFramerate.Groups[1].ToString(), NumberStyles.Any, CultureInfo.InvariantCulture, out fps);
                    parsed.Framerate = fps;
                }

                if (pfr.Success)
                {
                    parsed.FramerateMode = FramerateMode.PFR;
                }
                else if (cfr.Success)
                {
                    parsed.FramerateMode = FramerateMode.CFR;
                }
                else
                {
                    parsed.FramerateMode = FramerateMode.VFR; // Default to VFR
                }
                parsed.Grayscale      = grayscale.Success;
                parsed.TwoPass        = twoPass.Success;
                parsed.TurboFirstPass = turboFirstPass.Success;

                if (videoBitrate.Success)
                {
                    parsed.VideoEncodeRateType = VideoEncodeRateType.AverageBitrate;
                    parsed.VideoBitrate        = int.Parse(videoBitrate.ToString().Replace("-b ", string.Empty));
                }

                if (videoQuality.Success)
                {
                    float quality = float.Parse(videoQuality.ToString().Replace("-q ", string.Empty), Culture);
                    parsed.Quality = quality;

                    parsed.VideoEncodeRateType = VideoEncodeRateType.ConstantQuality;
                }

                #endregion

                #region Audio Tab

                // Find out how many tracks we need to add by checking how many encoders or audio tracks are selected.
                int encoderCount = 0;
                if (audioEncoders.Success)
                {
                    string[] audioDataCounters = audioEncoders.ToString().Replace("-E ", string.Empty).Split(',');
                    encoderCount = audioDataCounters.Length;
                }

                // Get the data from the regular expression results
                string[] trackMixes       = null;
                string[] trackEncoders    = null;
                string[] trackBitrates    = null;
                string[] trackSamplerates = null;
                string[] trackDRCvalues   = null;
                string[] trackGainValues  = null;

                if (audioTrackMixes.Success)
                {
                    trackMixes = audioTrackMixes.ToString().Replace("-6 ", string.Empty).Split(',');
                }
                if (audioEncoders.Success)
                {
                    trackEncoders = audioEncoders.ToString().Replace("-E ", string.Empty).Split(',');
                }
                if (audioBitrates.Success)
                {
                    trackBitrates = audioBitrates.ToString().Replace("-B ", string.Empty).Split(',');
                }
                if (audioSampleRates.Success)
                {
                    trackSamplerates = audioSampleRates.ToString().Replace("-R ", string.Empty).Split(',');
                }
                if (drcValues.Success)
                {
                    trackDRCvalues = drcValues.ToString().Replace("-D ", string.Empty).Split(',');
                }
                if (gainValues.Success)
                {
                    trackGainValues = gainValues.ToString().Replace("--gain=", string.Empty).Split(',');
                }

                // Create new Audio Track Classes and store them in the ArrayList
                ObservableCollection <AudioTrack> allAudioTrackInfo = new ObservableCollection <AudioTrack>();
                for (int x = 0; x < encoderCount; x++)
                {
                    AudioTrack track = new AudioTrack();

                    if (trackMixes != null)
                    {
                        if (trackMixes.Length >= (x + 1)) // Audio Mix
                        {
                            track.MixDown = Converters.GetAudioMixDown(Converters.GetMixDown(trackMixes[x].Trim()));
                        }
                    }

                    if (trackEncoders != null)
                    {
                        if (trackEncoders.Length >= (x + 1)) // Audio Mix
                        {
                            track.Encoder = Converters.GetAudioEncoderFromCliString(trackEncoders[x].Trim());
                        }
                    }

                    if (trackBitrates != null)
                    {
                        if (trackBitrates.Length >= (x + 1)) // Audio Encoder
                        {
                            track.Bitrate = int.Parse(trackBitrates[x].Trim() == "auto" ? "0" : trackBitrates[x].Trim());
                        }
                    }

                    if (trackSamplerates != null)
                    {
                        if (trackSamplerates.Length >= (x + 1)) // Audio SampleRate
                        {
                            track.SampleRate = double.Parse(trackSamplerates[x].Replace("Auto", "0").Trim(), Culture);
                        }
                    }

                    if (trackDRCvalues != null)
                    {
                        if (trackDRCvalues.Length >= (x + 1)) // Audio DRC Values
                        {
                            track.DRC = double.Parse(trackDRCvalues[x].Trim(), Culture);
                        }
                    }

                    if (trackGainValues != null)
                    {
                        if (trackGainValues.Length >= (x + 1)) // Audio DRC Values
                        {
                            track.Gain = int.Parse(trackGainValues[x].Trim());
                        }
                    }

                    allAudioTrackInfo.Add(track);
                }

                parsed.AudioTracks = allAudioTrackInfo;

                if (fallbackEncoder.Success)
                {
                    parsed.AllowedPassthruOptions.AudioEncoderFallback =
                        Converters.GetAudioEncoderFromCliString(fallbackEncoder.Groups[1].ToString().Trim());
                }

                if (allowedPassthru.Success)
                {
                    string[] allowedEncoders = allowedPassthru.Groups[1].ToString().Trim().Split(',');

                    parsed.AllowedPassthruOptions.AudioAllowAACPass   = allowedEncoders.Contains("aac");
                    parsed.AllowedPassthruOptions.AudioAllowAC3Pass   = allowedEncoders.Contains("ac3");
                    parsed.AllowedPassthruOptions.AudioAllowDTSHDPass = allowedEncoders.Contains("dtshd");
                    parsed.AllowedPassthruOptions.AudioAllowDTSPass   = allowedEncoders.Contains("dts");
                    parsed.AllowedPassthruOptions.AudioAllowMP3Pass   = allowedEncoders.Contains("mp3");
                }

                #endregion

                #region Chapters Tab

                if (chapterMarkersFileMode.Success || chapterMarkers.Success)
                {
                    parsed.IncludeChapterMarkers = true;
                }

                #endregion

                #region Advanced and other

                if (advanced.Success)
                {
                    parsed.AdvancedEncoderOptions = advanced.ToString().Replace("-x ", string.Empty);
                }

                if (x264Preset.Success)
                {
                    parsed.X264Preset =
                        Converters.Getx264PresetFromCli(x264Preset.ToString().Replace("--x264-preset", string.Empty).Replace("=", string.Empty).Trim());
                }

                if (h264Profile.Success)
                {
                    parsed.H264Profile =
                        Converters.Getx264ProfileFromCli(h264Profile.ToString().Replace("--h264-profile", string.Empty).Replace("=", string.Empty).Trim());
                }

                if (x264Profile.Success)
                {
                    parsed.H264Profile =
                        Converters.Getx264ProfileFromCli(x264Profile.ToString().Replace("--x264-profile", string.Empty).Replace("=", string.Empty).Trim());
                }

                if (h264Level.Success)
                {
                    parsed.H264Level =
                        h264Level.ToString().Replace("--h264-level", string.Empty).Replace("=", string.Empty).Trim();
                }

                if (x264Tune.Success)
                {
                    string tuneOptions =
                        x264Tune.ToString().Replace("--x264-tune", string.Empty).Replace("=", string.Empty).Trim();

                    parsed.FastDecode = tuneOptions.Contains("fastdecode");

                    // Remove these options. They are not in the dropdown.
                    tuneOptions = tuneOptions.Replace("fastdecode", string.Empty).Replace(
                        ",", string.Empty);

                    parsed.X264Tune = Converters.Getx264TuneFromCli(tuneOptions);
                }

                if (x265Preset.Success)
                {
                    parsed.X265Preset =
                        Converters.Getx265PresetFromCli(x265Preset.ToString().Replace("--x265-preset", string.Empty).Replace("=", string.Empty).Trim());
                }

                if (h264Profile.Success)
                {
                    parsed.H265Profile =
                        Converters.Getx265ProfileFromCli(h264Profile.ToString().Replace("--h265-profile", string.Empty).Replace("=", string.Empty).Trim());
                }

                if (x265Profile.Success)
                {
                    parsed.H265Profile =
                        Converters.Getx265ProfileFromCli(x265Profile.ToString().Replace("--x265-profile", string.Empty).Replace("=", string.Empty).Trim());
                }

                if (x265Tune.Success)
                {
                    string tuneOptions =
                        x265Tune.ToString().Replace("--x265-tune", string.Empty).Replace("=", string.Empty).Trim();

                    parsed.FastDecode = tuneOptions.Contains("fastdecode");

                    // Remove these options. They are not in the dropdown.
                    tuneOptions = tuneOptions.Replace("fastdecode", string.Empty).Replace(
                        ",", string.Empty);

                    parsed.X265Tune = Converters.Getx265TuneFromCli(tuneOptions);
                }

                #endregion
            }
            catch (Exception exc)
            {
                throw new Exception("An error has occured in the QueryParser Utility.", exc);
            }

            #endregion

            return(parsed);
        }
예제 #4
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", userSettingService.GetUserSetting <int>(ASUserSettingConstants.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 <VideoEncoder> .GetDisplay(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);
        }
예제 #5
0
        public static EncodeTask Import(string filename)
        {
            XmlNode root = loadFile(filename);

            if (root == null)
            {
                return(null);
            }

            // We'll query a query parser object and use it's public var structures to store all the data.
            // This will allow the preset loader logic to be used instead of writing custom logic just for this file.
            EncodeTask parsed      = new EncodeTask();
            string     qualityMode = string.Empty;

            #region Get a List of Audio Track Objects
            XmlNode           audioListDict = root.ChildNodes[2].ChildNodes[0].FirstChild.ChildNodes[1];
            List <AudioTrack> audioTracks   = new List <AudioTrack>();

            for (int i = 0; i < audioListDict.ChildNodes.Count; i++)
            {
                XmlNode    audioChannel = audioListDict.ChildNodes[i];
                AudioTrack track        = new AudioTrack();

                for (int subi = 0; subi < audioChannel.ChildNodes.Count; subi += 2)
                {
                    // Audio Channel Information is here.
                    string key   = audioChannel.ChildNodes[subi].InnerText;
                    string value = audioChannel.ChildNodes[subi + 1].InnerText;
                    switch (key)
                    {
                    case "AudioBitrate":
                        track.Bitrate = int.Parse(value);
                        break;

                    case "AudioEncoder":
                        track.Encoder = Converters.GetAudioEncoder(value.Trim());
                        break;

                    case "AudioMixdown":
                        track.MixDown = Converters.GetAudioMixDown(value.Trim());
                        break;

                    case "AudioSamplerate":
                        track.SampleRate = value == "Auto" ? 0 : double.Parse(value);
                        break;

                    case "AudioTrack":
                        //track.SourceTrack = value;
                        break;

                    case "AudioTrackDRCSlider":
                        track.DRC = double.Parse(value);
                        break;

                    case "AudioTrackGainSlider":
                        track.Gain = int.Parse(value);
                        break;
                    }
                }
                audioTracks.Add(track);
                parsed.AudioTracks = audioTracks;
            }
            #endregion

            #region Parse the reset of the plist keys into local variables

            XmlNode presetSettings = root.ChildNodes[2].ChildNodes[0].FirstChild;

            // Start from 2 to avoid the audio settings which we don't need.
            for (int i = 2; i < presetSettings.ChildNodes.Count; i += 2)
            {
                string key   = presetSettings.ChildNodes[i].InnerText;
                string value = presetSettings.ChildNodes[i + 1].InnerText;

                switch (key)
                {
                // Output Settings
                case "FileFormat":
                    parsed.OutputFormat = Converters.GetFileFormat(value.Replace("file", string.Empty).Trim());
                    break;

                case "Mp4HttpOptimize":
                    parsed.OptimizeMP4 = value == "1";
                    break;

                case "Mp4LargeFile":
                    parsed.IPod5GSupport = value == "1";
                    break;

                case "Mp4iPodCompatible":
                    parsed.IPod5GSupport = value == "1";
                    break;

                // Picture Settings
                case "PictureAutoCrop":
                    parsed.HasCropping = value != "1";
                    break;

                case "PictureTopCrop":
                    parsed.Cropping.Top = int.Parse(value);
                    break;

                case "PictureBottomCrop":
                    parsed.Cropping.Bottom = int.Parse(value);
                    break;

                case "PictureLeftCrop":
                    parsed.Cropping.Left = int.Parse(value);
                    break;

                case "PictureRightCrop":
                    parsed.Cropping.Right = int.Parse(value);
                    break;

                case "PictureHeight":
                    parsed.Height = int.Parse(value);
                    break;

                case "PictureWidth":
                    parsed.Width = int.Parse(value);
                    break;

                case "PictureKeepRatio":
                    parsed.KeepDisplayAspect = value == "1";
                    break;

                case "PicturePAR":
                    switch (value)
                    {
                    case "0":
                        parsed.Anamorphic = Anamorphic.None;
                        break;

                    default:
                        parsed.Anamorphic = Anamorphic.Strict;
                        break;

                    case "2":
                        parsed.Anamorphic = Anamorphic.Loose;
                        break;

                    case "3":
                        parsed.Anamorphic = Anamorphic.Custom;
                        break;
                    }
                    break;

                // Filters
                case "PictureDeblock":
                    parsed.Deblock = int.Parse(value);
                    break;

                case "PictureDecomb":
                    parsed.Decomb = Decomb.Off;
                    // Don't place custom here as it's handled in the filter panel
                    if (value == "2")
                    {
                        parsed.Decomb = Decomb.Default;
                    }
                    break;

                case "PictureDecombCustom":
                    if (value != string.Empty)
                    {
                        parsed.CustomDecomb = value;
                    }
                    break;

                case "PictureDecombDeinterlace":
                    // Not Used
                    break;

                case "PictureDeinterlace":
                    switch (value)
                    {
                    case "0":
                        parsed.Deinterlace = Deinterlace.Off;
                        break;

                    // Don't place custom here as it's handled in the filter panel
                    case "2":
                        parsed.Deinterlace = Deinterlace.Fast;
                        break;

                    case "3":
                        parsed.Deinterlace = Deinterlace.Slow;
                        break;

                    case "4":
                        parsed.Deinterlace = Deinterlace.Slower;
                        break;
                    }
                    break;

                case "PictureDeinterlaceCustom":
                    if (value != string.Empty)
                    {
                        parsed.CustomDeinterlace = value;
                    }
                    break;

                case "PictureDenoise":
                    switch (value)
                    {
                    case "0":
                        parsed.Denoise = Denoise.Off;
                        break;

                    // Don't place custom here as it's handled in the filter panel
                    case "2":
                        parsed.Denoise = Denoise.Weak;
                        break;

                    case "3":
                        parsed.Denoise = Denoise.Medium;
                        break;

                    case "4":
                        parsed.Denoise = Denoise.Strong;
                        break;
                    }

                    break;

                case "PictureDenoiseCustom":
                    if (value != string.Empty)
                    {
                        parsed.CustomDenoise = value;
                    }
                    break;

                case "PictureDetelecine":
                    parsed.Detelecine = Detelecine.Off;
                    if (value == "1")
                    {
                        parsed.Detelecine = Detelecine.Default;
                    }
                    break;

                case "PictureDetelecineCustom":
                    if (value != string.Empty)
                    {
                        parsed.CustomDetelecine = value;
                    }
                    break;

                // Video Tab
                case "VideoAvgBitrate":
                    if (!string.IsNullOrEmpty(value))
                    {
                        parsed.VideoBitrate = int.Parse(value);
                    }
                    break;

                case "VideoEncoder":
                    parsed.VideoEncoder = EnumHelper <VideoEncoder> .GetValue(value);

                    break;

                case "VideoFramerate":

                    if (value == "Same as source")
                    {
                        parsed.Framerate = null;
                    }
                    else if (!string.IsNullOrEmpty(value))
                    {
                        parsed.Framerate = double.Parse(value);
                    }
                    break;

                case "VideoFramerateMode":
                    switch (value)
                    {
                    case "vfr":
                        parsed.FramerateMode = FramerateMode.VFR;
                        break;

                    case "cfr":
                        parsed.FramerateMode = FramerateMode.CFR;
                        break;

                    default:
                        parsed.FramerateMode = FramerateMode.PFR;
                        break;
                    }
                    break;

                case "VideoGrayScale":
                    parsed.Grayscale = value == "1";
                    break;

                case "VideoQualitySlider":
                    parsed.Quality = double.Parse(value);
                    break;

                case "VideoQualityType":     // The Type of Quality Mode used
                    qualityMode = value;
                    break;

                case "VideoTurboTwoPass":
                    parsed.TurboFirstPass = value == "1";
                    break;

                case "VideoTwoPass":
                    parsed.TwoPass = value == "1";
                    break;

                // Chapter Markers Tab
                case "ChapterMarkers":
                    parsed.IncludeChapterMarkers = value == "1";
                    break;

                // Advanced x264 tab
                case "x264Option":
                    parsed.AdvancedEncoderOptions = value;
                    break;

                // Preset Information
                case "PresetBuildNumber":
                    parsed.PresetBuildNumber = int.Parse(value);
                    break;

                case "PresetDescription":
                    parsed.PresetDescription = value;
                    break;

                case "PresetName":
                    parsed.PresetName = value;
                    break;

                case "Type":
                    parsed.Type = value;
                    break;

                case "UsesMaxPictureSettings":
                    parsed.UsesMaxPictureSettings = value == "1";
                    break;

                case "UsesPictureFilters":
                    parsed.UsesPictureFilters = value == "1";
                    break;

                case "UsesPictureSettings":
                    parsed.UsesPictureSettings = value == "1";
                    break;
                }
            }

            // Kill any Quality values we don't need.
            switch (qualityMode)
            {
            case "1":     // Avg Bitrate
                parsed.VideoEncodeRateType = VideoEncodeRateType.AverageBitrate;
                break;

            case "2":     // CQ
                parsed.VideoEncodeRateType = VideoEncodeRateType.ConstantQuality;
                break;
            }
            #endregion

            return(parsed);
        }
예제 #6
0
        /// <summary>
        /// Generate the Command Line Arguments for the Audio Settings Tab
        /// </summary>
        /// <param name="task">
        /// The encode task.
        /// </param>
        /// <returns>
        /// A Cli Query as a string
        /// </returns>
        private static string AudioSettingsQuery(EncodeTask task)
        {
            string query = string.Empty;

            ObservableCollection <AudioTrack> audioTracks = task.AudioTracks;

            List <int>          tracks      = new List <int>();
            List <AudioEncoder> codecs      = new List <AudioEncoder>();
            List <Mixdown>      mixdowns    = new List <Mixdown>();
            List <double>       samplerates = new List <double>();
            List <int>          bitrates    = new List <int>();
            List <double>       drcs        = new List <double>();
            List <double>       gains       = new List <double>();
            List <string>       trackNames  = new List <string>();

            // No Audio
            if (audioTracks.Count == 0)
            {
                query += " -a none ";
            }

            // Gather information about each audio track and store them in the declared lists.
            foreach (AudioTrack track in audioTracks)
            {
                if (track.Track == null)
                {
                    continue;
                }

                tracks.Add(track.Track.Value);

                // Audio Codec (-E)
                codecs.Add(track.Encoder);

                // Audio Mixdown (-6)
                mixdowns.Add(track.IsPassthru ? Mixdown.None : track.MixDown);

                // Sample Rate (-R)
                samplerates.Add(track.IsPassthru ? 0 : track.SampleRate);

                // Audio Bitrate (-B)
                bitrates.Add(track.IsPassthru ? 0 : track.Bitrate);

                // DRC (-D)
                drcs.Add(track.IsPassthru ? 0 : track.DRC);

                // Gain (--gain)
                gains.Add(track.IsPassthru ? 0 : track.Gain);

                // Audio Track Name (--aname)
                trackNames.Add(track.TrackName);
            }

            // Audio Track (-a)
            string audioItems = string.Empty;
            bool   firstLoop  = true;

            foreach (int item in tracks)
            {
                if (firstLoop)
                {
                    audioItems = item.ToString();
                    firstLoop  = false;
                }
                else
                {
                    audioItems += "," + item;
                }
            }
            if (audioItems.Trim() != String.Empty)
            {
                query += " -a " + audioItems;
            }
            firstLoop  = true;
            audioItems = string.Empty; // Reset for another pass.

            // Audio Codec (-E)
            foreach (AudioEncoder item in codecs)
            {
                if (firstLoop)
                {
                    audioItems = Converters.GetCliAudioEncoder(item);
                    firstLoop  = false;
                }
                else
                {
                    audioItems += "," + Converters.GetCliAudioEncoder(item);
                }
            }
            if (audioItems.Trim() != String.Empty)
            {
                query += " -E " + audioItems;
            }
            firstLoop  = true;
            audioItems = string.Empty; // Reset for another pass.

            // Audio Mixdown (-6)
            foreach (Mixdown item in mixdowns)
            {
                if (firstLoop)
                {
                    audioItems = Converters.GetCliMixDown(item);
                    firstLoop  = false;
                }
                else
                {
                    audioItems += "," + Converters.GetCliMixDown(item);
                }
            }
            if (audioItems.Trim() != String.Empty)
            {
                query += " -6 " + audioItems;
            }
            firstLoop  = true;
            audioItems = string.Empty; // Reset for another pass.

            // Sample Rate (-R)
            foreach (double item in samplerates)
            {
                string add = (item == 0.0) ? "Auto" : item.ToString(new CultureInfo("en-US"));
                if (firstLoop)
                {
                    audioItems = add;
                    firstLoop  = false;
                }
                else
                {
                    audioItems += "," + add;
                }
            }
            if (audioItems.Trim() != String.Empty)
            {
                query += " -R " + audioItems;
            }
            firstLoop  = true;
            audioItems = string.Empty; // Reset for another pass.

            // Audio Bitrate (-B)
            foreach (int item in bitrates)
            {
                if (firstLoop)
                {
                    audioItems = item.ToString();
                    firstLoop  = false;
                }
                else
                {
                    audioItems += "," + item;
                }
            }
            if (audioItems.Trim() != String.Empty)
            {
                query += " -B " + audioItems;
            }
            firstLoop  = true;
            audioItems = string.Empty; // Reset for another pass.

            // DRC (-D)
            foreach (var itm in drcs)
            {
                string item = itm.ToString(new CultureInfo("en-US"));
                if (firstLoop)
                {
                    audioItems = item;
                    firstLoop  = false;
                }
                else
                {
                    audioItems += "," + item;
                }
            }
            if (audioItems.Trim() != String.Empty)
            {
                query += " -D " + audioItems;
            }

            audioItems = string.Empty; // Reset for another pass.
            firstLoop  = true;

            // Gain (--gain)
            foreach (var itm in gains)
            {
                string item = itm.ToString(new CultureInfo("en-US"));
                if (firstLoop)
                {
                    audioItems = item;
                    firstLoop  = false;
                }
                else
                {
                    audioItems += "," + item;
                }
            }
            if (audioItems.Trim() != String.Empty)
            {
                query += " --gain " + audioItems;
            }

            audioItems = string.Empty; // Reset for another pass.
            firstLoop  = true;

            // Audio Track Names (--aname)
            bool foundTrackName = false;

            foreach (string trackName in trackNames)
            {
                if (!string.IsNullOrEmpty(trackName))
                {
                    foundTrackName = true;
                }

                if (firstLoop)
                {
                    audioItems = string.IsNullOrEmpty(trackName) ? "\"\"" : string.Format("\"{0}\"", trackName.Trim());
                    firstLoop  = false;
                }
                else
                {
                    audioItems += "," + (string.IsNullOrEmpty(trackName) ? "\"\"" : string.Format("\"{0}\"", trackName.Trim()));
                }
            }
            if (foundTrackName)
            {
                query += string.Format(" --aname={0}", audioItems);
            }

            // Passthru Settings
            if (task.AllowedPassthruOptions != null)
            {
                string fallbackEncoders = string.Empty;

                if (task.AllowedPassthruOptions.AudioAllowAACPass != null && task.AllowedPassthruOptions.AudioAllowAACPass.Value)
                {
                    fallbackEncoders += "aac";
                }

                if (task.AllowedPassthruOptions.AudioAllowAC3Pass != null && task.AllowedPassthruOptions.AudioAllowAC3Pass.Value)
                {
                    fallbackEncoders += string.IsNullOrEmpty(fallbackEncoders) ? "ac3" : ",ac3";
                }

                if (task.AllowedPassthruOptions.AudioAllowDTSHDPass != null && task.AllowedPassthruOptions.AudioAllowDTSHDPass.Value)
                {
                    fallbackEncoders += string.IsNullOrEmpty(fallbackEncoders) ? "dtshd" : ",dtshd";
                }

                if (task.AllowedPassthruOptions.AudioAllowDTSPass != null && task.AllowedPassthruOptions.AudioAllowDTSPass.Value)
                {
                    fallbackEncoders += string.IsNullOrEmpty(fallbackEncoders) ? "dts" : ",dts";
                }

                if (task.AllowedPassthruOptions.AudioAllowMP3Pass != null && task.AllowedPassthruOptions.AudioAllowMP3Pass.Value)
                {
                    fallbackEncoders += string.IsNullOrEmpty(fallbackEncoders) ? "mp3" : ",mp3";
                }

                if (!string.IsNullOrEmpty(fallbackEncoders))
                {
                    // Special Case, The CLI alredy defaults to ALL, so if all area selected, then don't need to set copy mask
                    if (fallbackEncoders != "aac,ac3,dtshd,dts,mp3")
                    {
                        query += string.Format(" --audio-copy-mask {0}", fallbackEncoders);
                    }
                }
                else
                {
                    query += string.Format(" --audio-copy-mask none");
                }

                query += string.Format(" --audio-fallback {0}", Converters.GetCliAudioEncoder(task.AllowedPassthruOptions.AudioEncoderFallback));
            }

            return(query);
        }
예제 #7
0
        /// <summary>
        /// Get an EncodeJob model for a LibHB Encode.
        /// </summary>
        /// <param name="task">
        /// The task.
        /// </param>
        /// <param name="configuration">
        /// The configuration.
        /// </param>
        /// <returns>
        /// An Interop.EncodeJob model.
        /// </returns>
        public static EncodeJob GetEncodeJob(EncodeTask task, HBConfiguration configuration)
        {
            // The current Job Configuration
            EncodeTask work = task;

            // Which will be converted to this EncodeJob Model.
            EncodeJob job = new EncodeJob();

            // Audio Settings
            job.AudioEncodings = new List <AudioEncoding>();
            foreach (AudioTrack track in work.AudioTracks)
            {
                AudioEncoding newTrack = new AudioEncoding
                {
                    Bitrate        = track.Bitrate,
                    Drc            = track.DRC,
                    Gain           = track.Gain,
                    Encoder        = Converters.GetCliAudioEncoder(track.Encoder),
                    InputNumber    = track.Track.HasValue ? track.Track.Value : 0,
                    Mixdown        = Converters.GetCliMixDown(track.MixDown),
                    SampleRateRaw  = GetSampleRateRaw(track.SampleRate),
                    EncodeRateType = AudioEncodeRateType.Bitrate,
                    Name           = track.TrackName,
                    IsPassthru     = track.IsPassthru,
                };

                job.AudioEncodings.Add(newTrack);
            }

            // Title Settings
            job.OutputPath = work.Destination;
            job.SourcePath = work.Source;
            job.Title      = work.Title;

            // job.SourceType = work.Type;
            switch (work.PointToPointMode)
            {
            case PointToPointMode.Chapters:
                job.RangeType = VideoRangeType.Chapters;
                break;

            case PointToPointMode.Seconds:
                job.RangeType = VideoRangeType.Seconds;
                break;

            case PointToPointMode.Frames:
                job.RangeType = VideoRangeType.Frames;
                break;

            case PointToPointMode.Preview:
                job.RangeType = VideoRangeType.Preview;
                break;
            }

            if (work.PointToPointMode == PointToPointMode.Seconds)
            {
                job.SecondsEnd   = work.EndPoint;
                job.SecondsStart = work.StartPoint;
            }
            if (work.PointToPointMode == PointToPointMode.Chapters)
            {
                job.ChapterStart = work.StartPoint;
                job.ChapterEnd   = work.EndPoint;
            }
            if (work.PointToPointMode == PointToPointMode.Frames)
            {
                job.FramesEnd   = work.EndPoint;
                job.FramesStart = work.StartPoint;
            }

            if (work.PointToPointMode == PointToPointMode.Preview)
            {
                job.StartAtPreview = work.PreviewEncodeStartAt.HasValue ? work.PreviewEncodeStartAt.Value + 1 : 1;
                job.SecondsEnd     = work.PreviewEncodeDuration.HasValue ? work.PreviewEncodeDuration.Value : 30;
                job.SeekPoints     = configuration.PreviewScanCount;
            }

            job.Angle = work.Angle;

            // Output Settings
            job.IPod5GSupport = work.IPod5GSupport;
            job.Optimize      = work.OptimizeMP4;
            switch (work.OutputFormat)
            {
            case OutputFormat.Mp4:
                job.ContainerName = "av_mp4";     // TODO make part of enum.
                break;

            case OutputFormat.Mkv:
                job.ContainerName = "av_mkv";     // TODO make part of enum.
                break;
            }

            // Picture Settings
            job.Anamorphic = work.Anamorphic;
            job.Cropping   = new Cropping {
                Top = work.Cropping.Top, Bottom = work.Cropping.Bottom, Left = work.Cropping.Left, Right = work.Cropping.Right
            };
            job.DisplayWidth      = work.DisplayWidth.HasValue ? int.Parse(Math.Round(work.DisplayWidth.Value, 0).ToString()) : 0;
            job.PixelAspectX      = work.PixelAspectX;
            job.PixelAspectY      = work.PixelAspectY;
            job.Height            = work.Height.HasValue ? work.Height.Value : 0;
            job.KeepDisplayAspect = work.KeepDisplayAspect;
            job.MaxHeight         = work.MaxHeight.HasValue ? work.MaxHeight.Value : 0;
            job.MaxWidth          = work.MaxWidth.HasValue ? work.MaxWidth.Value : 0;
            job.Modulus           = work.Modulus.HasValue ? work.Modulus.Value : 16;
            job.UseDisplayWidth   = true;
            job.Width             = work.Width.HasValue ? work.Width.Value : 0;

            // Filter Settings
            job.CustomDecomb      = work.CustomDecomb;
            job.CustomDeinterlace = work.CustomDeinterlace;
            job.CustomDenoise     = work.CustomDenoise;
            job.DenoisePreset     = work.DenoisePreset.ToString().ToLower().Replace(" ", string.Empty);
            job.DenoiseTune       = work.DenoiseTune.ToString().ToLower().Replace(" ", string.Empty);
            job.CustomDetelecine  = work.CustomDetelecine;
            if (work.Deblock > 4)
            {
                job.Deblock = work.Deblock;
            }
            job.Decomb      = work.Decomb;
            job.Deinterlace = work.Deinterlace;
            job.Denoise     = work.Denoise;
            job.Detelecine  = work.Detelecine;
            job.Grayscale   = work.Grayscale;

            // Video Settings
            job.Framerate           = work.Framerate.HasValue ? work.Framerate.Value : 0;
            job.ConstantFramerate   = work.FramerateMode == FramerateMode.CFR;
            job.PeakFramerate       = work.FramerateMode == FramerateMode.PFR;
            job.Quality             = work.Quality.HasValue ? work.Quality.Value : 0;
            job.VideoBitrate        = work.VideoBitrate.HasValue ? work.VideoBitrate.Value : 0;
            job.VideoEncodeRateType = work.VideoEncodeRateType;
            job.VideoEncoder        = Converters.GetVideoEncoder(work.VideoEncoder);
            job.TwoPass             = work.TwoPass;
            job.TurboFirstPass      = work.TurboFirstPass;

            if (work.VideoEncoder == VideoEncoder.X264 || work.VideoEncoder == VideoEncoder.X265 || work.VideoEncoder == VideoEncoder.QuickSync)
            {
                job.VideoPreset  = work.VideoPreset.ShortName;
                job.VideoProfile = work.VideoProfile.ShortName;
                job.VideoLevel   = work.VideoLevel.ShortName;

                if (work.VideoEncoder != VideoEncoder.QuickSync)
                {
                    job.VideoTunes = new List <string>();
                    foreach (var item in work.VideoTunes)
                    {
                        job.VideoTunes.Add(item.ShortName);
                    }
                }
            }

            // Chapter Markers
            job.IncludeChapterMarkers  = work.IncludeChapterMarkers;
            job.CustomChapterNames     = work.ChapterNames.Select(item => item.ChapterName).ToList();
            job.UseDefaultChapterNames = work.IncludeChapterMarkers;

            // Advanced Settings
            job.VideoOptions = work.ShowAdvancedTab ? work.AdvancedEncoderOptions : work.ExtraAdvancedArguments;

            // Subtitles
            job.Subtitles = new Subtitles {
                SourceSubtitles = new List <SourceSubtitle>(), SrtSubtitles = new List <SrtSubtitle>()
            };
            foreach (SubtitleTrack track in work.SubtitleTracks)
            {
                if (track.IsSrtSubtitle)
                {
                    job.Subtitles.SrtSubtitles.Add(
                        new SrtSubtitle
                    {
                        CharacterCode = track.SrtCharCode,
                        Default       = track.Default,
                        FileName      = track.SrtPath,
                        LanguageCode  = track.SrtLang,
                        Offset        = track.SrtOffset,
                        BurnedIn      = track.Burned
                    });
                }
                else
                {
                    if (track.SourceTrack != null)
                    {
                        job.Subtitles.SourceSubtitles.Add(
                            new SourceSubtitle {
                            BurnedIn = track.Burned, Default = track.Default, Forced = track.Forced, TrackNumber = track.SourceTrack.TrackNumber
                        });
                    }
                }
            }

            return(job);
        }