Commit fe5734dd by tanghuan

上传优化

1 parent dba5d2f6
......@@ -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);
}
......
......@@ -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/';
......
......@@ -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('上传失败');
......
......@@ -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"'; // 输出文件
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!