ffmpeg -hide_banner -y -i beach.mkv \
-vf scale=w=640:h=360:force_original_aspect_ratio=decrease -c:a aac -ar 48000 -c:v h264 -profile:v main -crf 20 -sc_threshold 0 -g 48 -keyint_min 48 -hls_time 4 -hls_playlist_type vod -b:v 800k -maxrate 856k -bufsize 1200k -b:a 96k -hls_segment_filename beach/360p_%03d.ts beach/360p.m3u8 \
-vf scale=w=842:h=480:force_original_aspect_ratio=decrease -c:a aac -ar 48000 -c:v h264 -profile:v main -crf 20 -sc_threshold 0 -g 48 -keyint_min 48 -hls_time 4 -hls_playlist_type vod -b:v 1400k -maxrate 1498k -bufsize 2100k -b:a 128k -hls_segment_filename beach/480p_%03d.ts beach/480p.m3u8 \
-vf scale=w=1280:h=720:force_original_aspect_ratio=decrease -c:a aac -ar 48000 -c:v h264 -profile:v main -crf 20 -sc_threshold 0 -g 48 -keyint_min 48 -hls_time 4 -hls_playlist_type vod -b:v 2800k -maxrate 2996k -bufsize 4200k -b:a 128k -hls_segment_filename beach/720p_%03d.ts beach/720p.m3u8 \
-vf scale=w=1920:h=1080:force_original_aspect_ratio=decrease -c:a aac -ar 48000 -c:v h264 -profile:v main -crf 20 -sc_threshold 0 -g 48 -keyint_min 48 -hls_time 4 -hls_playlist_type vod -b:v 5000k -maxrate 5350k -bufsize 7500k -b:a 192k -hls_segment_filename beach/1080p_%03d.ts beach/1080p.m3u8
Convert this command to fluent-ffmpeg node js:
My Code:
let ffmpeg = require('fluent-ffmpeg');
new ffmpeg()
.addInput('./public/class.mp4')
.outputOptions([
'-map 0:v',
'-map 0:v',
'-map 0:a',
'-map 0:a',
'-s:v:0 426x240',
'-c:v:0 libx264',
'-b:v:0 400k',
'-c:a:0 aac',
'-b:a:0 64k',
'-s:v:1 640x360',
'-c:v:1 libx264',
'-b:v:1 700k',
'-c:a:1 aac',
'-b:a:1 96k',
//'-var_stream_map', '"v:0,a:0 v:1,a:1"',
'-master_pl_name playlist.m3u8',
'-f hls',
'-max_muxing_queue_size 1024',
'-hls_time 4',
'-hls_playlist_type vod',
'-hls_list_size 0',
'-hls_segment_filename ./public/output/v%v/segment%03d.ts'
])
.output('./public/output/v%v/master.m3u8')
.on('start', function (commandLine) {
console.log('Spawned Ffmpeg with command: ' + commandLine);
res.write('<p>' + commandLine + '</p>');
})
.on('error', function (err, stdout, stderr) {
console.error('An error occurred: ' + err.message, err, stderr);
res.write('<p>' + err.message + '</p>');
})
.on('progress', function (progress) {
console.log('Processing: ' + progress.percent + '% done');
console.log(progress);
/*percent = progress.percent;
res.write('<h1>' + percent + '</h1>');*/
})
.on('end', function (err, stdout, stderr) {
console.log('Finished processing!' /*, err, stdout, stderr*/);
res.write('Finished processing!');
})
.run();
This code generate only one bitrate .m3u8 stream.
I have tried many ways to generate multi bitrate hls stream through node js but always generate single bitrate. i have tried bash command and that was work fine, now i want to convert this command to nodejs script.
Is any one have idea about this?
-var_stream_map
than it gives me error (Error: undefine v:1,a:1). and if I comment than it out only one bitrate segment stream. – Vinay Vadachhak Dec 17 '20 at 12:45