Conversion script - php

Hello I am wondering what processes involves converting files online...What programming languages are required?Basically I am wondering how are the files on scribd,issu,slideshare converted...
Thank you..!

There is a media processing library called FFMpeg. It will read, write and convert pretty much any common media format. It can resize, crop, scale, resample, etc all the files it can load, meaning videos can be shrunk in size, or whatever you might want to do!
The great thing is, if you have PHP and FFMpeg installed on a server, you can use PHP's exec() command to convert/modify/save videos.
A little note: beware of using exec() with any commands that are influence by what is sent from the server, like frame sizes, etc - hackers can latch onto them and mess your server up!
To get round the problem of pethetic people (script kiddies, etc), try ffmpeg-php. I don't know how popular this is on web hosts, but I haven't seen it many places in the wild.
James
EDIT
Unfortunately not. FFMpeg is primarily for video/audio conversion. However, there is a program called pdf2swf that should do the trick. The man page for it is here.
The only concern about pdf2swf is whether your web host actually has it installed on their server. If you have a VPN or a dedicated server, that's no problem, but if you're on shared hosting, and have no access to the root filesystem, this is where issues arise - you can't install pdf2swf if you don't have it.

Related

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.

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.

Generate an image / thumbnail of a webpage using X/Gui-less linux

There exists numerous solutions on generating a thumbnail or an image preview of a webpage. Some of these solutions are webs-based like websnapshots, windows libraries such as PHP's imagegrabscreen (only works on windows), and KDE's wkhtml. Many more do exist.
However, I'm looking for a GUI-less solution. Something I can create an API around and link it to php or python.
I'm comfortable with python, php, C, and shell. This is a personal project, so I'm not interested in commercial applications as I'm aware of their existence.
Any ideas?
You can run a web browser or web control within Xvfb, and use something like import to capture it.
I'll never get back the time I wasted on wkhtml and Xvfb, along with the joy of embedding a monolithic binary from google onto my system. You can save yourself a lot of time and headache by abandoning wkhtml2whatever completely and installing phantom.js. Once I did that, I had five lines of shell code and beautiful images in no time.
I had a single problem - using ww instead of www in a url caused the process to fail without meaningful error messages. Eventually I saw the dns lookup problem, and my faith was restored.
But seriously, every other avenue of thumbnailing seemed to be out of date and/or buggy.
phantom.js = it changed my life.

Stream data (such as music) using PHP (or another language)

For years, I've been investigating how to create music streams from my computer. I've seen programs, but anything useful I've seen is Windows only (I use a Mac).
Eventually, I got interested in how streams work. Is there any way I could create my own stream, possibly using socket functions in PHP? Is there a PHP library for this?
Take a look at Ampache. It is a Web-based Open Source Audio file manager. It is implemented with MySQL, and PHP. It allows you to view, edit, and play your audio files via the web.
In the end it all boils down to the protocol you'd want to use. Shoutcast IMHO is plain HTTP, so to make your own stream, you just output the streams content.
To make an ogg based webradio work with my Sonos system, I have created a little transcoding wrapper around sox which is is actually written in PHP, so it may be helpful to you to serve as an example.
You'll find it here: http://www.gnegg.ch/ogg2mp3/
If you are after implementing your very own streaming protocol - maybe even UDP based, then, I'm afraid, PHP may not be the right solution for the problem - at least not as long as it has its share of problems when used for long running processes (which 5.3 may bring some help for with its integrated garbage collection)

Categories