gpt4 book ai didi

node.js - WebRTC Video Track 到 Node 中的 ffmpeg

转载 作者:行者123 更新时间:2023-12-04 23:20:34 29 4
gpt4 key购买 nike

我已经成功地在 Node(服务器)和浏览器之间建立了 WebRTC 连接。服务器获取 上的视频轨道在轨 RTCPeerConnection 内部的回调。有什么方法可以潜在地转换视频轨道并使其在 ffmpeg 上运行,以便我可以将其输出到 rtmp。
提前致谢。

最佳答案

我这样做的方式是使用到 Node 服务器的套接字,然后使用 ffmpeg 转换为 RTMP:
我产生 FFMPEG

var spawn = require('child_process').spawn;
spawn('ffmpeg',['-h']).on('error',function(m){
console.error("FFMpeg not found in system cli; please install ffmpeg properly or make a softlink to ./!");
process.exit(-1);
});
我确保我从套接字获取视频,然后将其通过管道传输到 FFMPEG 并输出到我的 RTMP 服务器:
变量操作= [
'-一世','-',
        '-c:v', 'libx264', '-preset', 'ultrafast', '-tune', 'zerolatency',  // video codec config: low latency, adaptive bitrate
'-c:a', 'aac', '-ar', audioBitrate, '-b:a', audioEncoding, // audio codec config: sampling frequency (11025, 22050, 44100), bitrate 64 kbits
//'-max_muxing_queue_size', '4000',
//'-y', //force to overwrite
//'-use_wallclock_as_timestamps', '1', // used for audio sync
//'-async', '1', // used for audio sync
//'-filter_complex', 'aresample=44100', // resample audio to 44100Hz, needed if input is not 44100
//'-strict', 'experimental',
'-bufsize', '5000',

'-f', 'flv', socket._rtmpDestination


];
}
console.log("ops", ops);
console.log(socket._rtmpDestination);
ffmpeg_process=spawn('ffmpeg', ops);
console.log("ffmpeg spawned");
你可以看到我的代码: https://github.com/dougsillars/browserLiveStream/blob/master/server.js
livestream.a.video 的工作示例

关于node.js - WebRTC Video Track 到 Node 中的 ffmpeg,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67508284/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com