namespace Vinno.vCloud.FIS.CrossPlatform.Windows.LiveVideo
{
public class VideoHelper
{
///
/// 计算码率
///
/// 帧率
/// 宽度
/// 高度
///
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;
}
///
/// 计算最大码率
///
/// 帧率
/// 宽度
/// 高度
/// 是否使用平均码率
///
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;
}
///
/// 计算视频质量
///
/// 宽度
/// 高度
/// 是否使用h264
///
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;
}
///
/// 计算视频编码速度
///
/// 宽度
/// 高度
/// 是否使用h264
///
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;
}
}
}
}