我们有一个从摄像头流式传输的 RTMP 服务器,该流 URL 被发送到 Flutter 应用程序进行显示,我们使用以下包进行存档:
media_kit
,该包运行良好。
我们现在需要实现一项功能,让 Flutter 应用程序在按下按钮时记录 X 秒数。
我的问题是我可以创建一个类似 HTTP 的请求来监听流字节并写入 mp4 文件吗?
我已经尝试过这个: 已经
widget.url
= = rtmp://rtmp-server-the-rest-of-the-url
var uri = Uri.parse(widget.url);
try {
final path = await _localPath;
final file = await File('$path/test.mp4').create(recursive: true);
var request = http.MultipartRequest("POST", uri);
final response = await request.send();
var bytes = <int>[];
response.stream.listen((newBytes) {
bytes.addAll(newBytes);
});
Future.delayed(const Duration(seconds: 10), (() {
file.writeAsBytes(bytes);
}));
} catch (error) {
print(error.toString());
}
没有成功,我收到一个错误:
Invalid argument(s): Unsupported scheme 'rtmp' in URI rtmp://rtmp-server-rest-of-the-url
http 包不适用于 RTMP 链接,因此您会遇到无效的 url 错误,请尝试 rtmp_broadcaster: ^2.2.4