Example #1
0
        /// <summary>
        /// Calculates the --vbv-maxrate value
        /// </summary>
        /// <returns>the --vbv-maxrate value</returns>
        public int getVBVMaxrate(AVCLevels.Levels avcLevel, bool bIsHighProfile)
        {
            string strCustomValue;
            int    iTemp = _xs.VBVMaxBitrate;

            extractCustomCommand("vbv-maxrate", out strCustomValue);
            if (Int32.TryParse(strCustomValue, out iTemp))
            {
                _xs.VBVMaxBitrate = iTemp;
            }

            if (_device.VBVMaxrate > -1 && (_xs.VBVMaxBitrate > _device.VBVMaxrate || _xs.VBVMaxBitrate == 0))
            {
                if (_log != null)
                {
                    _log.LogEvent("changing --vbv-maxrate to " + _device.VBVMaxrate + " as required for the selected device");
                }
                _xs.VBVMaxBitrate = _device.VBVMaxrate;
            }

            if (_log != null && avcLevel != AVCLevels.Levels.L_UNRESTRICTED)
            {
                AVCLevels al = new AVCLevels();
                iTemp = al.getMaxBR(avcLevel, bIsHighProfile);
                if (_xs.VBVMaxBitrate == 0)
                {
                    _log.LogEvent("--vbv-maxrate is not restricted. Maximum value for level " + AVCLevels.GetLevelText(avcLevel) + " is " + iTemp + ". Playback may be affected. Reselect AVC level/profile or target playback device in the x264 preset to set the proper value.", ImageType.Warning);
                }
            }

            return(_xs.VBVMaxBitrate);
        }
Example #2
0
        /// <summary>
        /// gets the maximum ref count based upon the given level
        /// </summary>
        /// <param name="level">the AVC level</param>
        /// <param name="hRes">the horizontal resolution</param>
        /// <param name="vRes">the vertical resolution</param>
        /// <returns>the maximum reference count; -1 if no restriction</returns>
        public static int getMaxRefForLevel(AVCLevels.Levels avcLevel, int hRes, int vRes)
        {
            if (hRes <= 0 || vRes <= 0 || avcLevel == AVCLevels.Levels.L_UNRESTRICTED)  // Unrestricted/Autoguess
            {
                return(-1);
            }

            int maxDPB = 0;  // the maximum picture decoded buffer for the given level

            switch (avcLevel)
            {
            case AVCLevels.Levels.L_10: maxDPB = 396;    break;

            case AVCLevels.Levels.L_1B: maxDPB = 396;    break;

            case AVCLevels.Levels.L_11: maxDPB = 900;    break;

            case AVCLevels.Levels.L_12: maxDPB = 2376;   break;

            case AVCLevels.Levels.L_13: maxDPB = 2376;   break;

            case AVCLevels.Levels.L_20: maxDPB = 2376;   break;

            case AVCLevels.Levels.L_21: maxDPB = 4752;   break;

            case AVCLevels.Levels.L_22: maxDPB = 8100;   break;

            case AVCLevels.Levels.L_30: maxDPB = 8100;   break;

            case AVCLevels.Levels.L_31: maxDPB = 18000;  break;

            case AVCLevels.Levels.L_32: maxDPB = 20480;  break;

            case AVCLevels.Levels.L_40: maxDPB = 32768;  break;

            case AVCLevels.Levels.L_41: maxDPB = 32768;  break;

            case AVCLevels.Levels.L_42: maxDPB = 34816;  break;

            case AVCLevels.Levels.L_50: maxDPB = 110400; break;

            case AVCLevels.Levels.L_51: maxDPB = 184320; break;

            case AVCLevels.Levels.L_52: maxDPB = 184320; break;
            }

            int frameHeightInMbs = (int)System.Math.Ceiling((double)vRes / 16);
            int frameWidthInMbs  = (int)System.Math.Ceiling((double)hRes / 16);
            int maxRef           = (int)System.Math.Floor((double)maxDPB / (frameHeightInMbs * frameWidthInMbs));

            return(System.Math.Min(maxRef, 16));
        }
