View Full Version : Determine width/height of a media file?
12-30-2006, 02:23 AM
Hi, I have a player on my website which utilizes Real Player/WMP/Qt to play .wmv, .mpg, and .mov files. I was wondering if there was a way to get PHP to determine the width/height of any of these formats.
12-30-2006, 03:36 AM
I'm afraid I don't personally know of any classes, extensions or librarys that could accomplish this.
12-30-2006, 03:47 PM
If your server has ffmpeg installed you can get info about a supported format using -i
ffmpeg -i /path/to/file.mpg
you would need to exec() that and parse the output to grab the size... sample output...
Duration: N/A, start: 0.184656, bitrate: N/A
Stream #0.0[0x1e0]: Video: mpeg2video, yuv420p, 720x576, 7500 kb/s, 25.00 fps(r)
Stream #0.1[0x1c0]: Audio: mp2, 48000 Hz, stereo, 128 kb/s
If you don't want to parse data out yourself take a look at this take a look at this ... http://ffmpeg-php.sourceforge.net/
12-30-2006, 05:49 PM
Your server may, or may not support exec. Shared hosts seldom allow it, but firepages suggestion is a good one if you have it supported.
12-30-2006, 06:40 PM
Thanks for the suggestion, I use DreamHost webhosting so I will have to contact them to find out if they support it. I think they support exec(), though.
Anyway, thanks firepages for the suggestion. I'll try it out today!
EDIT: Just found out, ffmpeg isn't installed by default but they give instructions on how to install (and compile) it.
01-08-2007, 03:39 AM
I have just gotten ffmpeg working! Well, making thumbnails is a bit messed in programs like Gallery, however it does get an output like the sample output you gave. Just two things I need to know before implementing this:
1. How CPU intensive is this?
2. How do I properly parse it?
EDIT: BTW, the FFMPEG-PHP bit does not work, however there is a binary that does work.
01-08-2007, 12:41 PM
ok, sorry to change tack :) but I have recently been playing with the brilliant getid3 classes (code not an external library etc) & this is far far easier...
$getID3 = new getID3();
$fileinfo = $getID3->analyze($filename);
echo $fileinfo['video']['resolution_x']. 'x'. $fileinfo['video']['resolution_y'];
echo '<pre>';print_r($fileinfo);echo '</pre>';
check it out at http://getid3.sourceforge.net/
01-09-2007, 01:10 AM
Wow, that works perfectly! Though there are a lot of arrays-within-arrays-within.... from that method. A little confusing, as for .wmv files it's actually $fileinfo['video']['stream']['2']['resolution_x'];.
Anyway, it works great and solves my problem completely. Thanks!
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.