Electron.js Node.js Remove Audio From Video Desktop App Using FFMPEG Full Project

Electron.js Node.js Remove Audio From Video Desktop App Using FFMPEG Full Project

Hi folks today in this video I will be talking about how to make a desktop app in which we will be removing audio from video using ffmpeg library. We will be using electron and node.js to make this application.

 

So you can see that this is the exact desktop app we will be building in this tutorial. In this app as you can see we have two buttons the first button is the select video button in which we can select the video to be processed and the second button is used to process the video and remove the audio from the video.

 

Practical Video

 

REQUIREMENTS

1) Electron

2) Node.js

3) FFMPEG

 

Initialization of Project

 

npx create-electron-app removeaudio

 

cd removeaudio

 

npm start

 

index.js

 

const { app, BrowserWindow } = require('electron');
const path = require('path');

// Handle creating/removing shortcuts on Windows when installing/uninstalling.
if (require('electron-squirrel-startup')) { // eslint-disable-line global-require
  app.quit();
}

const createWindow = () => {
  // Create the browser window.
  const mainWindow = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences:{
      nodeIntegration:true
    }
  });

  // and load the index.html of the app.
  mainWindow.loadFile(path.join(__dirname, 'index.html'));

  // Open the DevTools.
  //mainWindow.webContents.openDevTools();
};

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', createWindow);

// Quit when all windows are closed.
app.on('window-all-closed', () => {
  // On OS X it is common for applications and their menu bar
  // to stay active until the user quits explicitly with Cmd + Q
  if (process.platform !== 'darwin') {
    app.quit();
  }
});

app.on('activate', () => {
  // On OS X it's common to re-create a window in the app when the
  // dock icon is clicked and there are no other windows open.
  if (BrowserWindow.getAllWindows().length === 0) {
    createWindow();
  }
});

// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and import them here.

 

See also  jQuery Project to Search Tumblr API User Blog Posts & Images & Display it on Website With Pagination in Javascript Full Project For Beginners

index.html

 

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title>Hello World!</title>
    <link
      rel="stylesheet"
      href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css"
    />
    <link rel="stylesheet" href="index.css" />
  </head>
  <body>
    <div class="container">
      <br><br>
      <h1 style="text-align: center;">Remove Audio From Video</h1>
      <label for="filePath" id="filePath"></label>
      <button class="btn btn-block btn-primary" id="upload">Select File</button>

      <hr /><br>

      <button class="btn btn-block btn-danger" id="save">
        Save File and Remove Audio
      </button>
    </div>
  </body>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
  <script src="render.js"></script>
</html>

 

render.js

 

const {remote} = require('electron')
const $ = require('jquery')
const process = require('child_process')
const path = require('path')

const {dialog} = remote
var extname
var inputPath

$("#upload").click(function(){

    dialog.showOpenDialog(null, {
        properties: ['openFile']
      }).then(result => {
        console.log(result.filePaths[0])
        inputPath = result.filePaths[0]
        extname = path.extname(result.filePaths[0])
        $("#filePath").html(result.filePaths[0])
      }).catch(err => {
        console.log(err)
      })
})

$("#save").click(async function(){
    const { filePath } = await dialog.showSaveDialog({
        buttonLabel: 'Save video',
        defaultPath: `vid-${Date.now()}.${extname}`
      });

      console.log(filePath)

      $(this).html("Processing Video")

      $(this).prop("disabled",true)


      process.exec(`ffmpeg -i "${inputPath}" -an ${filePath}`,function(error,stdout, stderr){

        console.log('stdout: ' + stdout);

        $("#save").prop("disabled",false)
        $("#save").html("Save Video and Remove Audio")

        Notification.requestPermission().then(function(result){
            var myNotification = new Notification('Conversion Completed',{
                body:"Your file was successfully converted"
            });
                    
        })
        if (error !== null) {
             console.log('exec error: ' + error);
        }
    
    })
})

 

See also  Login with Google Account using Javascript

DOWNLOAD SOURCE CODE

Leave a Reply