-
-
Save kurokikaze/0ad526ee2bebc006776e to your computer and use it in GitHub Desktop.
Simple Node.js FFMPEG interface
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var sys = require('sys'), | |
child_process = require('child_process'); | |
var encoder = child_process.spawn('ffmpeg',['-i', "video.mkv", '-s', '300x200', '-f', 'avi', '-vcodec', 'mpeg4', 'video.avi']); | |
var total_time = 0; | |
var total_data = '' | |
encoder.stderr.addListener('data', function(data) { | |
if (data) { | |
total_data += data.toString(); | |
if (total_data.toString().match(/Duration:\s\d\d:\d\d:\d\d\.\d\d/)) { | |
var time = total_data.toString().match(/Duration:\s(\d\d:\d\d:\d\d\.\d\d)/).toString().substring(10,21); | |
sys.puts('DATA:' + total_data.toString()); | |
sys.puts('Time:' + time); | |
var seconds = parseInt(time.substr(0,2))*3600 + parseInt(time.substr(3,2))*60 + parseInt(time.substr(6,2)); | |
total_data = ''; | |
total_time = seconds; | |
sys.puts('sec: ' + seconds); | |
} | |
// sys.puts('>' + data.toString()); | |
// sys.puts(data.toString().substr(data.toString().length - 6, 5)); | |
if (data.toString().substr(data.toString().length - 6,5) == '[y/N]') { | |
sys.puts('File already exist, overwriting'); | |
encoder.stdin.write('Y', 'ascii'); | |
} | |
if (data.toString().substr(0,5) == 'frame') { | |
var time = parseInt(data.toString().match(/time=\s*(\d*)\.\d*/)[0].toString().substr(5)); | |
sys.puts('Percent done: ' + ((time / total_time) * 100) + '% (' + time + ' of ' + total_time); | |
} | |
} | |
//sys.puts('OUT:'+ data); | |
}); | |
encoder.stderr.addListener('exit', function(data) { | |
sys.puts('Encoding done: ' + data); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment