123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238 |
- namespace Vinno.vCloud.FIS.CrossPlatform.Windows.LiveVideo
- {
- public class VideoHelper
- {
- /// <summary>
- /// 计算码率
- /// </summary>
- /// <param name="frameRate">帧率</param>
- /// <param name="width">宽度</param>
- /// <param name="height">高度</param>
- /// <returns></returns>
- public static int CalBitRate(int frameRate, int width, int height)
- {
- int kbit_rate = 2000;
- int area = width * height;
- if (area <= (320 * 300))
- {
- kbit_rate = 280;
- }
- else if (area <= (360 * 320))
- {
- kbit_rate = 360;
- }
- else if (area <= (640 * 480))
- {
- kbit_rate = 580;
- }
- else if (area <= (800 * 600))
- {
- kbit_rate = 620;
- }
- else if (area <= (900 * 700))
- {
- kbit_rate = 820;
- }
- else if (area <= (1280 * 720))
- {
- kbit_rate = 1600;
- }
- else if (area <= (1366 * 768))
- {
- kbit_rate = 2000;
- }
- else if (area <= (1600 * 900))
- {
- kbit_rate = 2300;
- }
- else if (area <= (1600 * 1050))
- {
- kbit_rate = 2500;
- }
- else
- {
- kbit_rate = 2800;
- }
- kbit_rate = kbit_rate * frameRate / 20;
- if (kbit_rate < 80)
- kbit_rate = 80;
- return kbit_rate;
- }
- /// <summary>
- /// 计算最大码率
- /// </summary>
- /// <param name="frameRate">帧率</param>
- /// <param name="width">宽度</param>
- /// <param name="height">高度</param>
- /// <param name="isVarBitrate">是否使用平均码率</param>
- /// <returns></returns>
- public static int CalMaxKBitRate(int frameRate, int width, int height, bool isVarBitrate)
- {
- int max_kbit_rate = 2000;
- int area = width * height;
- if (area <= (320 * 300))
- {
- max_kbit_rate = isVarBitrate ? 320 : 600;
- }
- else if (area <= (360 * 320))
- {
- max_kbit_rate = isVarBitrate ? 400 : 800;
- }
- else if (area <= (640 * 360))
- {
- max_kbit_rate = isVarBitrate ? 600 : 1000;
- }
- else if (area <= (640 * 480))
- {
- max_kbit_rate = isVarBitrate ? 680 : 1300;
- }
- else if (area <= (800 * 600))
- {
- max_kbit_rate = isVarBitrate ? 700 : 1500;
- }
- else if (area <= (900 * 700))
- {
- max_kbit_rate = isVarBitrate ? 920 : 2200;
- }
- else if (area <= (1280 * 720))
- {
- max_kbit_rate = isVarBitrate ? 1600 : 3000;
- }
- else if (area <= (1366 * 768))
- {
- max_kbit_rate = isVarBitrate ? 1700 : 3300;
- }
- else if (area <= (1600 * 900))
- {
- max_kbit_rate = isVarBitrate ? 2400 : 3400;
- }
- else if (area <= (1600 * 1050))
- {
- max_kbit_rate = isVarBitrate ? 2600 : 3600;
- }
- else if (area <= (1920 * 1080))
- {
- max_kbit_rate = isVarBitrate ? 2900 : 3800;
- }
- else
- {
- max_kbit_rate = isVarBitrate ? 3500 : 5500;
- }
- max_kbit_rate = max_kbit_rate * frameRate / 25;
- if (area <= (320 * 240))
- {
- if (max_kbit_rate < 150)
- max_kbit_rate = 150;
- }
- else if (area <= (640 * 480))
- {
- if (max_kbit_rate < 300)
- max_kbit_rate = 300;
- }
- else if (area <= (1280 * 720))
- {
- if (max_kbit_rate < 600)
- max_kbit_rate = 600;
- }
- else if (area <= (1920 * 1080))
- {
- if (max_kbit_rate < 960)
- max_kbit_rate = 960;
- }
- else
- {
- if (max_kbit_rate < 1500)
- max_kbit_rate = 1500;
- }
- return max_kbit_rate;
- }
- /// <summary>
- /// 计算视频质量
- /// </summary>
- /// <param name="width">宽度</param>
- /// <param name="height">高度</param>
- /// <param name="ish264">是否使用h264</param>
- /// <returns></returns>
- public static int CalVideoQuality(int width, int height, bool ish264)
- {
- int area = width * height;
- int quality = ish264 ? 23 : 28;
- if (area <= (320 * 240))
- {
- quality = ish264 ? 23 : 27;
- }
- else if (area <= (640 * 360))
- {
- quality = ish264 ? 25 : 28;
- }
- else if (area <= (640 * 480))
- {
- quality = ish264 ? 25 : 28;
- }
- else if (area <= (960 * 600))
- {
- quality = ish264 ? 26 : 28;
- }
- else if (area <= (1280 * 720))
- {
- quality = ish264 ? 27 : 29;
- }
- else if (area <= (1600 * 900))
- {
- quality = ish264 ? 28 : 30;
- }
- else if (area <= (1920 * 1080))
- {
- quality = ish264 ? 29 : 31;
- }
- else
- {
- quality = ish264 ? 30 : 32;
- }
- return quality;
- }
- /// <summary>
- /// 计算视频编码速度
- /// </summary>
- /// <param name="width">宽度</param>
- /// <param name="height">高度</param>
- /// <param name="ish264">是否使用h264</param>
- /// <returns></returns>
- public static int CalVideoEncoderSpeed(int width, int height, bool ish264)
- {
- if (ish264)
- return 3;
- int area = width * height;
- if (area <= (960 * 600))
- {
- return 3;
- }
- else if (area <= (1280 * 720))
- {
- return 2;
- }
- else
- {
- return 1;
- }
- }
- }
- }
|