1.准备ffmpeg 和(rtsp-simple-server + srs搭建流媒体服务器)视频服务器.
2.解压视频流服务器修改配置文件mediamtx.yml ,hlsAlwaysRemux: yes
3.双击运行服务器。
4,安装ffmpeg ,添加到环境变量。
5.查询本机设备列表
ffmpeg -list_devices true -f dshow -i dummy
6.查看当前摄像头的详细参数
ffmpeg -list_options true -f dshow -i video="Integrated Camera"
7.预览本机摄像头画面
ffplay -f dshow -i video="Integrated Camera"
8.将本地电脑摄像头打开将视频流传到rtmp服务器
ffmpeg -f dshow -i audio="麦克风阵列 (Synaptics Audio)" -f dshow -i video="Integrated Camera" -vcodec libx264 -preset veryfast -maxrate 1000k -bufsize 2000k -vf "format=yuv420p" -g 50 -f flv rtmp://10.204.51.49:1935/love/stream
9.将rtmp视频流转成hls格式视频流,文件放nginx服务下
ffmpeg -i rtmp://10.204.51.49:1935/love/stream -vcodec copy -acodec copy -f hls -hls_flags delete_segments -segment_list_size 10 -hls_list_size 5 video.m3u8
10.创建一个html页面方法在nginx服务下
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>HLS 播放本地视频流</title><script src="https://cdn.jsdelivr.net/npm/hls.js@latest"></script>
</head>
<body><video id="video" controls></video><script>if (Hls.isSupported()) {var video = document.getElementById('video');var hls = new Hls();hls.loadSource('./video.m3u8'); // 替换为你的HLS流地址hls.attachMedia(video);hls.on(Hls.Events.MANIFEST_PARSED, function() {video.play();});} else if (video.canPlayType('application/vnd.apple.mpegurl')) {video.src = './video.m3u8'; // Safari支持HLS原生播放video.addEventListener('loadedmetadata', function() {video.play();});}</script>
</body>
</html>