How to convert video to mp4,webM,ogv while uploading ? - php

i am using videojs to play video on my website(it's a HTML5 website) so for a better support i need to make 3 formats of each video mp4,webM,ogv.
But in my website user can upload video also.
So please tell me how can i automatically convert videos after/while uploading to these formats.
I am using PHP5+JS for development.

As the conversion will need to happen on the server side, you will only be able to do this once the upload has been completed. HTML5 is great but is does not support video transcoding.
I would suggest to have a look at ffmpeg, it's an extremely powerful command line utility that allow you transcode your video's with the finest precision, in fact youtube uses this to convert their video's as well.
It is a free tool and there is more than enough documentation to get you started at
http://ffmpeg.org/

We have a system set up in PHP where the upload occurs, conversion then takes place and the videos appear to the clients once the conversion is complete. However, one thing to note... I have always had trouble with ffmpeg conversions for iPhone, iPad, iPod, iOS, etc.

Related

How to convert a set of BitmapDatas into video?

I basically need to record a video of the flash stage, and save it as a video file on the webserver. I don't have FMS or the luxury of Java based servers like Red5 to stream to, so I am pretty much stuck with HTTP post to a php script. Now I can grab invidual snapshots (bitmapDatas) Just fine, but how can I convert them to a video file? Any help is appreciated.
PS: This is not an AIR app, so I am using flash runtime. And the video would be couple seconds long so there shouldn't be much of a performance concern at this point.
Flex provide a JPEG encoder. You can use that to compress the bitmap images and send them to the server, where you can that stitch them together using ffmpeg.
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/graphics/codec/JPEGEncoder.html

Uploading video, with PHP serverside formatting & encoding

We've currently developed an ExpressionEngine site (php), and are using a paid JWPlayer to display video uploaded by the client.
At present we're running into a number of issues, as the client is:
Uploading video at the wrong size
Uploading video randomly in both flv or mp4 format
And the player is chugging along terribly with multiple pauses throughout the video - sometimes buffering the entire clip before it is played.
I know FFMPEG can be installed serverside, but I'm not sure of the way in which to go about this, and how it might interact between ExpressionEngine and JWPlayer. I'm also not sure about the formatting - the ability for this automated encoding process to also crop/resize the video to suit the player dimensions on the site.
We would really like to have the videos playable on all browsers & iOS devices.
A HQ option would also be great where applicable, but it's just a nice to have - as we're struggling with the formatting / encoding issues first and foremost.
Any help figuring out the best process, and what tools I might need would be greatly appreciated.
I'd reccomend using a service like zencoder
I've used them in the past and no matter what video format I've thrown at them it works great. (PS. I'm not affiliated with them at all)
There is a PHP API with a whole lot of resizing, quality and format options. After you've uploaded your video you can send it to zencoder and they'll send you a response some time later with success or fail.
They can put the processed video on Amazon S3 or FTP it to a server.
You'll need a HTML5 player for iOS devices though, unless JWPlayer has come a long way since I used it last.
You could get zencoder to output in mp4. and then you still only need mp4 for JWPlayer/flash and the HTML5 version for iOS, as long as your happy to use flash for all desktop browsers there's no problem.
As far as the buffering issues you are having - I have found that using a CDN version of the swf for JWPlayer (or whatever player you are using) has caused it to load the entire video file before playing. Easily fixed by hosting it yourself.
I have found many times the video conversion capabilities of different CMS to be limited, and often restricting video formats to what the developers thought was appropriate, such as FLV, which nowadays is turning obsolete for video delivery.
One of the ways you can approach it is by creating a custom script to process the videos uploaded by your client using FFmpeg, which in fact can accept almost any video format, and generate the correct output formats and dimensions, ensuring that the resulting videos will be suitable for web playback using your player.
The problem with the video buffering you are facing is because the video file is not prepared for progressive download or pseudo-streaming, so your browser needs to download the whole video before starting to play. This can be solved with programs like qt-faststart for MP4 and MOV video files, and flvtool2 for FLV files. So your script would need to also optimize the encoded videos using these tools.
Also note that if you use an HTML5 video player (browser native or recent JWPlayer), then you can enjoy from random seeking the video files without buffering them.
If starting from scratch is not an option, you can look into a commercial solution like tremendum transcoder which also uses FFmpeg and is quite simple to use, yet it does all you need in regards to dealing with different input formats and aspect ratios automatically.
I have done a few setups this way, separating the CMS part from the video processing part, and it saved me some headaches.

Take a snapshot of a flv video with php/js/as3

I am developing a website in php hosted on a shared linux server.
I need to allow the users of my site to upload and play flv videos with flowplayer.
It would be fantastic to show a snapshot of the video before it starts, something like these: http://flowplayer.org/demos/plugins/streaming/first-frame.html
My server doesn't support pseudostreaming and it has no ffmpeg/mplayer support (it's a shared host after all...)
I am guessing how can I take a snapshot of the nth frame of the video with only php or javascript or action script.
I read something about bitmapdata class in flash >= 8, but i don't know how to do all the work automatically without the user's input.
Can someone help me?
Thanks.
AFAIK - if your server doesn't have ffmpeg, you're not going to be able to do it with PHP.
You definitely can't do it with JS.
Which leaves AS - you can create a bitmap from any display object, and save that as an image file with PHP, both of which are pretty straightforward - but you're not going to be able to run through the video to find the first frame... with AS, the image "snapshot" is the exact current visible state of the display object.
if that is enough - taking the current state of a display object and saving it as an image file - post back and i'll link a sample.
If you're on a shared Linux server, you might have ImageMagick installed. That in turn may be able to extract a screenshot of a particular frame from a movie. However this will probably only work on AVI files - MPEG movies require ffmpeg, and I am not sure about FLV files (they're not in the list of supported formats on the IM website).
Could you switch to a VPS? This will give you the root access you need to install the conversion binaries you need. These days a reasonable one with 256M-512M of RAM will cost you from 5USD pcm depending on the quality and support (I pay 4GBP pcm for a 512M box and it really has been rock solid).