Example #3
0
        /// <summary>
        /// Verifies a group of x264Settings against an AVC Level
        /// </summary>
        /// <param name="settings">the x264Settings to test</param>
        /// <param name="level">the level</param>
        /// <param name="bytesInUncompressedFrame">Number of bytes in an uncompressed frame</param>
        /// <returns>   0 if the settings are compliant with the level
        ///             1 if (level > 3 || level = 3 AND Bframes > 0)
        ///             2 if maxDPB violated</returns>
        public int Verifyx264Settings(x264Settings settings, AVCLevels.Levels avcLevel, double bytesInUncompressedFrame)
        {
            if (!this.checkP4x4(avcLevel, settings))
            {
                return(1);
            }

            if (!this.checkMaxDPB(avcLevel, settings, bytesInUncompressedFrame))
            {
                return(2);
            }

            return(0);
        }
Example #4
0
        /// <summary>
        /// gets the maximum ref count based upon the given level
        /// </summary>
        /// <param name="level">the AVC level</param>
        /// <param name="hRes">the horizontal resolution</param>
        /// <param name="vRes">the vertical resolution</param>
        /// <returns>the maximum reference count; -1 if no restriction</returns>
        public static int getMaxRefForLevel(AVCLevels.Levels avcLevel, int hRes, int vRes)
        {
            if (hRes <= 0 || vRes <= 0 || avcLevel == AVCLevels.Levels.L_UNRESTRICTED)  // Unrestricted/Autoguess
            {
                return(-1);
            }

            AVCLevels oAVC             = new AVCLevels();
            int       maxDPB           = (int)oAVC.getMaxDPB(avcLevel); // the maximum picture decoded buffer for the given level
            int       frameHeightInMbs = (int)System.Math.Ceiling((double)vRes / 16);
            int       frameWidthInMbs  = (int)System.Math.Ceiling((double)hRes / 16);
            int       maxRef           = (int)System.Math.Floor((double)maxDPB / (frameHeightInMbs * frameWidthInMbs));

            return(System.Math.Min(maxRef, 16));
        }
Example #5
0
 public x264Device(int iID, string strName, int iProfile, AVCLevels.Levels avcLevel, int iVBVBufsize, int iVBVMaxrate, int iBframes, int iReframes, int iMaxWidth, int iMaxHeight, bool bBluRay, int iMaxGop, int iBPyramid)
 {
     this.iID         = iID;
     this.strName     = strName;
     this.iProfile    = iProfile;
     this.avcLevel    = avcLevel;
     this.iVBVBufsize = iVBVBufsize;
     this.iVBVMaxrate = iVBVMaxrate;
     this.iBframes    = iBframes;
     this.iReframes   = iReframes;
     this.iMaxWidth   = iMaxWidth;
     this.iMaxHeight  = iMaxHeight;
     this.bBluRay     = bBluRay;
     this.iBPyramid   = iBPyramid;
     this.iMaxGop     = iMaxGop;
 }
Example #6
0
        public static int GetDefaultNumberOfRefFrames(x264PresetLevelModes oPreset, x264PsyTuningModes oTuningMode, x264Device oDevice, AVCLevels.Levels avcLevel, bool blurayCompat, int hRes, int vRes)
        {
            int iDefaultSetting = 1;

            switch (oPreset)
            {
            case x264Settings.x264PresetLevelModes.ultrafast:
            case x264Settings.x264PresetLevelModes.superfast:
            case x264Settings.x264PresetLevelModes.veryfast:    iDefaultSetting = 1; break;

            case x264Settings.x264PresetLevelModes.faster:
            case x264Settings.x264PresetLevelModes.fast:        iDefaultSetting = 2; break;

            case x264Settings.x264PresetLevelModes.medium:      iDefaultSetting = 3; break;

            case x264Settings.x264PresetLevelModes.slow:        iDefaultSetting = 5; break;

            case x264Settings.x264PresetLevelModes.slower:      iDefaultSetting = 8; break;

            case x264Settings.x264PresetLevelModes.veryslow:
            case x264Settings.x264PresetLevelModes.placebo:     iDefaultSetting = 16; break;
            }
            if (oTuningMode == x264PsyTuningModes.ANIMATION && iDefaultSetting > 1)
            {
                iDefaultSetting *= 2;
            }
            if (iDefaultSetting > 16)
            {
                iDefaultSetting = 16;
            }
            if (blurayCompat)
            {
                iDefaultSetting = Math.Min(6, iDefaultSetting);
            }
            if (oDevice != null && oDevice.ReferenceFrames > -1)
            {
                iDefaultSetting = Math.Min(oDevice.ReferenceFrames, iDefaultSetting);
            }
            if (hRes > 0 && vRes > 0)
            {
                int iMaxRefForLevel = MeGUI.packages.video.x264.x264SettingsHandler.getMaxRefForLevel(avcLevel, hRes, vRes);
                if (iMaxRefForLevel > -1 && iMaxRefForLevel < iDefaultSetting)
                {
                    iDefaultSetting = iMaxRefForLevel;
                }
            }
            return(iDefaultSetting);
        }
