Whether your video is hosted online or on your machine, for accessibility or analysis, Deepgram can provide accurate transcriptions in just a few lines of code.
I'm glad you're here, but I must confess that I am leading you down a path slightly different to what you would expect. Instead of transcribing video directly, this post will cover converting video files to audio files and then sending them to Deepgram. First, we will transcribe local files, and then we will download files programatically before transcribing them.
Before We Start
You will need:
Node.js installed on your machine - download it here.
A Deepgram API Key - get one here.
A video file to transcribe - here's one you can download and place in your new project directory.
A link to a hosted video file - here is the same video's direct URL.
Create a new directory and navigate to it with your terminal. Run npm init -y to create a package.json file and then install the following packages:
Create an index.js file, and open it in your code editor.
Preparing Dependencies
At the top of your file require these packages:
fs is the built-in file system module for Node.js. It is used to read and write files which you will be doing a few times throughout this post. ffmpeg-static includes a version of ffmpeg in our node_modules directory, and requiring it returns the file path.
Initialize the Deepgram client:
Running ffmpeg Commands
ffmpeg is a toolkit for developers to work with audio and video files - which includes conversion between formats. It's used most commonly in a terminal, so below is a utility function to add to your index.js file. It allows us to fire off terminal commands directly from our Node.js application:
Transcribing Local Video
This function will convert and transcribe local video files:
ffmpeg(`-hide_banner -y -i ${filePath} ${filePath}.wav`) takes in the provided file, and converts it to a .wav audio file. -hide_banner reduces the amount of information printed in the terminal and-y will overwrite an existing file (useful for development).
Save and run the file in your terminal with node index.js and you should see transcripts appear.
Transcribing Remote Video
Add this utility to the bottom of your file:
This allows us to download a file to our machine. The file name will be derived from the last part of the URL - for example https://example.com/directory/directory2/file.mp4 becomes file.mp4 locally.
With this in place, we first download the video and then use our existing transcribeLocalVideo() function:
The complete project is available at https://github.com/deepgram-devs/transcribe-videos and if you have any questions please feel free to reach out on Twitter - we're @DeepgramAI.
Learn more about Deepgram
Sign up for a Deepgram account and get $200 in Free Credit (up to 45,000 minutes), absolutely free. No credit card needed!
We encourage you to explore Deepgram by checking out the following resources:
Unlock language AI at scale with an API call.
Get conversational intelligence with transcription and understanding on the world's best speech AI platform.