需要一些帮助。视频在浏览器中加载,但从未开始播放。我正在使用 hls.js 将 m3u8 播放列表流式传输到浏览器。我使用 FFmpeg 创建 ts 和 m3u8 文件。
对于 FFmpeg:
./ffmpeg -rtsp_transport tcp -i rtsp://user:password@ipaddress/axis-media/media.amp -vcodec copy -hls_time 4 -hls_list_size 4 -hls_wrap 4 -start_number 1 -y test.m3u8
HTML 代码:
<!DOCTYPE html>
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/hls.js@latest"></script>
</head>
<body>
<video id="video" height="800px" width="1200px"></video>
<body>
<script>
var video = document.getElementById('video');
if(Hls.isSupported()){
var hls = new Hls();
hls.loadSource('/images/live/test.m3u8');
hls.attachMedia(video);
hls.on(Hls.Events.MANIFEST_PARSED,function() {
video.play();
});
}
else if (video.canPlayType('application/vnd.apple.mpegurl')){
video.src = '/images/live/test.m3u8';
video.addEventListener('loadedmetadata',function() {
video.play();
});
}
</script>
</html>
最佳答案
只需将 ffmpeg 命令行更改为:
ffmpeg -rtsp_transport tcp -i rtsp://user:password@ip_address/axis-media/media.amp -y -s 854x480 -codec:v libx264 -b:v 800000 -hls_time 4 -hls_list_size 4 -hls_wrap 4 start_number 0 test .m3u8
关于javascript - TS 文件不播放 hls.js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57602466/