|
|
|
@ -42,9 +42,10 @@ function init () { |
|
|
|
|
if(session.audioCodec !== 0 && session.videoCodec !== 0){ |
|
|
|
|
transCommand(results[0].username, key).then((r) => { |
|
|
|
|
execFile(config['media']['ffmpeg'], r, {maxBuffer: Infinity}, (err, stdout, stderr) => { |
|
|
|
|
/*console.log(err); |
|
|
|
|
console.log(stdout); |
|
|
|
|
console.log(stderr);*/ |
|
|
|
|
//console.log(r);
|
|
|
|
|
//console.log(err);
|
|
|
|
|
//console.log(stdout);
|
|
|
|
|
//console.log(stderr);
|
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
break; |
|
|
|
@ -126,29 +127,49 @@ function init () { |
|
|
|
|
|
|
|
|
|
async function transCommand(user: string, key: string): Promise<string[]>{ |
|
|
|
|
let args: string[] = ['-loglevel', 'fatal', '-y']; |
|
|
|
|
let vcodec: string = 'libx264'; |
|
|
|
|
if(config['hwaccel']['type'] === 'nvenc'){ |
|
|
|
|
vcodec = 'h264_nvenc'; |
|
|
|
|
if(config['hwaccel']['decode']){ |
|
|
|
|
args = args.concat(['-hwaccel', 'cuda']); |
|
|
|
|
if(config['hwaccel']['device']) |
|
|
|
|
args = args.concat(['-hwaccel_device', config['hwaccel']['device']]); |
|
|
|
|
args = args.concat(['-hwaccel_output_format', 'cuda']); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else if (config['hwaccel']['type'] === 'vaapi') { |
|
|
|
|
vcodec = 'h264_vaapi'; |
|
|
|
|
if(config['hwaccel']['decode'] === 'fallback'){ |
|
|
|
|
args = args.concat('init_hw_device', 'vaapi=foo:'+config['hwaccel']['device'], '-hwaccel vaapi', '-hwaccel_output_format', 'vaapi', '-hwaccel_device', 'foo'); |
|
|
|
|
} else if (config['hwaccel']['decode']) { |
|
|
|
|
args = args.concat(['-hwaccel', 'vaapi', '-hwaccel_output_format', 'vaapi', '-vaapi_device', config['hwaccel']['device']]); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if(config['transcode']['inputflags'] !== null && config['transcode']['inputflags'] !== "") args = args.concat(config['transcode']['inputflags'].split(" ")); |
|
|
|
|
args = args.concat(['-i', 'rtmp://127.0.0.1:'+config['rtmp']['port']+'/'+config['media']['privateEndpoint']+'/'+key, '-movflags', '+faststart']); |
|
|
|
|
if(config['transcode']['adaptive']===true && config['transcode']['variants'] > 1) { |
|
|
|
|
for(let i=0;i<config['transcode']['variants'];i++){ |
|
|
|
|
args = args.concat(['-map', '0:2']); |
|
|
|
|
} |
|
|
|
|
args = args.concat(['-map', '0:1', '-c:a', 'aac', '-c:v:0', 'libx264']); |
|
|
|
|
args = args.concat(['-map', '0:1', '-c:a', 'aac', '-c:v:0', vcodec]); |
|
|
|
|
for(let i=1;i<config['transcode']['variants'];i++){ |
|
|
|
|
args = args.concat(['-c:v:'+i, 'libx264',]); |
|
|
|
|
args = args.concat(['-c:v:'+i, vcodec,]); |
|
|
|
|
} |
|
|
|
|
for(let i=1;i<config['transcode']['variants'];i++){ |
|
|
|
|
let crf: number = Math.floor(18 + (i * 8)) > 51 ? 51 : Math.floor(18 + (i * 7)); |
|
|
|
|
args = args.concat(['-crf:'+i, ''+crf]); |
|
|
|
|
} |
|
|
|
|
for(let i=1;i<config['transcode']['variants'];i++){ |
|
|
|
|
let bv: number = Math.floor((5000 / config['transcode']['variants']) * (config['transcode']['variants'] - i)); |
|
|
|
|
let bv: number = Math.floor((10000 / config['transcode']['variants']) * (config['transcode']['variants'] - i)); |
|
|
|
|
args = args.concat(['-b:v:'+i, ''+bv]); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
args = args.concat(['-c:a', 'aac', '-c:v', 'libx264']); |
|
|
|
|
args = args.concat(['-c:a', 'aac', '-c:v', vcodec]); |
|
|
|
|
} |
|
|
|
|
args = args.concat(['-preset', 'veryfast', '-tune', 'zerolatency']); |
|
|
|
|
if(!config['hwaccel']['type']) |
|
|
|
|
args = args.concat(['-preset', 'veryfast']); |
|
|
|
|
args = args.concat(['-tune', 'zerolatency']); |
|
|
|
|
//if(config['transcode']['format'] === 'dash')
|
|
|
|
|
args = args.concat(['-remove_at_exit', '1', '-seg_duration', '1', '-window_size', '30']); |
|
|
|
|
if(config['transcode']['outputflags'] !== null && config['transcode']['outputflags'] !== "") args = args.concat(config['transcode']['outputflags'].split(" ")); |
|
|
|
|