Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
ethan
/
appframe
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit 9d1c99d7
authored
2026-04-29 09:28:29 +0800
by
tanghuan
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
ios 18.6.x 不使用 h264_videotoolbox
1 parent
7a995230
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
2 deletions
lib/utils/video_util.dart
lib/utils/video_util.dart
View file @
9d1c99d
...
@@ -9,7 +9,8 @@ class VideoUtil {
...
@@ -9,7 +9,8 @@ class VideoUtil {
///
///
/// 将视频格式转换为mp4
/// 将视频格式转换为mp4
/// 转码的同时,根据文件大小自动选择压缩参数
/// 转码的同时,根据文件大小自动选择压缩参数
/// iOS: h264_videotoolbox 硬件加速 + 按文件大小自动码率
/// iOS 18.6.x: libx264 + 按文件大小自动CRF(h264_videotoolbox在iOS 18.6.x存在稳定性问题)
/// 其它iOS版本: h264_videotoolbox 硬件加速 + 按文件大小自动码率
/// Android: libx264 + 按文件大小自动CRF
/// Android: libx264 + 按文件大小自动CRF
/// [onProgress] 进度回调,值范围 0.0 ~ 1.0
/// [onProgress] 进度回调,值范围 0.0 ~ 1.0
///
///
...
@@ -23,7 +24,7 @@ class VideoUtil {
...
@@ -23,7 +24,7 @@ class VideoUtil {
final
fileSize
=
await
File
(
inputPath
).
length
();
final
fileSize
=
await
File
(
inputPath
).
length
();
String
cmd
;
String
cmd
;
if
(
Platform
.
isIOS
)
{
if
(
Platform
.
isIOS
&&
!
_isIos18_6
()
)
{
final
bitrate
=
_getBitrateByFileSize
(
fileSize
);
final
bitrate
=
_getBitrateByFileSize
(
fileSize
);
cmd
=
'-i "
$inputPath
" '
cmd
=
'-i "
$inputPath
" '
'-c:v h264_videotoolbox '
// 启用 iOS 硬件加速
'-c:v h264_videotoolbox '
// 启用 iOS 硬件加速
...
@@ -138,6 +139,23 @@ class VideoUtil {
...
@@ -138,6 +139,23 @@ class VideoUtil {
return
completer
.
future
;
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)
/// 根据文件大小自动计算视频码率(kbps)
/// 用于iOS h264_videotoolbox硬件加速模式(不支持CRF,需用码率控制质量)
/// 用于iOS h264_videotoolbox硬件加速模式(不支持CRF,需用码率控制质量)
/// 文件越大码率越低(压缩率越高,清晰度越低)
/// 文件越大码率越低(压缩率越高,清晰度越低)
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment