【问题标题】:WebRTC Video Track to ffmpeg in NodeWebRTC Video Track 到 Node 中的 ffmpeg
【发布时间】:2021-08-03 02:10:56
【问题描述】:

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

提前致谢。

【问题讨论】:

    标签: node.js ffmpeg webrtc video-streaming rtmp


    【解决方案1】:

    我这样做的方式是使用socket到节点服务器,然后使用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 服务器:

    var ops=[ '-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

    以及livestream.a.video 的工作示例

    【讨论】:

      猜你喜欢
      • 2016-05-31
      • 2012-03-11
      • 1970-01-01
      • 2017-05-03
      • 2018-07-15
      • 1970-01-01
      • 2018-05-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多