How To Convert A Video File To GIF with PHP

profile picture

How To Convert A Video File To GIF with PHP

First you will need to install the linux package ffmpeg

sudo apt-get install ffmpeg

In your PHP Project, install the php-ffmpeg package

composer require php-ffmpeg/php-ffmpeg

Assuming you have the full local path of the video to convert:

$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);

That's it !! Easy right πŸ˜„

about me

profile picture

I consider myself as an IT Business Artisan. Or Consultant CTO. I'm a self-taught Web Developper, coach and teacher. My main work is helping and guiding digital startups.

more about me

follow me

newsletter

A weekly email with the latests articles

support my work

Start trading on binance
  • BTC

    BTC

    bc1qgw9a8hyqqwvcls9ln7vhql4mad0qkveutr2td7

  • ETH

    ETH

    0x3A720717Da03dB6f3c4a4Ff08BC64100205A79d0

recent posts

DDOS By Web Crawlers

1
1 year ago

Something Given

1
1 year ago

2025 © My Dynamic Production SRL All rights Reserved.