WebRTC 视频轨道到 Node 中的 ffmpeg
WebRTC Video Track to ffmpeg in Node
我已经成功地在节点(服务器)和浏览器之间建立了 WebRTC 连接。服务器在 RTCPeerConnection 中的 onTrack 回调中获取视频轨道。有什么方法可以转换视频轨道并使其在 ffmpeg 上运行,以便我可以将其输出到 rtmp。
提前致谢。
我这样做的方法是使用套接字到节点服务器,然后使用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 服务器:
变量操作=[
'-i','-',
'-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
中的工作示例
我已经成功地在节点(服务器)和浏览器之间建立了 WebRTC 连接。服务器在 RTCPeerConnection 中的 onTrack 回调中获取视频轨道。有什么方法可以转换视频轨道并使其在 ffmpeg 上运行,以便我可以将其输出到 rtmp。
提前致谢。
我这样做的方法是使用套接字到节点服务器,然后使用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 服务器:
变量操作=[ '-i','-',
'-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
中的工作示例