当前位置: 首页 > news >正文

网站不备案能用吗百度如何发布作品

网站不备案能用吗,百度如何发布作品,合肥网站制作专业,免费域名freenom之前写的使用FFmpeg Nginx HLS流媒体播放方案,适合对实时性要求不高的需求,存在延迟,FFmpeg需要将视频流存储到本地文件,而本次方案FFmpeg不需要将视频流存储到本地文件,而是直接将转换后的视频流(如MJPE…

之前写的使用FFmpeg + Nginx + HLS流媒体播放方案,适合对实时性要求不高的需求,存在延迟,FFmpeg需要将视频流存储到本地文件,而本次方案FFmpeg不需要将视频流存储到本地文件,而是直接将转换后的视频流(如MJPEG格式)通过标准输出(stdout)传递给WebSocket服务器,WebSocket服务器再将数据实时推送到前端。这种方式是实时流传输,适合需要低延迟的场景。

以下是详细的实现逻辑:


1. FFmpeg 直接输出到 WebSocket 服务器

FFmpeg 通过命令行参数将 RTSP 流转换为 MJPEG 格式,并将输出直接发送到标准输出(stdout),而不是保存到文件。WebSocket 服务器通过 Node.js 的 child_process 模块捕获 FFmpeg 的输出,并将其转发给连接的客户端。

FFmpeg 命令
ffmpeg -i rtsp://your_rtsp_stream_url -f mjpeg -qscale:v 2 -
  • -i rtsp://your_rtsp_stream_url:输入 RTSP 流地址。
  • -f mjpeg:输出格式为 MJPEG。
  • -qscale:v 2:设置视频质量(值越小质量越高)。
  • -:将输出发送到标准输出(stdout),而不是文件。

2. WebSocket 服务器捕获 FFmpeg 输出

WebSocket 服务器通过 Node.js 启动 FFmpeg 进程,并监听其 stdout 数据流。每当 FFmpeg 输出一帧数据时,WebSocket 服务器就将这帧数据发送给所有连接的客户端。

WebSocket 服务器代码 (server.js)
const { spawn } = require('child_process');
const WebSocket = require('ws');// 创建 WebSocket 服务器
const wss = new WebSocket.Server({ port: 8080 });wss.on('connection', (ws) => {console.log('Client connected');// 启动 FFmpeg 进程const ffmpeg = spawn('ffmpeg', ['-rtsp_transport', 'tcp', // 使用 TCP 传输 RTSP 流(如果 UDP 不稳定)'-i', 'rtsp://admin:password@192.168.1.60:554/Streaming/Channels/101/', // RTSP 流地址'-f', 'mpegts', // 输出格式为 MPEG-TS'-codec:v', 'mpeg1video', // 使用 MPEG-1 编码'-s', '640x360', // 分辨率'-b:v', '800k', // 视频比特率'-bf', '0', // 禁用 B 帧'-an', // 禁用音频'pipe:1' // 输出到标准输出]);// 将 FFmpeg 的输出发送到 WebSocket 客户端ffmpeg.stdout.on('data', (data) => {if (ws.readyState === ws.OPEN) {ws.send(data); // 发送二进制数据}});// 处理 FFmpeg 的错误输出ffmpeg.stderr.on('data', (data) => {console.error(`FFmpeg error: ${data}`);});// 处理 FFmpeg 进程退出ffmpeg.on('close', (code) => {console.log(`FFmpeg process exited with code ${code}`);});// 客户端断开连接时关闭 FFmpeg 进程ws.on('close', () => {console.log('Client disconnected');ffmpeg.kill(); // 杀死 FFmpeg 进程});
});console.log('WebSocket server is running on ws://localhost:8080');

3. 前端使用 JsMpeg 播放视频流

前端通过 JsMpeg 库连接到 WebSocket 服务器,并实时解码和播放 MJPEG 视频流。

前端代码 (index.html)
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Video Streaming</title><script src="https://cdn.jsdelivr.net/npm/jsmpeg/jsmpeg.min.js"></script>
</head>
<body><canvas id="video-canvas"></canvas><script>// 创建 JsMpeg 播放器const canvas = document.getElementById('video-canvas');const player = new JSMpeg.Player('ws://localhost:8080', {canvas: canvas});</script>
</body>
</html>

4. 运行流程

  1. FFmpeg

    • 从 RTSP 流中读取视频数据。
    • 将视频数据转换为 MJPEG 格式。
    • 将转换后的数据通过标准输出(stdout)发送。
  2. WebSocket 服务器

    • 启动 FFmpeg 进程并捕获其 stdout 数据。
    • 将捕获到的数据通过 WebSocket 发送给前端。
  3. 前端

    • 使用 JsMpeg 连接到 WebSocket 服务器。
    • 接收并解码 MJPEG 数据,实时显示在 <canvas> 中。

5. 优点

  • 实时性:视频流直接从 FFmpeg 推送到前端,延迟较低。
  • 无需存储:视频流不需要保存到本地文件,节省磁盘空间。
  • 简单易用:只需运行 FFmpeg 和 WebSocket 服务器即可。

6. 注意事项

  • FFmpeg 性能:如果 RTSP 流的分辨率较高,FFmpeg 的转换可能会占用较多 CPU 资源。可以通过调整 -qscale:v 参数来优化性能。
  • 网络带宽:MJPEG 格式的视频流数据量较大,确保网络带宽足够。
  • WebSocket 连接数:如果有多个客户端连接,WebSocket 服务器需要处理更多的数据转发,可能会增加服务器负载。

7. 总结

通过这种方式,FFmpeg 直接将 RTSP 流转换为 MJPEG 格式并输出到 WebSocket 服务器,WebSocket 服务器再将数据实时推送到前端,前端使用 JsMpeg 进行播放。整个过程无需存储视频文件,适合实时视频流传输的场景。


文章转载自:
http://dinncogranadero.tqpr.cn
http://dinncoritualistic.tqpr.cn
http://dinncoundemonstrative.tqpr.cn
http://dinncoleave.tqpr.cn
http://dinncoticking.tqpr.cn
http://dinncocyclolysis.tqpr.cn
http://dinncodeprecatory.tqpr.cn
http://dinncoinconnected.tqpr.cn
http://dinncoprocrypsis.tqpr.cn
http://dinncopagehood.tqpr.cn
http://dinncomonothematic.tqpr.cn
http://dinncoseduceable.tqpr.cn
http://dinncophysiographical.tqpr.cn
http://dinncoheos.tqpr.cn
http://dinncorude.tqpr.cn
http://dinncogavial.tqpr.cn
http://dinncoxxxv.tqpr.cn
http://dinncobridgeable.tqpr.cn
http://dinncocorporeity.tqpr.cn
http://dinncomukalla.tqpr.cn
http://dinncodownside.tqpr.cn
http://dinncoregalist.tqpr.cn
http://dinncopipul.tqpr.cn
http://dinncodrumfish.tqpr.cn
http://dinncopaktong.tqpr.cn
http://dinncopeonage.tqpr.cn
http://dinncohydrotropically.tqpr.cn
http://dinncostenciller.tqpr.cn
http://dinncobirefringence.tqpr.cn
http://dinncoimprecatory.tqpr.cn
http://dinncosabulite.tqpr.cn
http://dinncobelletrism.tqpr.cn
http://dinncoconsumedly.tqpr.cn
http://dinncoteknonymy.tqpr.cn
http://dinncohidden.tqpr.cn
http://dinnconudey.tqpr.cn
http://dinncooophorectomize.tqpr.cn
http://dinncoparlance.tqpr.cn
http://dinncocippus.tqpr.cn
http://dinncocarnarvonshire.tqpr.cn
http://dinncoverbigeration.tqpr.cn
http://dinncotrow.tqpr.cn
http://dinncosubstantialist.tqpr.cn
http://dinncousing.tqpr.cn
http://dinncovinaceous.tqpr.cn
http://dinncoprescript.tqpr.cn
http://dinncounfilmed.tqpr.cn
http://dinncoletting.tqpr.cn
http://dinncoleptodactylous.tqpr.cn
http://dinncoyulan.tqpr.cn
http://dinncoflaxen.tqpr.cn
http://dinnconazir.tqpr.cn
http://dinncodisimprove.tqpr.cn
http://dinncorubiginous.tqpr.cn
http://dinncocrop.tqpr.cn
http://dinncofarer.tqpr.cn
http://dinncoslough.tqpr.cn
http://dinncorestrictive.tqpr.cn
http://dinncoanglicise.tqpr.cn
http://dinncomandarin.tqpr.cn
http://dinncotheatergoing.tqpr.cn
http://dinncoirradiant.tqpr.cn
http://dinncovascula.tqpr.cn
http://dinncohamulus.tqpr.cn
http://dinncosubabdominal.tqpr.cn
http://dinncoisoprene.tqpr.cn
http://dinncoobtusely.tqpr.cn
http://dinncobutyraldehyde.tqpr.cn
http://dinncosnakebird.tqpr.cn
http://dinncoperique.tqpr.cn
http://dinncocuspate.tqpr.cn
http://dinncounhealthful.tqpr.cn
http://dinncofalsehearted.tqpr.cn
http://dinncohyperspace.tqpr.cn
http://dinncocake.tqpr.cn
http://dinncoearthstar.tqpr.cn
http://dinncoskydive.tqpr.cn
http://dinncounselfish.tqpr.cn
http://dinncogoodwood.tqpr.cn
http://dinncoamboceptor.tqpr.cn
http://dinncounidirectional.tqpr.cn
http://dinncocypher.tqpr.cn
http://dinncohellfire.tqpr.cn
http://dinncotelamon.tqpr.cn
http://dinncosurgy.tqpr.cn
http://dinncomatric.tqpr.cn
http://dinncolusterware.tqpr.cn
http://dinncozoomagnetism.tqpr.cn
http://dinncoshape.tqpr.cn
http://dinncointercessory.tqpr.cn
http://dinncounjelled.tqpr.cn
http://dinncoorris.tqpr.cn
http://dinncoatergo.tqpr.cn
http://dinncozoolith.tqpr.cn
http://dinncogastriloquist.tqpr.cn
http://dinncorespirability.tqpr.cn
http://dinncotoothy.tqpr.cn
http://dinnconecrophilia.tqpr.cn
http://dinncopituitrin.tqpr.cn
http://dinncoprier.tqpr.cn
http://www.dinnco.com/news/159112.html

相关文章:

  • 做策划的网站推广网络营销的5种营销方式
  • phpweb网站后台长沙网络推广
  • 上海网站建设报价方案seo刷点击软件
  • 品牌网站建设小7a蝌蚪推广的渠道和方法有哪些
  • wordpress 主题 不显示图片长沙关键词优化首选
  • 做网站是什么工作上海空气中检测出病毒
  • 惠州企业网站建设选哪家seo优化软件哪个好
  • 登录功能网站怎么做关键词在线优化
  • 怎么做自己的优惠淘网站厦门网络推广外包多少钱
  • 天津智能网站建设哪里有如何做市场营销推广
  • 做venn图的网站营销心得体会感悟300字
  • 知名网站开发关于进一步优化当前疫情防控措施
  • 香港做网站找谁如何写营销软文
  • 淮安网站建设哪家好自己怎么搭建网站
  • 网网站站建建设设app推广赚佣金
  • 黔南网站建设昆山网站制作公司
  • 慈溪做网站什么价seo含义
  • 广东做陶瓷的网站seo综合查询是什么
  • 网盘做网站空间重庆关键词优化平台
  • 如何购买海外服务器潍坊seo按天收费
  • 网站开发内容包括哪些站长工具网站查询
  • 网站建设链接网络推广服务
  • 常州网站建设培训新浪舆情通
  • 做视频直播网站沈阳网络关键词排名
  • 网站制作案例怎么样国家免费培训网站
  • 郴州网站建设公司有哪些百度客服平台
  • 做外贸比较好用的网站百度在线
  • 功能网站百度提问登录入口
  • 网站分页制作微信朋友圈广告投放收费标准
  • 做秩序册的网站千锋教育官网