SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    sweden
    Posts
    646
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    How do I check a sound file

    I want to make a page where people can upload a sound file.
    It have to be in Wav-format and some parameters have to be correct when uploading.

    Is there any way I can check a file when it has been uploaded, so the user will see that everything was ok.
    The file needs to be: Audio with 16 bit (sample size), 44.1 kHz (sample rate), 1411 kbps (bit rate) stereo WAV file.

    Not sure if it's possible, but would be great and save a lot of time if this process could be built in in the upload script.

    Any ideas?

  2. #2
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Probably with ffmpeg.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  3. #3
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    sweden
    Posts
    646
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    No, I want the users to make sure they are uploading the correct file. It's supposed to be a master sound file that can be used uncompressed.
    So, when they are uploading, I want my script to look at the details of the file and make sure all the elements are correct and give the uploader a thumbs up.
    Don't want them to upload a crappy mp3 file.

    I guess there must be some way I can check what's in the file with some code?

  4. #4
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    No. In order for your server to check the file it must be uploaded. There is no magic powers here.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  5. #5
    Always A Novice bronze trophy
    K. Wolfe's Avatar
    Join Date
    Nov 2003
    Location
    Columbus, OH
    Posts
    2,182
    Mentioned
    66 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by brad62 View Post
    No, I want the users to make sure they are uploading the correct file. It's supposed to be a master sound file that can be used uncompressed.
    So, when they are uploading, I want my script to look at the details of the file and make sure all the elements are correct and give the uploader a thumbs up.
    Don't want them to upload a crappy mp3 file.

    I guess there must be some way I can check what's in the file with some code?
    I'm unsure of the checks that can be done, but if there is a third party script to do the check on media such as this, you can always upload to a temp folder, run the check, and move the file to where it can be used or delete it accordingly depending on the result.

  6. #6
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    sweden
    Posts
    646
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Well, yes something like that. I've seen it somewhere, but don't remember where.
    The file is uploaded and a temporary folder might be fine. But I don't know how to check the file. How is a check like that working? What kind of code do I use for this?

  7. #7
    Always A Novice bronze trophy
    K. Wolfe's Avatar
    Join Date
    Nov 2003
    Location
    Columbus, OH
    Posts
    2,182
    Mentioned
    66 Post(s)
    Tagged
    2 Thread(s)
    You need to find a command line tool, from there you can use shell_exec (http://php.net/manual/en/function.shell-exec.php). As logic pointed out, you might be able to use ffmpeg, but you'll have to play around with it to see if it will fit your needs.

  8. #8
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    sweden
    Posts
    646
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Isn't there any way I can look at a file that is uploaded. When a user is uploading a sound file I would like to look at the header info or wherever this may be hidden. And then check if the file is 16 bit (sample size), 44.1 kHz (sample rate), 1411 kbps (bit rate) stereo WAV files.
    If everything is ok, I will tell the user that it looks fine. But if any of this is not correct, I will show an error code on the page, telling the user that the sample rate is not correct, or whatever is the error.

    Is there a way to do this or what should I look for when searching for answers?

  9. #9
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    sweden
    Posts
    646
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Sorry, I just found the answer.

    <pre>
    <?php
    $fp = fopen('soundd.wav', 'r');
    fseek($fp, 20);
    $rawheader = fread($fp, 16);
    $header = unpack('vtype/vchannels/Vsamplerate/Vbytespersec/valignment/vbits',
    $rawheader);
    print_r($header);
    ?>
    </pre>

  10. #10
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    sweden
    Posts
    646
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Well, I was too quick. I can't see the bitrate there. Is there a way to add that one as well? Or is that some math involved?

  11. #11
    SitePoint Addict kduv's Avatar
    Join Date
    May 2012
    Location
    Maui, HI
    Posts
    211
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    Check out ffmpeg-php. Don't be fooled by the name ffmpeg ... it doesn't only handle mpeg files. It handles lots of audio formats as well as a plethora of video formats. It will be more than enough to do what you need... including file creation, conversion, and even grabbing individual frames from video files.

    http://ffmpeg-php.sourceforge.net/
    Keith
    Freelance web developer
    http://www.duvalltech.com/


Bookmarks

Posting Permissions

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