ffmpeg - 构建一个直播页面,用户将通过 ip 地址输入一个 rtsp 流媒体源
问题描述
我正在构建一个直播页面,其中流媒体源通过 rtsp 流式传输。目前,我正在使用 ffmpeg 将传入的 rtsp 流转换为 .m3u8 文件,并通过 HLS 在网页上播放。
我现在要解决的问题是根据用户的输入加载一个 rtsp 流。我该如何解决这个问题?必须能够在 iOS 和 android 上查看流。ffmpeg 命令:
ffmpeg -i "rtsp://10.193.79.185:5554" -hls_time 3 -hls_wrap 10 "C:\wamp64\www\hls\output.m3u8"
我目前拥有的加载硬编码 rtsp 流的代码
<!DOCTYPE html>
<html>
<body>
<script src="https://cdn.jsdelivr.net/npm/hls.js@latest"></script>
<center>
<h1>RTSP Stream</h1>
<input type ="text" name="rtspAddress" placeholder="RTSP address">
<input type ="text" name="output" placeholder="output Name">
<button type="submit" name="submit">Start</button>
<video height="600" id="video" controls></video>
</center>
<script>
if(Hls.isSupported())
{
var video = document.getElementById('video');
var mystring = "http://192.168.43.79/hls/output.m3u8";
var hls = new Hls({
debug: true
});
hls.loadSource(mystring);
hls.attachMedia(video);
hls.on(Hls.Events.MEDIA_ATTACHED, function() {
video.muted = true;
video.play();
});
}
// hls.js is not supported on platforms that do not have Media Source Extensions (MSE) enabled.
// When the browser has built-in HLS support (check using `canPlayType`), we can provide an HLS manifest (i.e. .m3u8 URL) directly to the video element throught the `src` property.
// This is using the built-in support of the plain video element, without using hls.js.
else if (video.canPlayType('application/vnd.apple.mpegurl')) {
video.src = 'http://192.168.43.79/hls/output.m3u8';
video.addEventListener('canplay',function() {
video.play();
});
}
</script>
</body>
</html>
解决方案
推荐阅读
- angular - primeNG 表上的可编辑行问题
- reactjs - reactjs中formik表单初始值如何设置前置字段数据
- google-cloud-platform - 云任务未按时运行
- arrays - 如何最大化给定数组中有效索引的数量?
- sql-server - 如何使用 SQL/T-SQL 正确地对扩展字符集进行 Base64 编码
- c# - 如何在 ASP.NET Core 3.1 MVC 中进行自定义路由
- python - How to append two DataFrames with different number of rows, populating the shorter one
- while-loop - Jmeter如何在while控制器下计算样本的响应时间
- machine-learning - 近端策略优化算法论文 - “KL”操作的定义?
- angular - 有什么方法可以支持 Angular 8 的 IE 兼容性视图?