How to convert .caf file to .mp3 file using php? - php

I have created one webservice using php which upload audio file from IOS device to server.audio file gets uploaded as .caf format which is not supported by server so is there any way to convert .caf file to .mp3 or .wav file?
I want to create PHP script which will convert .caf file to .mp3 file any idea about it?
Thanks

Core Audio Format (.caf) is a audio file container developed by Apple for audio files. A .caf file can contains different audio file formats just like .mov container for different video formats.
So, changing the format from .CAF to .MP3 through Program is a difficult task but not impossible thing. I think you can use FFMPEG to change the format from CAF to MP3, just download the latest build or create your own are use the following command:
FFMPEG -i song.caf song.mp3
I haven't tried thing thing at all but think it will work. There is also a Perl Script available known as PACPL through which can be done as:
shell_exec("pacpl input.caf -to mp3");
You may or may not need to reconfigure the permissions or use sudo in there depending on the host server config.
.caf is just a container format, what's inside can vary, although the vast majority of the time it's going to be PCM uncompressed audio. This could actually be what was tripping Audacity and other programs up, as they were expecting PCM and what is inside the .caf is something else, like AAC. I've seen something similar happen with WAV files (which is also a container format, but has PCM audio in it most of the time).

Related

ffmpeg real-time encoding while file uploading by chunks

Now the process is:
File upload
Encode file with ffmpeg when file has been uploaded
Can be done at the same time?, obviusly yes, but I don't know how.
The file upload process is by 8MB chunks stored in server, then, temporary I have videofile.ext.tmp that is growing up to final uploaded file.
I read about ffmpeg -stream_loop or -loop parameters, but I don't know if the upload process is good for real-time encoding or how to manage it.
Any help will be appreciated.
EDITED: I tried this feature and works good when: Internet connection is faster than ffmpeg encode speed. When uploaded file is big enough.
I personally ruled out this procedure because the internet speed may change or cut out.
It depends on the file format. Some formats like ts,mkv,flv will work this way. Mp4 may or may not work depending on how the file was created.

Is it possible to display .bin image files on a web page without converting it to jpg/png/gif?

I am able to view the .bin image files using display command in ImageMagick.
display -size 512x512 -depth 32 -equalize gray:<filename>
I was able to convert it to jpg format and then display on a webpage.
But I need to display the file without converting it to jpg.
Using php exec(), it was possible to display the file when running the php file on terminal but not on apache web server.
Is there a way to display the .bin image file on a web page?
Please help me as I have been trying this for many days...
No.
The gray: protocol will only output an image data blob. There is no image headers, and various important meta-data (like size, depth, & etc) are not communicated/transported.
Even display requires you to, at minimum, specify size + depth before it can read the .bin file.
However, if you can communicate the depth & width to the web browser, you can rebuild the image with Javascript & <canvas> tag. But that would be labor intensive, and the load-time results would be unpleasant for end-users.

Get the stream content file from remote files

I'm using phpseclib to connect to SFTP from PHP.
I need to get a zip files from the SFTP Server. Those zip files contains xml and jpg files. I should extract data from xml and stream from jpg files and then save all in the database. I can't download the zip file because I haven't write permissions.
Can I get the stream content file (zip, xml and jpg) from remote files? Note that I'm using phpseclib.
You can get the stream content, however for the ZIP you need to program yourself a library that operates on the stream for the ZIP format (I do not know which one of the existing libraries can that out of the box, the ones I know can't, perhaps pclzip).
Then you need to operate on in-memory streams from the ZIP for the XML and JPG files which again needs to use stream compatible libraries - most likely you will need them to write yourself in context of PHP. Or at least invest a fair amount of time to deal this way.
But yes, it's perfectly possible. And (hopefully) you can do it.

Audio file to waveform using PHP

I'm looking for PHP class which will take an audio file and them return an image file of the waveform - similar effect can be seen here http://soundcloud.com/rollin-fire-cru/sets/house-house-house-house/
It should run on a linux server and accept the following audio file formats: mp3, mp4, aac, wav
I found an example class, but it does a very basic job
http://phpclasses.ca/package/482-PHP-Extracts-attributes-of-audio-files-Visualization.html
Any help will be highly appreciated!
All sane sites does this as a background job, preferably in a faster language (e.g.: C++).
You have to decode all the formats to raw audio (wav), then create an image from that. Preferably on the fly meaning as soon as you decode a chunk of audio you draw the image for that chunk. Most codecs compress the data to 5-20% of the original size, so if you have a 10M file you suddenly have 50-200M of raw data... and if you have a 100M DJ mix.. well.. you get the point.
After the background process finished, you can simply serve the generated image with your favorite web-server.
Although it's possible to do all of this in PHP I wouldn't recommend it.

How to embed audio message into an audio file with php?

I would like know if it is possible to create embedding of audio message to audio files?
For example, on playing every 10 sec of an audio, it would be interrupted with an audio message "You are currently listening to an audio by XYZ band" and then the audio continues. And even if someone were to download the mp3 file, the audio message is still embedded with that downloaded file?
May I know if there are any libraries or classes that can work with php to achieve the above result? And what would be the workflow?
Thank you very much.
You definitely can't do that in pure PHP - in theory you could write a MP3 decoding and encoding engine for PHP but it's an insane idea - and you will need some server side help for the task.
ffmpeg should enable you to mix multiple MP3s together to one file, provided your host supports it.
I would use sox for everything. It can decode and chop up the audio into segments, into which you can interject your message, and then render the sequence into a new mp3 file. It should also be able to overlay the messages onto the audio, so you don't break up the music, which might sound more pleasant.
Of course, this means using PHP just for management. The signal processing would be done by sox. If you really want to do as much as possible in PHP, use an external tool to decode the mp3 into a wave file, load the PCM into an integer array in PHP, and manipulate it there. PHP is probably not very fast when it comes to number crunching like this, but it should be possible. Save the PCM to disk for final encoding.

Categories