using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace DaikuanDemo { class Program { static void Main(string[] args) { var data= bandwidthTesting(1080, 1920, "YCBCR_420", 1.064, 8, 60); Console.WriteLine(data); Console.ReadLine(); } public static double bandwidthTesting(double height, double width, string ChromaSamplingFactor, double PF, double BitsPerPixel, double FrameRate) { double HDMI_H_ACTIVE = width; BitsPerPixel = BitsPerPixel * 3; /** * 带宽计算公式: * "color_space" : "YCBCR_422" * 视频的总高度*视频的活跃宽度*色度采样因子*PF*像素深度(RGB每个占8,一共是24)*帧率/1 000 000 000 * HDMI_V_TOTAL * HDMI_H_ACTIVE * Chroma sampling factor * PF * Bits per pixel * Frame rate / 1 000 000 000 */ #region 对采样因子进行处理 retuen lastchromaSamplingFactor --张小墨 /** * 对色度采样因子进行处理: * 处理思路: * * 1.定义四个变量,用来存储在横竖方面各自的分子和分母 * 2.对ChromaSamplingFactor进行拆分,获取后三位,再将后三位拆成单个的数据 * 3.横向的分子是中间的数,分母是第一个数 * 4.竖向的,如果不是零,分子是1,分母是2. 如果是0,分子分母都是1 * 5.分别对横竖方面的分子分母进行约分 * 6.将横竖的分子相加,分母相加,结果进行约分 * 7.返回约分后的结果 * */ //分子 int line_numerator = 0, vertical_numerator = 0; //分母 int line_denominator = 0, vertical_denominator = 0; //最终的分子分母 double last_numerator = 0, last_denominator = 0; //YCBCR_422 var ChromaSamplingNumberstring = ChromaSamplingFactor.Split('_')[1].ToCharArray(); //取出每个数据 for (int i = 0; i < ChromaSamplingNumberstring.Length; i++) { if (i == 0) { line_denominator = int.Parse(ChromaSamplingNumberstring[i].ToString()); } if (i == 1) { line_numerator = int.Parse(ChromaSamplingNumberstring[i].ToString()); } if (i == 2) { vertical_numerator = 1;if (int.Parse(ChromaSamplingNumberstring[i].ToString()) != 0) { vertical_denominator = 1; } else { vertical_denominator = 2; } } } //对行数据进行约分 if (line_denominator % line_numerator == 0) { line_denominator = line_denominator / line_numerator; line_numerator = 1; } //获得最后的分子分母值 last_denominator = line_denominator + vertical_denominator; last_numerator = line_numerator + vertical_numerator; double lastchromaSamplingFactor = last_numerator / last_denominator; #endregion #region 计算HDMI_V_TOTA retuen HDMI_V_TOTA --张小墨 /** * 计算HDMI_V_TOTA: * 计算思路: *1.获取到此种视频的宽高隐藏比例 *2.计算例子:x-24%x=1280 (1-0.24)x=1280 x=1280/0.76=1684 * */ double HDMI_V_TOTA = 1080 / (1 - (4.00 / 100)); #endregion double bandWidth = HDMI_V_TOTA * HDMI_H_ACTIVE * lastchromaSamplingFactor * PF * BitsPerPixel * FrameRate / 1000000000; return bandWidth; } } }