Last active
March 30, 2018 16:17
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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