-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
26ea153
commit 0d25ba9
Showing
4 changed files
with
170 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# audio-cutter | ||
|
||
Cut a random sample of the specified length from anywhere with Options | ||
|
||
# Variable Usage | ||
``` | ||
inputPath - Path of Sample file. | ||
outputPath - Path of output. | ||
seconds - Amount of Time for which sample has be cut. | ||
fadeInOut - Bool - true or false. | ||
fadeInOutTime - Time to fade out - Current = second - 1. i.e. fadeout will start 1 second before ending the file. | ||
setStartTime - Time from where cut has to start. | ||
``` | ||
# Steps | ||
|
||
``` | ||
1. npm install | ||
2. node app.js | ||
``` |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
const ffmpegPath = require('@ffmpeg-installer/ffmpeg').path; | ||
const ffmpeg = require('fluent-ffmpeg'); | ||
const fs = require('fs'); | ||
const inputPath = 'art_of_war_01-02_sun_tzu.ogg'; //Input file Path with Extension | ||
const outputPath = 'output.mp3'; //Output File Path with Extension | ||
const seconds = 300; //Trim Time in seconds | ||
const fadeInOut = true; | ||
let fadeInOutTime = seconds - 1; | ||
const setStartTime = 0; // Start Time | ||
ffmpeg.setFfmpegPath(ffmpegPath); | ||
let audioFilters = []; // Initilizing the Filter | ||
const convert = new ffmpeg({ source: inputPath }); | ||
|
||
// Conversion of Audio with different options. | ||
try { | ||
// Check if File Exist or Not | ||
if (fs.existsSync(inputPath)) { | ||
//Work if fadeInOut is true. | ||
if (fadeInOut) { | ||
audioFilters = [ | ||
{ | ||
filter: 'afade', | ||
options: 't=out:st=' + fadeInOutTime + ':d=1' | ||
} | ||
]; | ||
} else { | ||
audioFilters = []; | ||
} | ||
// Convert the audio with functionality and output the new File. | ||
convert | ||
.setStartTime(setStartTime) //Can be in "HH:MM:SS" format also | ||
.setDuration(seconds) | ||
.audioFilters(audioFilters) | ||
.on('start', function(command) { | ||
console.log('Actual command Executed: ' + command); | ||
}) | ||
.on('error', function(err) { | ||
console.log('error: ', +err); | ||
}) | ||
.on('end', function(err) { | ||
if (!err) { | ||
console.log('conversion Done and file saved at: ', outputPath); | ||
} | ||
}) | ||
.saveToFile(outputPath); | ||
} else { | ||
throw "File Doesn't Exist"; | ||
} | ||
} catch (err) { | ||
console.error(err); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"name": "audio-cutter", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "app.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "Cloudtub", | ||
"license": "ISC", | ||
"dependencies": { | ||
"@ffmpeg-installer/ffmpeg": "^1.0.17", | ||
"fluent-ffmpeg": "^2.1.2" | ||
} | ||
} |