brad62 — 2012-11-28T09:21:18-05:00 — #1
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.
logic_earth — 2012-11-28T13:22:58-05:00 — #2
brad62 — 2012-11-28T15:39:49-05:00 — #3
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?
logic_earth — 2012-11-28T15:58:52-05:00 — #4
No. In order for your server to check the file it must be uploaded. There is no magic powers here.
kylewolfe — 2012-11-28T16:04:12-05:00 — #5
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.
brad62 — 2012-11-29T08:37:25-05:00 — #6
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?
kylewolfe — 2012-11-29T09:49:03-05:00 — #7
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.
brad62 — 2012-12-11T05:02:03-05:00 — #8
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?
brad62 — 2012-12-11T05:19:33-05:00 — #9
Sorry, I just found the answer.
$fp = fopen('soundd.wav', 'r');
$rawheader = fread($fp, 16);
$header = unpack('vtype/vchannels/Vsamplerate/Vbytespersec/valignment/vbits',
brad62 — 2012-12-11T05:31:55-05:00 — #10
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?
kduv — 2012-12-11T15:29:17-05:00 — #11
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.