In this tutorial, we are going to make a Video to GIF Converter Tool using PHP and FFMPEG. With the help of this free tool, you can make your own Video to GIF Converter Tool Website.
What is a GIF?
A GIF (short for Graphics Interchange Format) is a type of image file that is widely used on the internet for a variety of purposes. GIFs are often used to display simple, looping animations, or to show a sequence of images that convey a message or tell a story. They are also used as a way to share short, funny or memorable moments from movies, TV shows, and other forms of media. GIFs are typically compressed, making them small in size and easy to share online. They can be viewed on most web browsers and are often used on social media platforms and messaging apps.
What is FFmpeg?
FFmpeg is a free and open-source software project that provides a complete, cross-platform solution for recording, converting, and streaming audio and video. It includes a set of libraries and command-line tools that enable users to record, convert, and stream video and audio files from a variety of sources in various formats.
FFmpeg is commonly used for tasks such as transcoding video and audio files, adding watermarks or logos to videos, creating GIFs, and much more. It can also be used to extract audio from video files, convert audio files to different formats, and more.
FFmpeg is widely used in the media industry and has a large user base among developers, making it a popular choice for building applications that deal with audio and video. It is available for Windows, Mac, and Linux operating systems.
Video to GIF Converter in Localhost
- Download FFMPEG to your Windows or Mac.
- Install FFMPEG to your Windows or Mac. Don’t know how? Click here for Windows and Click here for Mac).
- Create a Folder name “videoconvert” inside “C:\xampp\htdocs\” like “C:\xampp\htdocs\videoconvert”.
- Now open the folder in Visual Studio Code.
- Run the below command in the terminal.
composer require php-ffmpeg/php-ffmpeg
6. Create a new file “index.php” and paste the below code to your file.
<?php
$videoPath = '/path/to/video.mp4';
// The gif duration will be as long as the video/
$ffprobe = FFProbe::create();
$duration = (int) $ffprobe->format($videoPath)->get('duration');
// The gif will have the same dimension. You can change that of course if needed.
$dimensions = $ffprobe->streams($videoPath)->videos()->first()->getDimensions();
$gifPath = '/path/to/gifvideo.gif';
// Transform
$ffmpeg = FFMpeg::create();
$ffmpegVideo = $ffmpeg->open($videoPath);
$ffmpegVideo->gif(TimeCode::fromSeconds(0), $dimensions, $duration)->save($gifPath);
?>
7. Now run your project to your server.
Video to GIF Converter in Ubuntu Server
- Update your server using the below command.
sudo apt update
2. Install FFmpeg to your server using the below command.
sudo apt install ffmpeg
ffmpeg -version
3. Run the below command in your root directory.
composer require php-ffmpeg/php-ffmpeg
4. Look at the (6th) point above.
5. Run your IP or domain.
Congratulation! You successfully made your own Video to Gif Converter PHP Tool.
Download the complete project for free.