Example #7
0
 public static int GetDefaultNumberOfRefFrames(x264PresetLevelModes oPreset, x264PsyTuningModes oTuningMode, x264Device oDevice, AVCLevels.Levels avcLevel, bool blurayCompat)
 {
     return(GetDefaultNumberOfRefFrames(oPreset, oTuningMode, oDevice, avcLevel, blurayCompat, -1, -1));
 }
Example #8
0
 /// <summary>
 /// default constructor, initializes codec default values
 /// </summary>
 public x264Settings() : base(ID, VideoEncoderType.X264)
 {
     x264DeviceList         = x264Device.CreateDeviceList();
     preset                 = x264PresetLevelModes.medium;
     psyTuningMode          = x264PsyTuningModes.NONE;
     deadZoneInter          = 21;
     deadZoneIntra          = 11;
     noFastPSkip            = false;
     ssimCalc               = false;
     psnrCalc               = false;
     EncodingMode           = 9;
     BitrateQuantizer       = 23;
     KeyframeInterval       = 250;
     nbRefFrames            = 3;
     noMixedRefs            = false;
     NbBframes              = 3;
     deblock                = true;
     alphaDeblock           = 0;
     betaDeblock            = 0;
     cabac                  = true;
     weightedBPrediction    = true;
     weightedPPrediction    = 2;
     NewadaptiveBFrames     = 1;
     bFramePyramid          = 2;
     subPelRefinement       = 7;
     psyRDO                 = new decimal(1.0);
     psyTrellis             = new decimal(0.0);
     macroBlockOptions      = 3;
     chromaME               = true;
     p8x8mv                 = true;
     b8x8mv                 = true;
     p4x4mv                 = false;
     i4x4mv                 = true;
     i8x8mv                 = true;
     MinQuantizer           = 0;
     MaxQuantizer           = 69;
     maxQuantDelta          = 4;
     CreditsQuantizer       = new decimal(40);
     ipFactor               = new decimal(1.4);
     pbFactor               = new decimal(1.3);
     chromaQPOffset         = new decimal(0.0);
     vbvBufferSize          = 0;
     vbvMaxBitrate          = 0;
     vbvInitialBuffer       = new decimal(0.9);
     bitrateVariance        = 1;
     quantCompression       = new decimal(0.6);
     tempComplexityBlur     = 20;
     tempQuanBlurCC         = new decimal(0.5);
     bframePredictionMode   = 1;
     scdSensitivity         = new decimal(40);
     bframeBias             = new decimal(0);
     meType                 = 1;
     meRange                = 16;
     NbThreads              = 0;
     minGOPSize             = 25;
     adaptiveDCT            = true;
     quantizerMatrix        = "";
     quantizerMatrixType    = 0;          // none
     x264Trellis            = 1;
     base.MaxNumberOfPasses = 3;
     AQMode                 = 1;
     AQStrength             = new decimal(1.0);
     useQPFile              = false;
     qpfile                 = "";
     FullRange              = false;
     range                  = "auto";
     advSet                 = false;
     lookahead              = 40;
     noMBTree               = true;
     threadInput            = true;
     noPsy                  = false;
     scenecut               = true;
     slicesnb               = 0;
     maxSliceSyzeBytes      = 0;
     maxSliceSyzeMBs        = 0;
     x264Nalhrd             = 0;
     x264PullDown           = 0;
     sampleAR               = 0;
     colorMatrix            = 0;
     transfer               = 0;
     colorPrim              = 0;
     x264Aud                = false;
     profile                = 3; // Autoguess. High if using default options.
     avcLevel               = AVCLevels.Levels.L_UNRESTRICTED;
     x264SlowFirstpass      = false;
     openGop                = "False";
     picStruct              = false;
     fakeInterlaced         = false;
     nonDeterministic       = false;
     interlacedMode         = x264InterlacedModes.progressive;
     targetDevice           = x264DeviceList[0];
     blurayCompat           = false;
     _gopCalculation        = 1;
     quantizerCrf           = 23;
     tuneFastDecode         = tuneZeroLatency = false;
     stitchable             = false;
     x26410Bits             = false;
 }
