Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Dec 2006
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Determine width/height of a media file?

    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.

    Thanks,
    -Metroid48

  • #2
    Regular Coder xconspirisist's Avatar
    Join Date
    Jun 2006
    Location
    Great Britain.
    Posts
    138
    Thanks
    1
    Thanked 6 Times in 6 Posts
    I'm afraid I don't personally know of any classes, extensions or librarys that could accomplish this.
    If I have been helpful, use the "thank" button - It makes me happy!

    xconspirisist.co.uk - homepage of my online alias
    technowax.net - a community for people interested in all forms of modern technology.

  • #3
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,108
    Thanks
    11
    Thanked 101 Times in 99 Posts
    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...
    Quote Originally Posted by ffmpeg
    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/
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #4
    Regular Coder xconspirisist's Avatar
    Join Date
    Jun 2006
    Location
    Great Britain.
    Posts
    138
    Thanks
    1
    Thanked 6 Times in 6 Posts
    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.
    If I have been helpful, use the "thank" button - It makes me happy!

    xconspirisist.co.uk - homepage of my online alias
    technowax.net - a community for people interested in all forms of modern technology.

  • #5
    New Coder
    Join Date
    Dec 2006
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    Last edited by Metroid48; 12-30-2006 at 07:42 PM.

  • #6
    New Coder
    Join Date
    Dec 2006
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Parsing?

    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?

    Thanks!


    EDIT: BTW, the FFMPEG-PHP bit does not work, however there is a binary that does work.
    Last edited by Metroid48; 01-08-2007 at 04:57 AM.

  • #7
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,108
    Thanks
    11
    Thanked 101 Times in 99 Posts
    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...

    PHP Code:
    <?php
            
    require_once('/fire/scripts/lib/getid3/getid3/getid3.php');
            
    $getID3 = new getID3();
            
    $filename="/fire/My Documents/video/ferrari1.mpg";
            
    $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/
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #8
    New Coder
    Join Date
    Dec 2006
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Works like a charm! Is a little confusing, though...

    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!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •