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 4f351c61
authored
2025-11-24 16:36:07 +0800
by
tanghuan
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
ios 视频转码指令优化
1 parent
7bd593e0
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
4 deletions
lib/utils/video_util.dart
lib/utils/video_util.dart
View file @
4f351c6
import
'dart:io'
;
import
'package:ffmpeg_kit_flutter_new/ffmpeg_kit.dart'
;
import
'package:ffmpeg_kit_flutter_new/ffmpeg_kit.dart'
;
import
'package:ffmpeg_kit_flutter_new/return_code.dart'
;
import
'package:ffmpeg_kit_flutter_new/return_code.dart'
;
...
@@ -7,10 +9,27 @@ class VideoUtil {
...
@@ -7,10 +9,27 @@ class VideoUtil {
/// 转码的同时,进行压缩
/// 转码的同时,进行压缩
///
///
static
Future
<
bool
>
convertToMp4
(
String
inputPath
,
String
outputPath
)
async
{
static
Future
<
bool
>
convertToMp4
(
String
inputPath
,
String
outputPath
)
async
{
// final session = await FFmpegKit.execute(
// '-i "$inputPath" -c:v libx264 -c:a aac -strict experimental -movflags faststart -f mp4 "$outputPath"');
String
cmd
;
final
session
=
await
FFmpegKit
.
execute
(
if
(
Platform
.
isIOS
)
{
'-i "
$inputPath
" -c:v libx264 -crf 28 -c:a aac -b:a 128k -strict experimental -movflags faststart -f mp4 "
$outputPath
"'
);
// 构建命令
// 1. -c:v h264_videotoolbox : 启用 iOS 硬件加速
// 2. -b:v 1500k : 限制视频码率为 1.5Mbps (体积小,手机看足够)
// 3. -vf scale=1280:-2 : 缩放到 720p (保持比例)
// 4. -c:a aac : 音频转为 AAC (兼容性最好)
// 5. -b:a 128k : 音频码率
cmd
=
'-i "
$inputPath
" '
'-c:v h264_videotoolbox -b:v 1500k '
'-vf scale=1280:-2 '
'-c:a aac -b:a 128k '
'"
$outputPath
"'
;
print
(
"开始极速转码:
$cmd
"
);
}
else
{
cmd
=
'-i "
$inputPath
" -c:v libx264 -crf 28 -c:a aac -b:a 128k -strict experimental -movflags faststart -f mp4 "
$outputPath
"'
;
}
final
session
=
await
FFmpegKit
.
execute
(
cmd
);
final
returnCode
=
await
session
.
getReturnCode
();
final
returnCode
=
await
session
.
getReturnCode
();
return
ReturnCode
.
isSuccess
(
returnCode
);
return
ReturnCode
.
isSuccess
(
returnCode
);
}
}
...
...
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