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 fe5734dd
authored
2026-04-21 10:46:15 +0800
by
tanghuan
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
上传优化
1 parent
dba5d2f6
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
15 additions
and
5 deletions
lib/bloc/web_cubit.dart
lib/config/constant.dart
lib/data/repositories/message/upload_start_handler.dart
lib/utils/video_util.dart
lib/bloc/web_cubit.dart
View file @
fe5734d
...
...
@@ -456,7 +456,7 @@ class WebCubit extends Cubit<WebState> with WidgetsBindingObserver {
_sendResponse
(
resp
);
}
void
sendUploadEnd
(
String
unique
,
String
uploadId
,
String
url
)
{
void
sendUploadEnd
(
String
unique
,
String
uploadId
,
String
url
,
{
String
errMsg
=
''
}
)
{
var
resp
=
{
'unique'
:
''
,
'cmd'
:
'uploadEnd'
,
...
...
@@ -464,7 +464,7 @@ class WebCubit extends Cubit<WebState> with WidgetsBindingObserver {
'uploadId'
:
uploadId
,
'url'
:
url
,
},
'errMsg'
:
''
'errMsg'
:
errMsg
};
_sendResponse
(
resp
);
}
...
...
lib/config/constant.dart
View file @
fe5734d
...
...
@@ -24,7 +24,7 @@ class Constant {
/// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///
/// obs文件分片上传的分片大小:5M
static
const
int
obsUploadChunkSize
=
1024
*
1024
*
5
;
static
const
int
obsUploadChunkSize
=
1024
*
1024
*
1
;
/// obs文件上传的逻辑前缀
static
const
String
obsLogicPrefix
=
EnvConfig
.
env
==
'dev'
?
'd2/pridel/user/'
:
'p2/unpridel/user/'
;
...
...
lib/data/repositories/message/upload_start_handler.dart
View file @
fe5734d
...
...
@@ -81,6 +81,12 @@ class UploadStartHandler extends MessageHandler {
// 返回 null,让 MessageDispatcher 不处理返回指令
return
null
;
}
catch
(
e
)
{
debugPrint
(
'====================>上传失败:
$e
'
);
// 确保发送了 uploadEnd 指令
if
(
e
is
Exception
&&
e
.
toString
()
!=
Exception
(
'参数错误'
).
toString
())
{
_webCubit
?.
sendUploadEnd
(
_cmdUnique
,
_cmdUploadId
,
''
,
errMsg:
e
.
toString
());
}
}
finally
{
_unfollowCubit
();
}
...
...
@@ -369,7 +375,7 @@ class UploadStartHandler extends MessageHandler {
throw
Exception
(
'Chunk
$chunkIndex
upload failed after
$maxRetries
attempts:
$e
'
);
}
// 等待后重试
await
Future
.
delayed
(
Duration
(
seconds:
2
*
attempt
));
await
Future
.
delayed
(
Duration
(
seconds:
2
*
(
attempt
+
1
)
));
}
}
throw
Exception
(
'上传失败'
);
...
...
lib/utils/video_util.dart
View file @
fe5734d
...
...
@@ -34,6 +34,8 @@ class VideoUtil {
'-crf 28 '
// 设置恒定速率因子CRF为28(中等压缩质量)
'-c:a aac '
// 设置音频编码器为AAC
'-b:a 128k '
// 设置音频比特率为128kbps
'-preset fast '
'-threads 0 '
'-strict experimental '
// 允许使用实验性编解码器功能
'-movflags faststart '
// 优化MP4文件结构,使视频可以快速启动播放
'-f mp4 '
// 指定输出格式为MP4
...
...
@@ -96,7 +98,9 @@ class VideoUtil {
'-crf
$crf
'
// 恒定速率因子(质量控制)
'-c:a aac '
// 音频编码器
'-b:a 128k '
// 音频比特率
'-preset medium '
// 编码预设
// '-preset medium ' // 编码预设
'-preset fast '
// 编码预设,编码速度显著提升,体积损失很小
'-threads 0 '
// 让 libx264 自动使用所有可用 CPU 核心,默认行为可能只用单核
'-movflags faststart '
// 优化MP4文件结构
'"
$outputPath
"'
;
// 输出文件
...
...
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