Skip to content

Instantly share code, notes, and snippets.

@sentenza
Created October 26, 2017 11:03
Show Gist options
  • Save sentenza/c60d94cfb6f5af56afb13a85698ed95e to your computer and use it in GitHub Desktop.
Save sentenza/c60d94cfb6f5af56afb13a85698ed95e to your computer and use it in GitHub Desktop.
Extract a thumbnail using PHP and FFmpeg
<?php
class Extract {
const FFMPEG_PATH = '/usr/bin/ffmpeg';
public function exec($psSource, $psDest) {
$aOutput = [];
$aError = null;
$sCommand = sprintf("%s -i %s -vframes 1 %s 2>&1", self::FFMPEG_PATH, $psSource, $psDest);
echo 'Executing: ' . $sCommand;
exec($sCommand, $aOutput, $aError);
print_r('Output: ' . implode("\n", $aOutput));
print_r($aError);
if (!file_exists($psDest) || filesize($psDest) == 0) {
echo 'Video export format generation failed!';
}
}
}
$oExtract = new Extract();
$oExtract->exec('./test.mp4', './out.jpg');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment