How can I transform a GIF to an MP4/WebM? #24
-
Since GIFs are really a bad format to store animated content, because they weigh a ton, is there a way to automatically transform to MP4 or WebM? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Hi @AlejandroAkbal, I've just added support for GIF when using Note that you might want to adjust the default settings of those converters, depending on the actual size and quality of your gif. You can also convert gif at upload time using the transform method like this: use Illuminate\Http\File;
use Spatie\TemporaryDirectory\TemporaryDirectory;
use Spatie\Image\Image;
use Spatie\Image\Enums\Fit;
new MediaCollection(
name: 'files',
transform: function (File $file, TemporaryDirectory $temporaryDirectory): File {
$input = $file->getRealPath();
$output = $temporaryDirectory->path('converted-file.mp4');
$ffmpeg = new FFMpeg;
$ffmpeg->video()->mp4($input, $output)
return new File($output);
}
); |
Beta Was this translation helpful? Give feedback.
-
Just released it in v4.2.0 ! let me know if it works well |
Beta Was this translation helpful? Give feedback.
Hi @AlejandroAkbal,
I've just added support for GIF when using
MediaMp4Converter
andMediaWebmConverter
. You should now be able to convert gif with those converters.Note that you might want to adjust the default settings of those converters, depending on the actual size and quality of your gif.
You can also convert gif at upload time using the transform method like this: