Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ////////////////////
- // ENCODING LIBRARY
- ////////////////////
- class Encoding {
- constructor(){
- this.error = null;
- this.in_path = null;
- this.out_path = null;
- this.options = ["-loop 1", "-movflags faststart","-c:v libx264","-crf 21","-preset medium", "-r 30","-c:a aac","-ac 2","-strict -2", "-f mp4", '-af volume=6.0','-map [out]', '-map 1:a'];
- this.input_options = ["-sseof -4"];
- this.debug_mode = false;
- this.backgroundFile = false;
- this.watermarkFile = false;
- }
- logging(value){
- this.debug_mode = value;
- }
- getError(){
- return this.error;
- }
- setPaths(in_path, out_path){
- this.in_path = in_path;
- this.out_path = out_path;
- };
- setOptions(value){
- this.options = value;
- }
- setBackground(backgroundFile){
- this.backgroundFile = backgroundFile;
- }
- setWatermark(watermarkFile){
- this.watermarkFile = watermarkFile;
- }
- async convert(){
- return new Promise((resolve, reject)=>{
- if(this.debug_mode){
- console.log("Starting File Conversion");
- console.log(this.in_path);
- console.log(this.out_path);
- }
- if(this.watermarkFile){
- ffmpeg()
- .input(this.backgroundFile)
- .input(this.in_path)
- .complexFilter([
- "[1]scale=640:480[inner];[0][inner]overlay=0:120:shortest=1[out]"
- ])
- .outputOptions(this.options)
- .saveToFile(this.out_path)
- .on('end', () => {
- if(this.debug_mode){console.log("Conversion Complete");}
- resolve(true);
- })
- .on('error',(err)=>{
- if(this.debug_mode){console.log("Conversion Error");}
- if(this.debug_mode){console.log(err);}
- resolve(err);
- });
- } else {
- ffmpeg()
- .input(this.backgroundFile)
- .input(this.in_path)
- .complexFilter([
- "[1]scale=640:480[inner];[0][inner]overlay=0:120:shortest=1[out]"
- ])
- .outputOptions(this.options)
- .saveToFile(this.out_path)
- .on('end', () => {
- if(this.debug_mode){console.log("Conversion Complete");}
- resolve(true);
- })
- .on('error',(err)=>{
- if(this.debug_mode){console.log("Conversion Error");}
- if(this.debug_mode){console.log(err);}
- resolve(err);
- });
- }
- });
- }
- }
- ////////////////////
- // MAIN FUNCTION
- ////////////////////
- (async()=>{
- let encoder = new Encoding();
- encoder.logging(true);
- encoder.setPaths("./overlay.mp4", "./output.mp4");
- encoder.setWatermark(false);
- encoder.setBackground("./background.png");
- await encoder.convert();
- })();
- ////////////////////
- // FILES
- ////////////////////
- /*
- overlay.mp4 -> https://storage.googleapis.com/clipdrop-prod/videos/test/overlay.mp4
- background.png -> https://storage.googleapis.com/clipdrop-prod/videos/test/background.png
- */
Add Comment
Please, Sign In to add comment