From 2c265fa70244f659be26128c2ba9c9c131668ed4 Mon Sep 17 00:00:00 2001 From: flashwave Date: Wed, 23 Oct 2024 19:51:01 +0000 Subject: [PATCH] Fix: the IO namespace doesn't exist anymore :) --- src/FFMPEG.php | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/FFMPEG.php b/src/FFMPEG.php index fa639fd..e310cf8 100644 --- a/src/FFMPEG.php +++ b/src/FFMPEG.php @@ -4,23 +4,26 @@ namespace Uiharu; use stdClass; use Imagick; use RuntimeException; -use Index\IO\Stream; -use Index\IO\ProcessStream; final class FFMPEG { - public static function grabFirstVideoFrame(string $url): Stream { - return new ProcessStream( - sprintf('ffmpeg -i %s -ss 00:00:00.000 -vframes 1 -c:v png -f image2pipe -', escapeshellarg($url)), - 'rb' - ); + public static function grabFirstVideoFrame(string $url): string { + try { + $file = popen(sprintf('ffmpeg -i %s -f image2pipe -c:v png -frames:v 1 2>/dev/null -', escapeshellarg($url)), 'rb'); + return stream_get_contents($file); + } finally { + if(isset($file) && is_resource($file)) + pclose($file); + } } - public static function grabFirstAudioCover(string $url): Stream { - return self::grabFirstVideoFrame($url); - /*return new ProcessStream( - sprintf('ffmpeg -i %s -an -c:v png -f image2pipe -', escapeshellarg($url)), - 'rb' - );*/ + public static function grabFirstAudioCover(string $url): string { + try { + $file = popen(sprintf('ffmpeg -i %s -an -f image2pipe -c:v copy -frames:v 1 2>/dev/null -', escapeshellarg($url)), 'rb'); + return stream_get_contents($file); + } finally { + if(isset($file) && is_resource($file)) + pclose($file); + } } public static function probe(string $url): ?object {