Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get width and height of mp4 file in php code before playing them [duplicate]

Tags:

php

mp4

I need to open file with .mp4 extension in popup. It is playing nicely and all other things are perfectly done. But when that popup is opening. At that time I want it to open with same height and width as of the video. I have that kind of more then 25 videos on my page. So I will store that parameters in code and then use it in javascript when I will open the popup. So I want to know video files width and height before I am playing that file. I want to know these parameters in php.

like image 860
Dena Avatar asked Oct 24 '25 14:10

Dena


1 Answers

Try the php-mp4info library.

include("MP4Info.php");
$info = MP4Info::getInfo('directory/to/file.mp4');
if($info->hasVideo) {
  echo $info->video->width . ' x ' . $info->video->height;
}

The $info object is, for example, as follows:

stdClass Object
(
  [hasVideo] => 1
  [hasAudio] => 1
  [video] => stdClass Object
    (
      [width] => 480
      [height] => 272
      [codec] => 224
      [codecStr] => H.264
    )
  [audio] => stdClass Object
    (
      [codec] => 224
      [codecStr] => AAC
    )
  [duration] => 6
)
like image 75
mabako Avatar answered Oct 27 '25 04:10

mabako