Skip to content

Instantly share code, notes, and snippets.

@nicklasos
Last active December 27, 2015 13:59
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 nicklasos/7337140 to your computer and use it in GitHub Desktop.
Save nicklasos/7337140 to your computer and use it in GitHub Desktop.
FFMPG + Video functions
<?php
/**
* Compile video from images with FFMPG
*
* @param string $tmpDirWithImages
* @param string $ext jpg|png...
* @param string $videoFilePath
*/
function compileVideo($tmpDirWithImages, $ext, $videoFilePath)
{
$command =
"/usr/local/bin/ffmpeg ".
"-i {$tmpDirWithImages}%5d.{$ext} ".
"-vf 'split [a], pad=iw*2:ih [b], [a] alphaextract, [b] overlay=w' ".
"-qmin 0 ".
"-qmax 39 ".
"-y {$videoFilePath}"; system($command);
}
/**
* Get the dimensions of a video file
*
* @param string $video path
* @return bool|array(width,height)
* @author Jamie Scott
*/
public function getVideoDimensions($video)
{
if (!file_exists($video)) {
return false;
}
$command = 'ffmpeg -i ' . $video . ' -vstats 2>&1';
$output = shell_exec($command);
preg_match('/[0-9]?[0-9][0-9][0-9]x[0-9][0-9][0-9][0-9]?/', $output, $regs);
if (!isset($argc[0])) {
return false;
}
$vals = explode('x', $regs [0]);
$width = $vals[0] ? $vals[0] : null;
$height = $vals[1] ? $vals[1] : null;
return ['width' => $width, 'height' => $height];
}
/**
* Generate thumb from video file
* @param string $videoFilePath
* @param string $thumbPath
*/
function generateThumbnail($videoFilePath, $thumbPath)
{
shell_exec(escapeshellcmd("ffmpeg -i {$videoFilePath} -r 1 -f image2 -vframes 1 -s 100x100 -an {$thumbPath}"));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment