Created
March 6, 2018 00:48
-
-
Save Shaked/98bd85babc56f3b68605c2165dfc8797 to your computer and use it in GitHub Desktop.
PHP-FFMPEG possible ExtractMultipleFramesFilter bug
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 | |
require 'vendor/autoload.php'; | |
use \FFMpeg\Filters\Video\ExtractMultipleFramesFilter; | |
/** | |
* @param $fromUrl | |
*/ | |
function getIGOriginalVideoUrl($fromUrl) { | |
$html = file_get_contents($fromUrl); | |
$doc = new \DOMDocument(); | |
libxml_use_internal_errors(TRUE); //disable libxml errors | |
if ($html) { | |
$doc->loadHTML($html); | |
libxml_clear_errors(); //remove errors for yucky html | |
$xpath = new \DOMXPath($doc); | |
$query = '/html/head/meta[@property="og:video"]/@content'; | |
$row = $xpath->query($query); | |
if ($row->length > 0) { | |
foreach ($row as $row) { | |
return $row->nodeValue; | |
} | |
} | |
} | |
} | |
$url = getIGOriginalVideoUrl('https://www.instagram.com/p/BdmpyJFFPQB/?taken-by=shaked.klein.orbach'); | |
$dir = '/tmp/test_dir'; | |
@mkdir($dir, 0777, true); | |
$ffmpeg = \FFMpeg\FFMpeg::create(); | |
$video = $ffmpeg->open($url); | |
$video | |
->filters() | |
->extractMultipleFrames( | |
ExtractMultipleFramesFilter::FRAMERATE_EVERY_60SEC, | |
$dir | |
) | |
->synchronize(); | |
$path = sprintf('%s/output_%s.png', $dir, '%d'); | |
$format = new \FFMpeg\Format\Video\X264(); | |
$format->on('progress', function ($video, $format, $percentage) { | |
echo 'percentage: ' . $percentage . PHP_EOL; | |
}); | |
$video | |
->save($format, $path); | |
die(PHP_EOL . 'DONE' . PHP_EOL); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment