Creating a video from images to the server (PHP)

Hello. There was a task to create a Gif on the server from ordinary images (jpg). The problem was solved using the php library GD, but after that I was faced with the problem of displaying gifok on apple-like devices and, as it seems to me now,the only way out is to create either from the finished gif, or from the frames from which the video gif was created, so that instead of showing this video to the user. How can this be implemented in PHP?

Author: Артем, 2016-07-27

2 answers

Putting ffmpeg on the server

And write the following code

<?php 
  // ниже может быть любая команда на подобие exec, shell_exec и д.р.
  // да и в команду лучше вставить абсолютные пути
  system('ffmpeg -i animation.gif -s 420x300 animation.avi');
  if(file_exist('animation.avi') { 
     // проверяем фаил есть значит безошибок
     // хотя лучше взять вывод систем и проанализировать его на предмет корректной отработки
     echo "gif converted";
  }
 2
Author: Naumov, 2016-07-27 13:36:41

Using the same ffmpeg:

<?
shell_exec("ffmpeg -framerate 0.5 -pattern_type glob -i 'pathToFile/*.jpg' \
  -c:v libx264 -r 30 -pix_fmt yuv420p pathToVideo/result.mp4");
?>

Replace pathToFile with the path in the files,
pathToVideo to the path where to save the video

After - framerate, the frame rate per second is specified (0.5 means showing each frame for 2 seconds)

 0
Author: Denis Rusak, 2019-08-29 06:00:30