Skip to content

Commit 3f6c8ea

Browse files
committed
fix(*)
1 parent 104d375 commit 3f6c8ea

3 files changed

Lines changed: 12 additions & 21 deletions

File tree

lib/recorder/ffmpeg/ffmpeg_command_builder.dart

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,43 +20,32 @@ class FFmpegCommandBuilder {
2020
final ua = headers?['user-agent'] ?? defaultUserAgent;
2121
final headerStr = _buildHeader(headers);
2222
final normalizedOutputPath = '$outputDir${Platform.pathSeparator}%Y%m%d_%H%M%S.ts';
23+
final rwTimeoutMicro = (rwTimeout * 1000000).clamp(0, 2147483647);
24+
2325
final args = <String>[
2426
'-y',
2527
'-hide_banner',
2628
'-loglevel', 'info',
27-
// 允许的协议白名单,确保直播流能正常加载
2829
'-protocol_whitelist', 'httpproxy,udp,rtp,tcp,tls,data,file,http,https,crypto',
29-
30-
// --- 重连与网络优化 ---
3130
'-reconnect', '1',
3231
'-reconnect_streamed', '1',
3332
'-reconnect_delay_max', '2',
3433
'-reconnect_at_eof', '1',
35-
'-rw_timeout', '${rwTimeout * 1000000}', // 转化为微秒
34+
'-rw_timeout', rwTimeoutMicro.toString(),
3635
'-max_delay', '5000000',
3736
'-thread_queue_size', threadQueueSize.toString(),
38-
39-
// --- 身份伪装 ---
40-
'-user_agent', _quote(ua),
41-
if (headerStr.isNotEmpty) ...['-headers', _quote(headerStr)], // 关键:headers必须包裹在引号内
42-
// --- 输入 ---
43-
'-i', _quote(url),
44-
45-
// --- 轨道处理 ---
46-
// 使用 copy 模式避免 CPU 占用过高
37+
'-user_agent', ua,
38+
if (headerStr.isNotEmpty) ...['-headers', _quote(headerStr)], //关键:headers
39+
'-i', url,
4740
'-map', preferBestStream ? '0:v:0' : '0:v',
4841
'-map', preferBestStream ? '0:a:0' : '0:a',
4942
'-c', 'copy',
50-
51-
// --- 分段逻辑 ---
5243
'-f', 'segment',
5344
'-segment_format', 'mpegts',
5445
'-segment_time', segmentTime.toString(),
5546
'-reset_timestamps', '1',
5647
'-strftime', '1',
57-
58-
// 输出路径 (使用 .ts 格式以防断流导致文件损坏)
59-
_quote(normalizedOutputPath),
48+
normalizedOutputPath,
6049
];
6150

6251
return args.join(' ');
@@ -68,8 +57,6 @@ class FFmpegCommandBuilder {
6857
.where((e) => e.key.toLowerCase() != 'user-agent')
6958
.map((e) => '${e.key}: ${e.value}')
7059
.join('\r\n');
71-
72-
// FFmpeg 要求 headers 末尾也必须有换行符
7360
return lines.isEmpty ? '' : '$lines\r\n';
7461
}
7562
}

lib/recorder/pages/recorder/recorder_controller.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,10 @@ class RecorderController extends GetxService {
287287
if (task.status == RecordStatus.running || task.status == RecordStatus.preparing) {
288288
log('Stopping task: ${task.taskId}');
289289
}
290+
if (task.status == RecordStatus.reconnecting) {
291+
task.status = RecordStatus.stopped;
292+
updateTask(task);
293+
}
290294
}
291295

292296
Future<void> _onComplete(LiveRecordTask task) async {

lib/recorder/services/ffmpeg_service.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ class FFmpegService {
6161
);
6262
});
6363
ffempgSession.setCompleteCallback((completedSession) {
64-
log('FFmpeg complete => $taskId');
6564
final code = completedSession.getReturnCode();
6665
final success = ReturnCode.isSuccess(code);
66+
log('FFmpeg complete => taskId: $taskId;successCode: $code ');
6767
onEvent(
6868
FFmpegEvent(
6969
taskId: taskId,

0 commit comments

Comments
 (0)