Commit 9d1c99d7 by tanghuan

ios 18.6.x 不使用 h264_videotoolbox

1 parent 7a995230
......@@ -9,7 +9,8 @@ class VideoUtil {
///
/// 将视频格式转换为mp4
/// 转码的同时,根据文件大小自动选择压缩参数
/// iOS: h264_videotoolbox 硬件加速 + 按文件大小自动码率
/// iOS 18.6.x: libx264 + 按文件大小自动CRF(h264_videotoolbox在iOS 18.6.x存在稳定性问题)
/// 其它iOS版本: h264_videotoolbox 硬件加速 + 按文件大小自动码率
/// Android: libx264 + 按文件大小自动CRF
/// [onProgress] 进度回调,值范围 0.0 ~ 1.0
///
......@@ -23,7 +24,7 @@ class VideoUtil {
final fileSize = await File(inputPath).length();
String cmd;
if (Platform.isIOS) {
if (Platform.isIOS && !_isIos18_6()) {
final bitrate = _getBitrateByFileSize(fileSize);
cmd = '-i "$inputPath" '
'-c:v h264_videotoolbox ' // 启用 iOS 硬件加速
......@@ -138,6 +139,23 @@ class VideoUtil {
return completer.future;
}
/// 判断当前iOS系统版本是否为18.6.x
/// iOS 18.6.x中h264_videotoolbox硬件编码器存在稳定性问题,需改用libx264
static bool _isIos18_6() {
if (!Platform.isIOS) return false;
try {
final versionStr = Platform.operatingSystemVersion;
final regex = RegExp(r'(\d+)\.(\d+)');
final match = regex.firstMatch(versionStr);
if (match != null) {
final major = int.parse(match.group(1)!);
final minor = int.parse(match.group(2)!);
return major == 18 && minor == 6;
}
} catch (_) {}
return false;
}
/// 根据文件大小自动计算视频码率(kbps)
/// 用于iOS h264_videotoolbox硬件加速模式(不支持CRF,需用码率控制质量)
/// 文件越大码率越低(压缩率越高,清晰度越低)
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!