How can I convert videos in php without using ffmpeg? [duplicate] - php

This question already has answers here:
How to install ffmpeg for PHP
(2 answers)
Closed 6 years ago.
I made a code in php that extracts mp3 audio track from a video file using the exec function to execute ffmpeg.
All works fine on a local server using WAMP on windows. But when deploying the script to the server, I can not run ffmpeg anymore because the server does not have the software.
Is there a class in pure PHP, or an API that is capable of the same or at least the basic ffmpeg functionality?

But when deploying the script to the server, I can not run ffmpeg anymore because the server does not have the software.
It's easy to get ffmpeg on your server:
Download a static build of ffmpeg for Linux, Windows, or OS X.
Point your script to it.
Encode.
See FFmpeg Wiki: PHP.

EDITED:
As any conversion is very CPU intensive, there is no pure PHP solution and in near future never will be.

For conversion you can use https://cloudconvert.com/ that provides rest api and asyncronous conversions.

First your question title mentions "videos", but the question body asks about MP3s, could you please clarify?
Second, just because the server does not have ffmpeg this does not mean you cannot install it. This probably should be the option to pursue - and if the host is that strict, it is unlikely you'd be able to install any other solution anyway.
PHP as a language does not have MP3 decoders, and while it is possible to write one, or even to find one already written, I would avoid it. Parsing multimedia formats is tricky, as recent Stagefright bug in Android proved, so you'd be better using a well-tested and supported frameworks such as GStreamer or FFMpeg.
Also if you need to convert only certain formats such as MP3, you can look at MP3 decoders such as lame.

Related

How to create .exe executable file for php project [duplicate]

This question already has answers here:
Convert a PHP script into a stand-alone windows executable
(7 answers)
Closed 9 years ago.
I developed one project using YII framework. Now I want the project in single executable file.
Is it possible to create using yii or php libraries.
How to create .exe executable file for yii project.
And is it possible to convert project file to some format that if I install it any others
place that they can't read may be some encrypted format.
Short answer: Not possible.
Long answer: It depends.
You could install a web- and database server on his machine (or create an installer that does it) and run the application locally on his machine.
or
You keep the application on a server and just provide a launcher that opens his browser and points it to the URL of the application.
It might be a good idea to switch to SQLite instead of MySQL but depending on how your application is written it might require a lot of code and SQL Query changes.
PHP Desktop which allows you to create desktop apps in the same way as you build websites with php/html/js.
The convenient solution is not to convert the website to .exe. I think it will be better if you have portable server/php/mysql and make the website work from a usb or CD with autorun.
there are many good options for the same and you can find them at PHP Compilers
I have used PHPLanger for the same

Imagemagick exec and convert

I recently started using imagemagick with php and
I'm relatively new with both of these, IM and PHP.
So, I'm here to ask for some help/suggestion(s).
First
If lets say a user uploads a gif or a png image on
my site and I want it converted to jpg, is there any
command like for example.$image->convert($file,'.jpg)
or the convert command is accesible only thru exec() ?
like for example exec(convert picture.png to picture.jpg)
Second
What if for again, the user uploads gif/png on the site
and I resize the image to a specified width/height and
write the image, with the writeImage function of IM like this:
$image->writeImage(basename.$ext) where $ext = jpg.
Will this work properly,is this a good practice? I assume this will
only rename it but still, I don't see a problem in this... o.O
Oh sorry one more question, I'm not very familiar with exec,
is it better using imagemagick using exec(), does it improve
speed, load etc?
I can't answer your questions directly but thought I point you to a few resources:
Regarding which is better, exec or the PHP extension, I asked this same question a few months ago:
Should I use a PHP extension for ImageMagick or just use PHP's Exec() function to run the terminal commands?
For all Image Magick PHP functions you should look up the official guide:
http://www.php.net/manual/en/book.imagick.php
I switched from Image Magick to Graphics Magick as I heard it has better performance. It is a fork of Image Magick with an emphasis on performance. Large sites like Flickr and Etsy use it:
http://www.graphicsmagick.org/
This guide got me started:
http://devzone.zend.com/1559/manipulating-images-with-php-and-graphicsmagick/
And they have their own manual on php.net:
http://php.net/manual/en/book.gmagick.php (most of the commands are identical to Image Magick's)
I prefer using exec() as it is supported a lot better than Imagick ( the example code you posted ), easier to use and supports all the operators ( depending on your version ) which again Imagick does not.
Some of the Imagick code works differntly in the different versions; there are a lot more Imagick examples around than there were a couple of years ago when I first started looking at it.
Saying that Imagick can be faster and is/can be? built into php although some people have trouble installing it.
I belive that this site http://valokuva.org/?cat=1 belongs to a Imagick developer and has lots of examples.
My site www.rubblewebs.co.uk/imagemagick has lots of examples of php with exec( )
As to your other two questions yes you can change the file type with Imagick and I am not sure about basename.$ext - why not try it? As long as basename does not have an extension it may work but you might need to include basename.$ext in quotes.
As to speed it dpends sometimes GD is faster other times Imagick or Imagemagick. You can always do some tests. I did some a year or so ago and you can try the code on your server. http://www.rubblewebs.co.uk/imagemagick/speed/Speed_tests_1.pdf

Open documents(pdf,doc,docx,txt) in browser page using php (without using google docs viewer) [duplicate]

This question already has answers here:
Is there a PDF parser for PHP? [closed]
(7 answers)
Closed 8 years ago.
My question is that i want to open documents(pdf,doc,docx,txt) in browser page using php (without using google docs viewer) can any one help me?
Some of these are doable. Some, not so much. Let's tackle the low-hanging fruit first.
Text files
You can just wrap the content in <pre> tags after running it through htmlspecialchars.
PDF
There is no native way for PHP to turn a PDF document into HTML and images. Your best bet is probably ImageMagick, a common image manipulation program. You can basically call convert file.pdf file.png and it will convert the PDF file into a PNG image that you can then serve to the user. ImageMagick is installed on many Linux servers. If it's not available on your host's machine, please ask them to install it, most quality hosts shouldn't have a problem with this.
DOC & DOCX
We're getting a bit more tricky. Again, there's no way to do this in pure PHP. The Docvert extension looks like a possible choice, though it requires OpenOffice be installed as well. I was actually going to recommend plain vanilla OpenOffice/LibreOffice as well, because it can do the job directly from the command line. It's very unlikely that a shared host will want to install this. You'll probably need your own dedicated or virtual private server.
In the end, while these options can be made to work, the output quality is not guaranteeable. Overall, this is kind of a bad idea that you should not seriously consider implementing.
I am sure libraries and such exist that can do this. Google could probably help you there more than I can.
For txt files I would suggest breaking lines after a certain number of characters and putting them inside pre tags.
I know people will not be happy about this response, but if you are on a Linux environment and have pdf2html installed you could use shell_exec and call pdf2html.
Note: If you use shell_exec be wary of what you pass to it since it will be executed on the server outside of PHP.
I thought I'd just add that pdfs generally view well in a simple embed tag.
Or use an object so you can have fall backs if it cannot be displayed on the client.

Compile AS3 into a SWF online using Flex SDK's mxmlc

Read my question thoroughly before responding, I know there’s a site called wonderfl.net
I‘ve got the Flex SDK 4 on my Mac and I found a way to compile AS3 into SWF files using Flex's mxmlc compiler in Xcode, so I wondered, would it be possible to do this sort of simply online? Using for example a language I'm familiar with, PHP?
I thought it’d be a thing that would be interesting to use for a website, or like some private projects.
Thanks in advance!
You have the available tools to do so. You can write the AS3 content posted from the web into files, use PHP's exec function to run mxmlc, then send the resulting .SWF file to the client using PHP's readfile function. You'd just have to make sure mxmlc was present on the web server running the PHP.

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.

Categories