any way to encode to mp3 using php without paying fee - php

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.

Related

extract images from PDF with PHP

The thing is that the client wants to upload a pdf with images as a way of batch processing multiple images at once.
I already looked around and out of the box PHP can't read PDF's.
What are my alternatives?
I already know the host has not installed imageMagick or any pdf library and the exec function is disabled. That's basicly leaving me with nothing to work with, I guess?
Does anyone know if there is an online service that can do this, with an api of sorts?
thanks in adv
AFAIK, there is no PHP module to do it. There is a command line tool, pdfimages (part of xpdf). For reference, here's how that works:
pdfimages -j source.pdf image
Which will extract all images from source.pdf as image-000.jpg, image-001.jpg, etc. Note the output format is always Jpeg.
Possible Options
Being a command line tool, you need exec (or system, passthru, any of the command executing functions built into PHP). As your environment doesn't have that, I see four options:
Beg that exec be turned on for you (your hosting provider can limit what you can exec to a single command)
Change the design -- how about a ZIP upload?
Roll your own, using the source code of pdfimages as a model
Let pdfimages do the heavy lifting, by running it on a remote host you do control
Regarding #3, rolling your own, I don't think rolling your own, to solve a very narrow definition of requirements, would be too difficult. I seem to recall that the image boundaries in PDF are well defined: just read in the file to a boundary, cut to the end of the boundary, base64_decode, and write to a file -- repeat. However, that may be too much...
If rolling your own is too complicated, then option #4 is kind of like what Joel Spolsky describes for working with complicated Excel objects (see the numbered list under the bold heading "Let Office do the heavy work for you").
Find a cheap hosting environment (eg Amazon EC2) that let's you exec and curl
Install pdfimages
Write a PHP script that takes a URL to a PDF, curl opens that PDF, writes it to disk, passes it to pdfimages, then returns the URL to the resulting images.
An example exchange could look like this:
GET http://www.cheaphost.com/pdfimages.php?extract=http://www.limitedhost.com/path/to/uploaded.pdf
Content-type: text/html
<html>
<body>
<ul>
<li>http://www.cheaphost.com/pdfimages.php?retrieve=ab9895v/image-000.jpg</li>
<li>http://www.cheaphost.com/pdfimages.php?retrieve=ab9895v/image-001.jpg</li>
</ul>
</body>
</html>
So your single pdfimages.php script (running on the host with the exec functionality) can both extract images, and give you access to the extracted images. When extracting, it reads a PDF you tell it, runs pdfimages on it, and gives you back a list of URL to call to retrieve the extracted images. When retrieving, it just gives you back a straight image.
You would need to deal with cleanup, perhaps the thing to do would be to delete the image after retrieval. You would also need to handle security -- don't know what's in these images, but the content might need to be wrapped in SSL and other precautions taken.
You can use pdfimages and install it this way:
apt install poppler-utils
Then use it this way to get all the images as PNG files:
pdfimages -j mypdf.pdf image -png
Images will be placed in the same folder under image-000.png, image-001.png, etc.
There are many options available, including some to change the output format, more information here.
I hope this helps!

Convert audio files in 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.

Can Imagemagick be used without having to install it on the server?

I don't know anything about imagemagick, I have a need to convert images that users upload to gif format and resize and optimize said images as well. Before I look further into it, can someone please clarify whether imagemagick is a software or a standalone script? Meaning do I need to have it installed on my server or can I just uload the files and use the script's commands?
I'm referring to imagemagick for PHP.
It depends what you mean by "install."
If you are talking about the PHP extensions, then yeah, those have to be "installed."
If you are talking about the standalone binary programs, then no, they don't have to be "installed." If you can find a copy of the programs designed for the exact type and version of the operating system your server runs, you could place them somewhere accessible, give them execute permissions, and call them from your script. However, some shared hosting providers prohibit you from running compiled binaries in any way whatsoever, so this might not be such a good idea.
Your best bet is going to be either convincing your hosting provider to install it, or switching providers to one that already has it installed.
try MagickStudio
To convert, edit, or compose your image directly from a Web page, press Browse to browse and select your image file or enter the URL of your image. Next, set any of the optional parameters below. Finally, press view to continue.

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.

OpenCart mp3 preview

What is the best method and player for giving an audio preview on an OpenCart store. This would involve uploading the full track and then extracting a portion to be played
m3psplt is by far your best bet.
It can sometimes be a little dicey to install (particularly on CentOS, other RH based distros) but it's really the only solution I've found.
I usually run a script that analyzes the mp3 with getid3 to get the length, then I calculate the halfway point of the mp3, and pass that plus thirty seconds to mp3splt via the exec command to mp3splt.
It works great when you can get it to install properly. If you're on debian/ubuntu it's actually a cinch to install via aptitude.
The only other thing I could think do do would be to wrap your command line unix audio editing utilities in a php script to basically create a "grab 2 minute head of MP3" function, then run that on files when they are uploaded. then yes, save them in a "previews" area of the file system and store the filename in a DB table for later reference.
I've found a PHP script that could fit your needs (please note I didn't tested it). You can find it here. The class interface seems simple and functional. Anyway, you will need to modify your OpenCart product template to expose the preview command.

Categories