Skip to content

Instantly share code, notes, and snippets.

@hpez
Last active March 30, 2018 16:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hpez/419a422d8ce30eea76eec8b0e349d786 to your computer and use it in GitHub Desktop.
Save hpez/419a422d8ce30eea76eec8b0e349d786 to your computer and use it in GitHub Desktop.
Give it an array of addresses to image files, it turns them into a video and returns the address to that using FFMPEG
function pic2vid($picAddresses)
{
$prefix = uniqid("app"); //A prefix for temp files
foreach ($picAddresses as $key => $picAddress) {
copy($picAddress, sys_get_temp_dir() . '/' . $prefix . sprintf('%03d', $key + 1) . '.png');
if ($key == count($picAddresses) - 1)
copy($picAddress, sys_get_temp_dir() . '/' . $prefix . sprintf('%03d', $key + 2) . '.png');
}
$filename = uniqid();
shell_exec("/usr/local/bin/ffmpeg -framerate 0.5 -i " . sys_get_temp_dir() . '/' . $prefix . "%03d.png -c:v libx264 -vf fps=25 -pix_fmt yuv420p " . sys_get_temp_dir() . '/' . $filename . ".mp4 2>&1");
return sys_get_temp_dir() . '/' . $filename . ".mp4";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment