Last active
June 11, 2025 18:55
-
-
Save erdum/c7b4f13981860b9636a3d71735444638 to your computer and use it in GitHub Desktop.
Video Utility class
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 | |
| namespace App\Utils; | |
| use App\Exceptions; | |
| use Illuminate\Support\Facades\Process; | |
| class Video | |
| { | |
| public static function get_duration(string $video_path): string | |
| { | |
| if (! file_exists($video_path)) { | |
| throw new Exceptions\BaseException( | |
| 'File does not exists in temporary location', | |
| 500 | |
| ); | |
| } | |
| $result = Process::run("ffprobe -i {$video_path} -show_entries format=duration -v quiet -of csv='p=0' -sexagesimal"); | |
| if ($result->failed()) { | |
| logger()->error('Error fetching video duration ffprobe failed: '.$result->errorOutput()); | |
| throw new Exceptions\BaseException( | |
| 'Error while parsing video duration', | |
| 500 | |
| ); | |
| } | |
| return substr($result->output(), 2, 5); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment