node.js @ffmpeg-installer/ffmpeg 桌面推流

//安装
npm install --save @ffmpeg-installer/ffmpeg

//stream.js

// 引入所需模块

const ffmpeg = require('@ffmpeg-installer/ffmpeg');

const { exec } = require('child_process');

// 设置 FFmpeg 路径

const ffmpegPath = ffmpeg.path;

const rtmpUrl = "rtmp://localhost:1935/live/desktop";

// 使用 FFmpeg 进行视频转换

exec(`{ffmpegPath} -f gdigrab -i desktop -vcodec libx264 -preset:v ultrafast -tune:v zerolatency -f flv -pix_fmt yuv420p {rtmpUrl}`, (error, stdout, stderr) => {

if (error) {

console.error(`执行错误: ${error.message}`);

return;

}

if (stderr) {

console.error(`错误信息: ${stderr}`);

return;

}

console.log(`输出信息: ${stdout}`);

});

//运行
node stream.js

//参考

https://npm.io/package/@ffmpeg-installer/ffmpeg

相关推荐
东方小月4 小时前
从零开发一个 Coding Agent(九):实现 Agent 的工具调用闭环
人工智能·前端框架·node.js
王八八。19 小时前
nvm 安装与配置完全指南:从零到多版本 Node.js 自由切换
node.js
紫禁玄科20 小时前
Shai-Hulud:npm生态的自我复制蠕虫风暴
前端·npm·node.js
烂蜻蜓1 天前
Node.js入门教程(十四):async/await
node.js
程序员老陆1 天前
说一说FFmpeg6在Linux平台的编译
linux·运维·服务器·ffmpeg
用户518186005661 天前
FFmpeg 剪辑:为什么 `-c copy` 往往做不到帧准确剪切
ffmpeg
福大大架构师每日一题1 天前
mediamtx v1.19.3正式发布:认证安全、WebRTC跨域、MoQ稳定性、RTSP与HLS全面升级
安全·ffmpeg·webrtc
cpp_learner2 天前
FFmpeg 解复用全流程解析
ffmpeg
程序员老陆2 天前
FFmpeg时间基相关函数大杂烩
ffmpeg·时间基·timebase
谢小飞3 天前
大文件上传很难?学会这招,GB文件秒传不是梦
前端·node.js