Richienb / webm-to-mp4

Convert a webm video to mp4.
MIT License
39 stars 4 forks source link

Support audio-only #1

Open tfsjohan opened 3 years ago

tfsjohan commented 3 years ago

Can I use this to convert webm audio file to a audio mp4 file? Don't need video, just audio.

Richienb commented 3 years ago

It didn't know that mp4 was an audio format - I have no idea if it will work.

oscarguinane commented 3 years ago

You can apt install ffmpeg and run the following code below in NodeJS.

const exec = require( 'child_process' ).exec;

function convertWebmToMP4 ( filePath ) {
  exec( 
    `ffmpeg -i "${ filePath }" "${ filePath.replace( /.webm/, '.mp4' ) }"`, 
    function( error, stdout, stderr ) {
      if ( error )
        console.error( `Got an error trying to convert the file: ${ error }` );
      else
        console.log( stdout );
    } 
  );
}

convertWebmToMP4( `${ process.env.PWD }/tmp/file.webm` );

( Tested in NodeJS 14.13.1 )

Richienb commented 3 years ago

Accepting a PR to conditionally add -vn (skip inclusion of video flag) when an option is passed.