Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

husseinrubaie98's avatar

Video Duration Length Time

Hello,

I have a web application that uploads videos, and I need to get the length time of the video. I am using the getID3 library suggested in: https://laracasts.com/discuss/channels/laravel/video-duration-time :

$video_file = $getID3->analyze('path-to-your-video');
// Get the duration in string, e.g.: 4:37 (minutes:seconds)
$duration_string = $video_file['playtime_string'];
// Get the duration in seconds, e.g.: 277 (seconds)
$duration_seconds = $video_file['playtime_seconds'];

But I'm getting an error when analyzing the video (could not open file, !file_exists, !file_readable). I don't remember the full error, but I believe it's related to the storage permissions, since my videos are private and not public. I am using Windows and XAMPP Server. Is there any way that this can be done/solved?

Thanks all. It really have been long time since I had the problem, and I'm really blocked.

0 likes
9 replies
mr-shahin's avatar

Can you show us where you store the files, and how you'e getting the file path also what is the permission for the directory where you store your files?

husseinrubaie98's avatar

@bljdavidson I have a symbolic link to the public storage file. But the videos that I'm trying to access and get their duration are private, and stored inside the storage folder not lonk to the public.

husseinrubaie98's avatar

@mr-shahin regarding the path, I'm using /storage/app/videos/video_name.mp4 When I open my PC, I will try to re-run the code to show you the exact error. And regarding the permission, I will also check it. But it should be private (since I'm not using the public storage folder)

husseinrubaie98's avatar

@bljdavidson @mr-shahin This is my code where I'm analyzing the video:

$video = $request->file('lesson_video');
$video_name = time() . "." . $video->getClientOriginalExtension();
$validation['filename'] = $video_name;
$video->storeAs('videos', $video_name);
$path = '/storage/app/videos/' . $video_name;
$getID3 = new \getID3;
$video_file = $getID3->analyze($path);
dd($video_file);

And here's the error I'm getting:

array:2 [▼
  "GETID3_VERSION" => "1.9.20-202006061653"
  "error" => array:1 [▼
    0 => "Could not open "\storage\app\videos03659311.mp4" (!is_readable; !is_file; !file_exists)"
  ]
]

I would really appreciate your help.

bljdavidson's avatar

@husseinrubaie98 rather than calling $path = '/storage/app/videos/' . $video_name; you can get the file contents with the Laravel Storage facade:

$path = Storage::disc('videos')->get($video_name);

Also, remember to add the relevant permissions in config/filesystem.php

'videos' => [
    'driver' => 'local',
    'root' => storage_path('app/videos'),
    'visibility' => 'private',
],

Hope this helps.

Ben

husseinrubaie98's avatar
Level 3

@bljdavidson That didn't work. First, when we call

Storage::('videos')->get('video_name')

This will get us the video file as byte map. That does not work. What I did was the following:

$video = $request->file('lesson_video');
$video_name = time() . "." . $video->getClientOriginalExtension();
$validation['filename'] = $video_name;
$video->storeAs('videos', $video_name);

$path = Storage::path("videos/" . $video_name);
$getID3 = new \getID3;
$video_file = $getID3->analyze($path);
$duration_seconds = $video_file['playtime_seconds'];

I just had to get the path of the file from the Storage Facade, and now it's working. Also, I deleted the configurations from filesystem.php (the one you suggested. I added them before and didn't work).

Thanks all for your help <3

2 likes
sudipto_karmoker's avatar

Yes this is very nice. And i have tested that on Laravel 8. And its working Great to get video time duration. Thank You.

1 like

Please or to participate in this conversation.