diff --git a/src/controller.ts b/src/controller.ts index c87f0c9..6170a7d 100644 --- a/src/controller.ts +++ b/src/controller.ts @@ -53,8 +53,8 @@ async function run() { api: config.server.api, api_user: config.server.api_user, api_pass: config.server.api_pass - } - + }, + transcode: config.transcode }; db.init(dbcfg, bcryptcfg); await cleanup.init(); diff --git a/src/server.ts b/src/server.ts index 62d8a8d..0f0b0cf 100644 --- a/src/server.ts +++ b/src/server.ts @@ -34,14 +34,14 @@ function init (mediaconfig: any, satyrconfig: any) { //otherwise kill the session db.query('select username,record_flag from users where stream_key='+db.raw.escape(key)+' limit 1').then(async (results) => { if(results[0]){ - //push to rtmp - //execFile(satyrconfig.ffmpeg, ['-loglevel', 'fatal', '-analyzeduration', '0', '-i', 'rtmp://127.0.0.1:'+mediaconfig.rtmp.port+'/'+satyrconfig.privateEndpoint+'/'+key, '-vcodec', 'copy', '-acodec', 'copy', '-crf', '18', '-f', 'flv', 'rtmp://127.0.0.1:'+mediaconfig.rtmp.port+'/'+satyrconfig.publicEndpoint+'/'+results[0].username], {maxBuffer: Infinity}); - //push to mpd after making sure directory exists + //transcode to mpd after making sure directory exists keystore[results[0].username] = key; mkdir(satyrconfig.directory+'/'+satyrconfig.publicEndpoint+'/'+results[0].username, { recursive : true }, ()=>{;}); while(true){ if(session.audioCodec !== 0 && session.videoCodec !== 0){ - execFile(satyrconfig.ffmpeg, ['-loglevel', 'fatal', '-y', '-i', 'rtmp://127.0.0.1:'+mediaconfig.rtmp.port+'/'+satyrconfig.privateEndpoint+'/'+key, '-map', '0:2', '-map', '0:2', '-map', '0:2', '-map', '0:1', '-c:a', 'copy', '-c:v:0', 'copy', '-c:v:1', 'libx264', '-c:v:2', 'libx264', '-crf:1', '33', '-crf:2', '40', '-b:v:1', '3000K', '-b:v:2', '1500K', '-remove_at_exit', '1', '-seg_duration', '1', '-window_size', '30', '-f', 'dash', satyrconfig.directory+'/'+satyrconfig.publicEndpoint+'/'+results[0].username+'/index.mpd'], {maxBuffer: Infinity}); + transCommand(mediaconfig, satyrconfig, results[0].username, key).then((r) => { + execFile(satyrconfig.ffmpeg, r, {maxBuffer: Infinity}); + }); break; } await sleep(300); @@ -109,4 +109,33 @@ function init (mediaconfig: any, satyrconfig: any) { } }); } + +async function transCommand(config: object, satyrconfig: object, user: string, key: string): Promise{ + let args: string[] = ['-loglevel', 'fatal', '-y', '-i', 'rtmp://127.0.0.1:'+config['rtmp']['port']+'/'+satyrconfig['privateEndpoint']+'/'+key]; + if(config['transcode']['adaptive']===true && config['transcode']['variants'] > 1) { + for(let i=0;i 51 ? 51 : Math.floor(18 + (i * 7)); + args = args.concat(['-crf:'+i, ''+crf]); + } + for(let i=1;i