2024-09-09 Web Development, Programming, Productivity
Convert GIF files to MP4 Videos Using Fluent Ffmpeg
By O Wolfson
In this article I'll outline step-by-step how to up a script that will convert GIF files to MP4 videos using fluent-ffmpeg
. You will understand the code, and know how to run the script.
Gif
Video
Step 1: Setting Up Your Project
1.1 Install Node.js
Ensure that Node.js is installed on your system. If not, download and install it from nodejs.org.
1.2 Create a Project Directory
Create a new directory for your project and navigate into it:
1.3 Initialize the Node.js Project
Run the following command to create a package.json
file:
1.4 Install Dependencies
Install fluent-ffmpeg
and ffmpeg-static
by running:
Make sure that FFmpeg is correctly installed and accessible in your environment's PATH. The ffmpeg-static
package provides an FFmpeg binary that fluent-ffmpeg
can use.
Step 2: Create the Script
2.1 Create the JavaScript File
Create a file named convert.js
:
2.2 Write the Script
Paste the following code into convert.js
:
Step 3: Prepare the Files
3.1 Create Input and Output Directories
3.2 Add GIF Files
Add some GIF files to the _input
directory.
Step 4: Run the Script
Execute the script by running:
This will start the conversion process, where each GIF file in the _input
directory is processed and saved as an MP4 file in the _videos
directory. The script logs the status of each file, indicating whether the conversion was successful or if there were errors.
This tutorial covers the essential aspects of setting up a Node.js project to convert GIF files to MP4 using fluent-ffmpeg
. Adjust the filter and encoding settings in the script as needed to fit your specific requirements.