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

amk's avatar
Level 4

Video duration length time?

Is there any function have to take video duration time value from Controller just like image name getClientOriginalName()?

0 likes
4 replies
Helmchen's avatar
Helmchen
Best Answer
Level 15

Years ago I used php-ffmpeg.

But I'm really not sure if that's up to date.

OOP version

https://github.com/PHP-FFMpeg/PHP-FFMpeg#ffprobe

specifically

$ffprobe = FFMpeg\FFProbe::create();
$ffprobe
    ->format('/path/to/video/mp4') // extracts file informations
    ->get('duration');             // returns the duration property
2 likes
Israel Pereira's avatar

As @Helmchen wrote, PHP-FFMpeg is a great tool. The only downside is that it seems to be no longer updated.

There is also a great tool called getID3 by James Heinrich. (https://github.com/JamesHeinrich/getID3)

Here is an example of a use case.

$getID3 = new getID3;

$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'];

You can find more information on the Github page and in http://getid3.sourceforge.net/source/structure.txt.

husseinrubaie98's avatar

Thank you. I think this is helpful. 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.

So, could you please tell us what did you do so it worked on your project?

Thanks in advance!!

Please or to participate in this conversation.