Example #9
0
 public x264Device(int iID, string strName, int iProfile, AVCLevels.Levels avcLevel, int iVBVBufsize, int iVBVMaxrate, int iBframes, int iReframes, int iMaxWidth, int iMaxHeight) :
     this(iID, strName, iProfile, avcLevel, iVBVBufsize, iVBVMaxrate, iBframes, iReframes, iMaxWidth, iMaxHeight, false, -1, -1)
 {
 }
Example #10
0
        /// <summary>
        /// Checks a collection of x264Settings and modifies them if needed to fit within the level constraints.
        /// </summary>
        /// <param name="level">the level to enforce</param>
        /// <param name="inputSettings">the collection of x264Settings to check</param>
        /// <param name="frameSize">the size of the decoded video frame in bytes</param>
        /// <returns>A compliant set of x264Settings</returns>
        public x264Settings EnforceSettings(AVCLevels.Levels avcLevel, x264Settings inputSettings, double frameSize, out AVCLevelEnforcementReturn enforcement)
        {
            x264Settings enforcedSettings = (x264Settings)inputSettings.Clone();

            enforcement                     = new AVCLevelEnforcementReturn();
            enforcement.Altered             = false;
            enforcement.EnableP4x4mv        = true;
            enforcement.EnableVBVBufferSize = true;
            enforcement.EnableVBVMaxRate    = true;
            enforcement.Panic               = false;
            enforcement.PanicString         = "";

            if (!checkP4x4(avcLevel, inputSettings))
            {
                enforcement.Altered     = true;
                enforcedSettings.P4x4mv = false;
            }
            if (checkP4x4Enabled(avcLevel, inputSettings))
            {
                enforcement.EnableP4x4mv = true;
            }
            else
            {
                enforcement.EnableP4x4mv = false;
            }

            // step through various options to enforce the max decoded picture buffer size
            while (!this.checkMaxDPB(avcLevel, enforcedSettings, frameSize))
            {
                if (enforcedSettings.NbRefFrames > 1)
                {
                    enforcement.Altered           = true;
                    enforcedSettings.NbRefFrames -= 1; // try reducing the number of reference frames
                }
                else
                {
                    enforcement.Panic       = true;
                    enforcement.PanicString = "Can't force settings to conform to level (the frame size is too large)";
                    // reset output settings to original and set level to unrestrained
                    enforcedSettings          = (x264Settings)inputSettings.Clone();
                    enforcedSettings.AVCLevel = Levels.L_UNRESTRICTED;
                    return(enforcedSettings);
                }
            }

            // Disallow independent specification of MaxBitrate and MaxBufferSize unless Unrestrained
            if (avcLevel != Levels.L_UNRESTRICTED)
            {
                enforcement.EnableVBVMaxRate    = false;
                enforcedSettings.VBVMaxBitrate  = -1;
                enforcement.EnableVBVBufferSize = false;
                enforcedSettings.VBVBufferSize  = -1;
            }
            else
            {
                enforcement.EnableVBVMaxRate    = true;
                enforcement.EnableVBVBufferSize = true;
            }

            return(enforcedSettings);
        }