쪼렙 as! 풀스택

Node.js - spawn - ffmpeg 이용하여, facebook, Instagram LIVE 에 영상 송출하기. 본문

개발 일지/Web & Server

Node.js - spawn - ffmpeg 이용하여, facebook, Instagram LIVE 에 영상 송출하기.

코코앱 2021. 1. 31. 14:32
function start(streamUrl, streamKey, opt, SOURCE_URL) {
    if (!opt) {
        opt = '-ar 44100 -vcodec libx264 -b:v 3200k -f flv';  //ffmpeg 송출 option
    }

    const target = streamUrl + (streamUrl.charAt(streamUrl.length - 1) === '/' ? '' : '/') + streamKey;

    const argStr = `-re -i ${SOURCE_URL} ${opt} ${target}`
    const command = `ffmpeg ${argStr}`
    const args = argStr.split(' ');

	console.log(command)
    // spawn 을 시작한다.
    const proc = spawn('ffmpeg', args);

    // 이벤트 핸들링
    proc.on('error', function (error) {
        console.error(error)
    })

    proc.stdout.on('data', function (data) {
    	console.log(data)
    })

    proc.stderr.on('data', function (data) {
		console.log(data)
    })

    proc.on('exit', function (code) {
    	console.log('Exit code : ', code)
    })
}
Comments