php need help choosing player and format

I am in requirement of a player & video format that is supported on all desktop/laptop browser, and even on android and iphone, server is based on PHP
What I am right now using is .mov with H.264, which does not work on android, and sometimes not even in firefox
Help appreciated.
Thanks.
The fact that you are using PHP is irrelevant because PHP doesn't do video processing.
If you're trying to do video processing, your best bet will be getting ffmpeg installed, which you can call from your PHP script to process video.
You're probably going to want to store videos in the following formats, in order of likely-to-be-playable-hood:
FLV, Flash's video container, combined with a Flash video player. This will hit the largest chunk of your audience.
MPEG4 / H.264 will play in some systems that don't have Flash, including Apple's devices. Watch out, the H.264 codec is burdened by software patents and a commercial licensing scheme.
WebM (sometimes known as VP8) will soon play in everything else that doesn't support Flash or H.264.
For formats 2 and 3, you'll want to look at the HTML5 video tag, which will work in all modern browsers. Those modern browsers will also conveniently support those two formats. You'll want to read that link for a great deal more information about video handling, including a section on WebM encoding using ffmpeg and sections on mobile devices.
(There's also Ogg Theora, but nobody loves it enough.)

Uploading and Storing videos online using PHP and ffmpeg

I have a website that allows users to upload videos to it,
After they upload videos, I would like to be able to display them using a flash player.
One flash player i know is flowplayer, althrough if anyone knows a better one I will be happy to know.
In any case, as I understood from a brief google search, there are no players that can play .avi/.mpeg files, but they can only play .flv files.
I began searching for ways to convert my user's avi's/mpeg's and found that I can use ffmpeg to convert the video to .flv using system().
Is this the best solution for me? I feel like ffmpeg takes a lot of CPU and once I have enough users the server will crash..
Thanks!
Just an outline
(Note: i don't own nor wrote a PHP video sharing site, so treat these like tips)
Set up your web server and PHP to be capable of accepting large files via HTTP
Let users upload their videos via a web interface
Upon successful upload add uploaded video to a queue
Set up a fully server side script that handles video processing (No PHP)
Run a cron job on this queue when your server is able to crunch uploaded videos
Notify users when videos are done
Hope it helps in some way.

Categories