How to Transcode Audio & Video Files with FFmpeg in JavaScript
Converts digital-to-digital multimedia file formats. Local FFmpeg.wasm in-browser. Demo & full source code available.
--
Digital technology has greatly transformed the traditional notetaking process. Not only is information being recorded as handwritten text/handrawn diagrams but also in auditory and visual formats.
Rationale for Side Project
While auditory data is widely praised for its convenience and reliability (e.g. Note-Taking at Meetings or Customer Sentiment Analysis at Call Centres), the fact remains that many Speech-to-Text APIs such as Google Cloud and Amazon’s Transcribe Service supports only a few specific audio encodings*.
[*] List of supported formats by Google Cloud and AWS
As such, this has led me to explore the use of FFmpeg, an open-sourced utility to convert media files from one format to another. In particular, I chose to implement FFmpeg.wasm*, a JavaScript port built with WebAssembly in order to maximise portability and minimise installations required.
[*] Credits to Jerome Wu, the co-creator/maintainer of FFmpeg.wasm
Use Case: Transcode Audio from .wma → .mp3
For simplicity, a use-case demo shall be done via an in-browser setup of FFmpeg.wasm hosted on a local Express NodeJS server. As such, implementation shall be split into 2 parts — Part I: Server setup & Part II: Import FFmpeg.wasm into browser
Part I. Setting up NodeJS Express Server — 3 Steps
Step 1. Create an empty directory (e.g. FFmpegWasmExpressServer
) and proceed to run the following in your terminal (this creates package.json
):
cd FFmpegWasmExpressServer
npm init -y