Convert audio files in PHP - php

I need to convert AMR audio file to MP3. How can I make it in PHP without FFMPEG (i have no permissions to install it on the server). Please help me.

Use SoX - the Swiss Army knife of sound processing. Very easy to use.
It is a command line tool not a PHP library so to use from PHP you need to execute a shell command and get the result with in your code. I have used it with in few projects.
Example with PHP:
<?php
exec('sox /mypath/my_audio.amr /mypath/my_audio.mp3');
?>
SoX is a cross-platform (Windows, Linux, MacOS X, etc.) command line utility that can convert various formats of computer audio files in to other formats. It can also apply various effects to these sound files, and, as an added bonus, SoX can play and record audio files on most platforms.
SoX is very mature project! Here is the link: http://sox.sourceforge.net/
Here are some examples I googled for you:
http://www.thegeekstuff.com/2009/05/sound-exchange-sox-15-examples-to-manipulate-audio-files/

Just use ffmpeg. You can simply download a binary of ffmpeg (look for "static builds"), and then point your script to the binary. There is no need to install it so there should be no permission issues.

AFAIK there is no way, at least without other command line utilities. You could try using mplayer, but I guess the situation here is the same as with ffmpeg. :)
You could of course upload the executable and run it through PHP if your host's policies allow this (safe mode, SELinux).

Simple answer: You can't convert audio files in pure PHP. I would suggest you to create/ search for a web-service to accomplish that task.

Related

Using FFMpeg av_read_frame in PHP?

I'm hoping to incorporate FFMpeg in a PHP script. My understanding is that the two best solutions are to use the command line via exec() and extract results or use PHP-FFMpeg (https://github.com/PHP-FFMpeg/PHP-FFMpeg).
What I want to do is walk through a video frame-by-frame, and I think I need to use av_read_frame(). What's the best way to use that from PHP? I don't think it's available from the command line or PHP-FFMpeg. Should I write a C program (using XCode) to do what I want and call it from my PHP script?
Thanks!
I ended up learning the command line interface to FFMPEG. (It wasn't as hard as I feared!) To walk through frame-by-frame, I just created all frames as jpeg files with a single ffmpeg command with exec(), walked through each one, then deleted them when I was done. Easy.
If the video size is a risk, FFMPEG can be used to generate a range of jpeg files using -ss and -to options. For example, 0-20 seconds, 20-40 seconds, etc. for about 200mb of files per set.

any way to encode to mp3 using php without paying fee

Is there any opeensource library available for php that we can use to encode mp3 without paying fee. I will be using mp3 encoding on my website. If not can you tell me how much fee we have to pay for recording ten minutes sound clip.
Legally, no, mp3 is patent encumbered so you have to pay to use it. That's not to say that libraries don't exist, just look at the long list of products that exist to rip a CD into mp3 encoded files. However, if you are putting it on a public website, you really should do this the proper way.
You can use the ffmpeg library for encoding, from here. You need to install an extension (probably "ffmpeg") in your Apache, whether it be in your local machine or in the server. For the latter, you can ask the server administrator to do the installation, but provide specific information as to which version of the extension you want to get it installed.
Note: There are differences with this extension version & the PHP version.
Hope it helps.
Have a look at mencoder and ffmpeg . both can encode mp3, you can execute them
on command line from your php script.
But as #BMitch said, try to be sure about patent and fees issues.

Convert Video to .flv?

Could someone please advise on what my options are when it comes to video type conversion in PHP. I have just discovered that our system uses something called ffmpeg. This isn't a problem but when a website is transferred it does create a problem as this absolute command breaks websites.
system ('/usr/bin/ffmpeg -i '.$video.' -y -f flv -qmin 5 -qmax 9 -ar 22050 '.DATA_DIR . $new_filename);
As you can see, a transferred website would require to have this path on their host and most don't.
So the question is this. I need to replace this. Is there some sort of PHP script or API that will make this work?
Is there any option other than pinging our own servers with the video and our video sending back the video in the new format?
Thanks.
Is there some sort of PHP script or API that will make this work?
No. This is well beyond the scope of PHP. FFMPeg is indeed the household name for video conversion - the best thing is probably to stick with that.
One workaround would be to set up a conversion service script on a server that supports ffmpeg, and all the other web sites sending the material to that server (if file sizes and traffic rates allow.)
There is a php ffmpeg library, but you can just install linux version of ffmpeg in your application and change this directory
No, there are no native PHP alternatives to ffmpeg for transcoding videos, so you must work around that somehow.
As mentioned before, there is no PHP extension that does video conversion (the ffmpeg-php extension can not convert videos) - you will have to call something not in PHP to get the video conversion proper done.
I see two possible problems on the "transferred websites":
If it is simply a path problem: look at this page for how to call ffmpeg - you should not have to include the "/usr/bin/" part in your command.
If the problem is that you cannot install ffmpeg on the transferred websites, you can do two things, depending on which drawback is more acceptable:
You may convert all videos to .flv beforehand, and serve them either from the transferred websites or from your own servers. Use that method for videos that will be watched often, or whose converted version will be watched often.
The transferred websites will point to the video flux from your own servers, that will handle the on-the-fly conversion. Do that for videos that will not be watched as often.
Feel free to install ffmpeg into your home directory on your hosting provider; many, if not most, hosts allow you to install programs in addition to scripts.
However, please do not place this code on a production system. Or, any computer you care about. If some smartass uploads a video named
Puppy;/bin/rm -rf /;.avi
then you can kiss all your data goodbye. If it is named:
Puppy;`nc -l 11111`;.avi
then they have a shell they can use for whatever they please.

Server-side conversion of raster images to vector images

I would like to convert images that have been uploaded by the user (in various formats and conditions) to a vector image format such as .eps. I'm primarily working in PHP.
What options exist?
There are a small number of autotracing software projects released under GPU (for example, POTRACE that you could run via system commands. I can't attest to their quality. Tracing almost always requires some element of human supervision to avoid things looking like a mess of broken pottery, but you won't know until you try. Rather than triggering the tracer via PHP, I would use PHP simply to save incoming images to a temporary folder and then, through cronjob (one- or two-per-minute), crank through the holding folder in batches (you could pace it that way and avoid it being used as a way to DoS your site).
I'm thinking of doing something slightly similar (though not graphic related) for an upcoming project, and I'm considering doing all my heavy lifting on a desktop machine, which would fetch all incoming files and process them before FTPing them back to the server. I'm somewhat nervous about having any complex resource-intensive script like this running on a web server.
Definitelly you can do this with the Inkscape
here is the list of formats it supports What formats can Inkscape import/export?
and it can be of course used with the command line or exec() command Can Inkscape be used from the command line?
Imagetracer is a free and open source (Public Domain) library and application which can be used on the server side. Disclaimer: I made these.
You can use ImageTracer.jar from
https://github.com/jankovicsandras/imagetracerjava
like this with PHP:
<?php exec("java -jar ImageTracer.jar input.png outfilename output.svg"); ?>
You can also use the JavaScript version with Node.js on the server side, here's the example code:
https://github.com/jankovicsandras/imagetracerjs/tree/master/nodecli
https://github.com/jankovicsandras/imagetracerjs/blob/master/nodetest/nodetest.js
PHP is not an image editor. It is a hypertext preprocessor.
You have to move to serverfault.com, or even better on some image processing resource, and ask there for some command line utility that can be run from PHP using the system() command.

automatically composite sound - php or something like that - GD library for sound?

I am looking for a way to accomplish the following: A user programs some drum loops in flash and is somehow able to download or save an mp3 of the loop.
I thought that the pattern could be composted on the server side. Then a link to the file is sent to the user.
I had thought there might be something like imageGD or imageMagick for sound out there?
Also, if it is possible for flash to generate something that the user could save on the fly? That would work too, but I am unaware of any such functionality in flash.
I suppose something could be done in processing, but I am totally unfamiliar with that.
How might this sort of thing might be accomplished?
Take a look at SoX.
SoX is a cross-platform (Windows, Linux, MacOS X, etc.) command line utility that can convert various formats of computer audio files in to other formats. It can also apply various effects to these sound files, and, as an added bonus, SoX can play and record audio files on most platforms.
If you have control over your server environment, I suppose you could use ffmpeg to do the job.
In your PHP code:
exec(escapeshellcmd("/path/to/ffmpeg -i /path/to/audiofile1.mp3 -i /path/to/audiofile2.mp3 -itsoffset 10 -i /path/to/audiofile3.mp3 -itsoffset 20 -acodec mp3 /path/to/outputfile.mp3"),$output,$status);
Notice that -itsoffset is the offset in seconds you want the audio file to be placed in. So this is not ideal if you want very minute control over the timing, but I don't know if you need that.
Check out this MP3 class.
I'm using it for a project that was deployed just today.
It can read MP3's, extract a part of them, and merge files, among other things, except it doesn't overlap sounds.
Provided you already have those sound pieces (drums, guitar, etc) and that you don't need overlapping, it seems this is what you're looking for.

Categories