Skip to content

Instantly share code, notes, and snippets.

@erdum
Last active June 11, 2025 18:55
Show Gist options
  • Save erdum/c7b4f13981860b9636a3d71735444638 to your computer and use it in GitHub Desktop.
Save erdum/c7b4f13981860b9636a3d71735444638 to your computer and use it in GitHub Desktop.
Video Utility class
<?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