Example #1
0
 /// <summary>
 /// Gets the cropping to use for the given encoding profile and title.
 /// </summary>
 /// <param name="profile">The encoding profile to use.</param>
 /// <param name="title">The title being encoded.</param>
 /// <returns>The cropping to use for the encode.</returns>
 private static Cropping GetCropping(EncodingProfile profile, Title title)
 {
     Cropping crop;
     switch (profile.CroppingType)
     {
         case CroppingType.Automatic:
             crop = title.AutoCropDimensions;
             break;
         case CroppingType.Custom:
             crop = profile.Cropping;
             break;
         default:
             crop = new Cropping();
             break;
     }
     return crop;
 }
Example #2
0
        /// <summary>
        /// Calculates the output size for a non-anamorphic job.
        /// </summary>
        /// <param name="profile">The encoding profile for the job.</param>
        /// <param name="title">The title being encoded.</param>
        /// <returns>The dimensions of the final encode.</returns>
        private static Size CalculateNonAnamorphicOutput(EncodingProfile profile, Title title)
        {
            int sourceWidth = title.Resolution.Width;
            int sourceHeight = title.Resolution.Height;

            int width = profile.Width;
            int height = profile.Height;

            Cropping crop;
            switch (profile.CroppingType)
            {
                case CroppingType.Automatic:
                    crop = title.AutoCropDimensions;
                    break;
                case CroppingType.Custom:
                    crop = profile.Cropping;
                    break;
                default:
                    crop = new Cropping();
                    break;
            }

            sourceWidth -= crop.Left;
            sourceWidth -= crop.Right;

            sourceHeight -= crop.Top;
            sourceHeight -= crop.Bottom;

            double croppedAspectRatio = ((double)sourceWidth * title.ParVal.Width) / (sourceHeight * title.ParVal.Height);

            if (width == 0)
            {
                width = sourceWidth;
            }

            if (profile.MaxWidth > 0 && width > profile.MaxWidth)
            {
                width = profile.MaxWidth;
            }

            if (height == 0)
            {
                height = sourceHeight;
            }

            if (profile.MaxHeight > 0 && height > profile.MaxHeight)
            {
                height = profile.MaxHeight;
            }

            if (profile.KeepDisplayAspect)
            {
                if ((profile.Width == 0 && profile.Height == 0) || profile.Width == 0)
                {
                    width = (int)((double)height * croppedAspectRatio);
                    if (profile.MaxWidth > 0 && width > profile.MaxWidth)
                    {
                        width = profile.MaxWidth;
                        height = (int)((double)width / croppedAspectRatio);
                        height = GetNearestValue(height, PictureAutoSizeModulus);
                    }

                    width = GetNearestValue(width, PictureAutoSizeModulus);
                }
                else if (profile.Height == 0)
                {
                    height = (int)((double)width / croppedAspectRatio);
                    if (profile.MaxHeight > 0 && height > profile.MaxHeight)
                    {
                        height = profile.MaxHeight;
                        width = (int)((double)height * croppedAspectRatio);
                        width = GetNearestValue(width, PictureAutoSizeModulus);
                    }

                    height = GetNearestValue(height, PictureAutoSizeModulus);
                }
            }

            return new Size(width, height);
        }