Created
October 26, 2017 11:03
-
-
Save sentenza/c60d94cfb6f5af56afb13a85698ed95e to your computer and use it in GitHub Desktop.
Extract a thumbnail using PHP and FFmpeg
This file contains hidden or 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
<?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