我试图使用一个节点模块来在网站上播放视频。模块名为node-media-server。目前,我已经设置它工作时,从obs的实时源,它的工作很好。我不知道的是如何流一个固定的h.264视频。npm文档说要使用FFMPEG,但这让我搞不懂这到底意味着什么。如何使用ffmpeg将固定视频发布到节点媒体服务器?如何在其npm文档中的“发布实况流”一节中提到。你能不能帮我理解一下,在这里,ffmpeg会派上什么用场?提前谢谢。
发布于 2022-09-22 09:40:18
我使用fluent-ffmpeg从节点js运行ffmpeg命令,它可以工作。
const fs = require('fs');
const path = require('path')
const ffmpegPath = require('@ffmpeg-installer/ffmpeg').path;
const fluent = require('fluent-ffmpeg');
fluent.setFfmpegPath(ffmpegPath);
const executeFfmpeg = args => {
let command = fluent().output(' '); // pass "Invalid output" validation
command._outputs[0].isFile = false; // disable adding "-y" argument
command._outputs[0].target = ""; // bypass "Unable to find a suitable output format for ' '"
command._global.get = () => { // append custom arguments
return typeof args === "string" ? args.split(' ') : args;
};
return command;
};
executeFfmpeg(`ffmpeg -re -i INPUT_FILE_NAME -c copy -f flv rtmp://localhost/live/STREAM_NAME`)
.on('start', commandLine => console.log('start', commandLine))
.on('codecData', codecData => console.log('codecData', codecData))
.on('error', error => console.log('error', error))
.on('stderr', stderr => console.log('stderr', stderr))
.run();
https://stackoverflow.com/questions/73810919
复制相似问题