Tuesday, 16 September 2014

In this blog, you will learn how to extract MP3 file from any video.

The following  are required to achieve this.

a) node.js - version 0.10.29
b) fluent-ffmpeg - version 1.7.1
c) ffmpeg library on Ubuntu.

Step 1

Ensure that ffmpeg library is installed on Ubuntu 12.04 or higher. I have used ffmpeg from 

Jon Severinsson's FFmpeg PPA for ubuntu


ensure that you are able to execute following commands on terminal and get proper output

a) ffmpeg
b) ffprobe

Step 2

install node.js on ubuntu 12.04 or higher. Avoid to install any pre-release version of node.js

sudo apt-get install software-properties-common
sudo apt-get install python-software-properties python g++ make
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs

Step 3

install fluent-ffmpeg module using following command

npm install fluent-ffmpeg@1.7.1


Save the following script in a .js file and run

node <filename>

var FFmpeg = require('fluent-ffmpeg');
var datetime = new Date();

var conversion_process = new FFmpeg({ source: "test.webm", timeout:0})
.withAudioCodec('libmp3lame')
.withAudioBitrate(128)
.withAudioChannels(2)
.withAudioFrequency(44100)
.withAudioQuality(5)
.toFormat('mp3')
.on('start', function(commandLine) {
console.log(datetime + " DEBUG: " + "Audio Extraction Started");
})
.on('error', function(err, stdout, stderr) {
console.log(datetime + " DEBUG: " + "Audio Extraction Failed.");
console.log(err);

})
.on('progress', function(progress) {
console.log(datetime + " DEBUG: " + "Audio Extraction Percentage ..." + progress.percent);
})
.on('end', function() {
console.log(datetime + " DEBUG: " + "Audio Extraction Ended");
})
.saveToFile("test.mp3");

Step 4

You can do lot of improvisations with the configuration / Callback functions is above script


What's Next

Well, you can install audiowaveform in ubuntu from the following link.

URL : https://github.com/bbcrd/audiowaveform

and generate audio waveform from the MP3 file you have extracted.



Enjoy coding in node.js

No comments:

Post a Comment