Esempio n. 1
0
        /// <summary>
        /// Create the PAR object
        /// </summary>
        /// <param name="job">
        /// The Job
        /// </param>
        /// <param name="title">
        /// The title.
        /// </param>
        /// <returns>
        /// The produced PAR object.
        /// </returns>
        private static PAR CreatePAR(EncodeJob job, Title title)
        {
            Geometry resultGeometry = AnamorphicFactory.CreateGeometry(job, title, AnamorphicFactory.KeepSetting.HB_KEEP_WIDTH);

            return(new PAR {
                Num = resultGeometry.PAR.Num, Den = resultGeometry.PAR.Den
            });
        }
Esempio n. 2
0
        /// <summary>
        /// The create filter.
        /// </summary>
        /// <param name="job">
        /// The job.
        /// </param>
        /// <param name="title">
        /// The title.
        /// </param>
        /// <returns>
        /// The <see cref="Filter"/>.
        /// </returns>
        private static Filter CreateFilter(EncodeJob job, Title title)
        {
            Filter filter = new Filter
            {
                FilterList = new List <FilterList>(),
                Grayscale  = job.Grayscale
            };

            // Detelecine
            if (job.Detelecine != Detelecine.Off)
            {
                FilterList filterItem = new FilterList {
                    ID = (int)hb_filter_ids.HB_FILTER_DETELECINE, Settings = job.CustomDetelecine
                };
                filter.FilterList.Add(filterItem);
            }

            // Decomb
            if (job.Decomb != Decomb.Off)
            {
                string options;
                if (job.Decomb == Decomb.Fast)
                {
                    options = "7:2:6:9:1:80";
                }
                else if (job.Decomb == Decomb.Bob)
                {
                    options = "455";
                }
                else
                {
                    options = job.CustomDecomb;
                }

                FilterList filterItem = new FilterList {
                    ID = (int)hb_filter_ids.HB_FILTER_DECOMB, Settings = options
                };
                filter.FilterList.Add(filterItem);
            }

            // Deinterlace
            if (job.Deinterlace != Deinterlace.Off)
            {
                string options;
                if (job.Deinterlace == Deinterlace.Fast)
                {
                    options = "0";
                }
                else if (job.Deinterlace == Deinterlace.Slow)
                {
                    options = "1";
                }
                else if (job.Deinterlace == Deinterlace.Slower)
                {
                    options = "3";
                }
                else if (job.Deinterlace == Deinterlace.Bob)
                {
                    options = "15";
                }
                else
                {
                    options = job.CustomDeinterlace;
                }

                FilterList filterItem = new FilterList {
                    ID = (int)hb_filter_ids.HB_FILTER_DEINTERLACE, Settings = options
                };
                filter.FilterList.Add(filterItem);
            }

            // VFR / CFR
            int    fm           = job.ConstantFramerate ? 1 : job.PeakFramerate ? 2 : 0;
            IntPtr frameratePrt = Marshal.StringToHGlobalAnsi(job.Framerate.ToString(CultureInfo.InvariantCulture));
            int    vrate        = HBFunctions.hb_video_framerate_get_from_name(frameratePrt);

            int num;
            int den;

            if (vrate > 0)
            {
                num = 27000000;
                den = vrate;
            }
            else
            {
                // cfr or pfr flag with no rate specified implies use the title rate.
                num = title.FramerateNumerator;
                den = title.FramerateDenominator;
            }

            string framerateString = string.Format("{0}:{1}:{2}", fm, num, den); // filter_cfr, filter_vrate.num, filter_vrate.den

            FilterList framerateShaper = new FilterList {
                ID = (int)hb_filter_ids.HB_FILTER_VFR, Settings = framerateString
            };

            filter.FilterList.Add(framerateShaper);

            // Deblock
            if (job.Deblock >= 5)
            {
                FilterList filterItem = new FilterList {
                    ID = (int)hb_filter_ids.HB_FILTER_DEBLOCK, Settings = job.Deblock.ToString()
                };
                filter.FilterList.Add(filterItem);
            }

            // Denoise
            if (job.Denoise != Denoise.Off)
            {
                hb_filter_ids id = job.Denoise == Denoise.hqdn3d
                    ? hb_filter_ids.HB_FILTER_HQDN3D
                    : hb_filter_ids.HB_FILTER_NLMEANS;

                string settings;
                if (job.Denoise == Denoise.hqdn3d &&
                    !string.IsNullOrEmpty(job.CustomDenoise))
                {
                    settings = job.CustomDenoise;
                }
                else
                {
                    IntPtr settingsPtr = HBFunctions.hb_generate_filter_settings((int)id, job.DenoisePreset, job.DenoiseTune);
                    settings = Marshal.PtrToStringAnsi(settingsPtr);
                }

                FilterList filterItem = new FilterList {
                    ID = (int)id, Settings = settings
                };
                filter.FilterList.Add(filterItem);
            }

            // CropScale Filter
            Geometry   resultGeometry = AnamorphicFactory.CreateGeometry(job, title, AnamorphicFactory.KeepSetting.HB_KEEP_WIDTH);
            FilterList cropScale      = new FilterList
            {
                ID       = (int)hb_filter_ids.HB_FILTER_CROP_SCALE,
                Settings =
                    string.Format(
                        "{0}:{1}:{2}:{3}:{4}:{5}",
                        resultGeometry.Width,
                        resultGeometry.Height,
                        job.Cropping.Top,
                        job.Cropping.Bottom,
                        job.Cropping.Left,
                        job.Cropping.Right)
            };

            filter.FilterList.Add(cropScale);

            // Rotate
            /* TODO  NOT SUPPORTED YET. */

            return(filter);
        }