javascript - video to audio file convert & save through FFMPEG in node js -
i working on ffmpeg on node js. i'd retrieve audio track video file using node js. save such file can't figure out how.
i though line of code me :
ffmpeg('/path/to/file.avi').novideo(); i have got in npm package. don't quite understand how work , how save audio file.
some other line of code come in play :
try { var process = new ffmpeg('/path/to/your_movie.avi'); process.then(function (video) { // callback mode video.fnextractsoundtomp3('/path/to/your_audio_file.mp3', function (error, file) { if (!error) console.log('audio file: ' + file); }); }, function (err) { console.log('error: ' + err); }); } catch (e) { console.log(e.code); console.log(e.msg); } my question is:
how retrieve audio ffmpeg video ? how save ?
i like:
var ffmpeg = require('fluent-ffmpeg'); /** * input - string, path of input file * output - string, path of output file * callback - function, node-style callback fn (error, result) */ function convert(input, output, callback) { ffmpeg(input) .output(output) .on('end', function() { console.log('conversion ended'); callback(null); }).on('error', function(err){ console.log('error: ', e.code, e.msg); callback(err); }).run(); } convert('./df.mp4', './output.mp3', function(err){ if(!err) { console.log('conversion complete'); //... } }); just make sure ffmpeg installed , part of system path, make sure necessary codes present.
update:
for video without audio, .noaudio().videocodec('copy'):
function copywitoutaudio(input, output, callback) { ffmpeg(input) .output(output) .noaudio().videocodec('copy') .on('end', function() { console.log('conversion ended'); callback(null); }).on('error', function(err){ console.log('error: ', err); callback(err); }).run(); } update 2:
for merging video , audio single:
function mergemedia(aud, vid, output, callback) { ffmpeg() .input(aud) .input(vid) .output(output) .outputoptions( '-strict', '-2', '-map', '0:0', '-map', '1:0' ).on('end', function() { console.log('conversion ended'); callback(null); }).on('error', function(err){ console.log('error: ', err); callback(err); }).run(); }
Comments
Post a Comment