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.
Asked
Active
Viewed 1.2k times
3 Answers
3
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
)

mabako
- 1,213
- 11
- 19
-
My video is on amazons3 server. So by giving its path it is giving error 0x2a000000-* in stbl :( – Dena Nov 05 '12 at 23:11
-
Tried id out but got an error: "0x66726565-free in root". I guess its a bit outdated – Jonny Apr 29 '17 at 22:31
3
Try to use FF-MPEG. You can use it either via sys calls or using FF-MPEG extension for PHP which is located there http://ffmpeg-php.sourceforge.net/
Here is the way to get some meta information from the video using FF-MPEG-PHP:
$video = new ffmpeg_movie($filePath);
$duration = $video->getDuration();
$width = $video->getFrameWidth();
$height = $video->getFrameHeight()
FF-MPEG also has a bunch of useful features!

nkamm
- 627
- 5
- 14
-1
I don't wanna install any php extension (it's a disaster work under Windows, especially Windows 64bit), so I use ffprobe and a php (as follows) to get the dimension:
$xcmd = '{$ffmpeg-stored-folder}\bin\ffprobe -v error -of flat=s=_ -select_streams v:0 -show_entries stream=height,width '.$filename.' > vdogeom.txt';
exec($xcmd);
$lines = file("vdogeom.txt");
foreach ($lines as $v) eval('$'.$v.';');
}
echo strtoupper(pathinfo($filename, PATHINFO_EXTENSION)).intval(round(filesize($filename) * .0009765625))."K".$streams_stream_0_width."x".$streams_stream_0_height;
it will outpts such like as "WMV540K640x480"
The only trick here is: "I have to specify full path of the ffprobe exectution file cause my PHP's PATH environment is very bizzare".

Scott Chu
- 972
- 14
- 26
-
1A more simple solution is to return the result as json: ffprobe -v quiet -print_format json -show_format -show_streams out1.mp4 – klodoma Jan 05 '16 at 14:32