How to control the bitrate of youtube video on the go - php

I am using PHP as server side scripting. I want to know , How to control the quality of a video using php.
Here is what i want to do.
I will capture a video using any device and upload to server, and while retrieving the video
i would like to provide some options for the quality of a video to be displayed. Similar to how youtube provide some settings 240p,260p,480p etc
many thanks

You could use software such as wowza to do converting on the fly (http://www.wowza.com/)
Alternatively you could convert your uploaded video (straight after upload) by shelling out to ffmpeg.
exec("ffmpeg -i $input -b 128k $output", $output);
and then link to the different video files depending on selected bitrate.

Related

Queuing up videos for live stream

Would first like to tell that am new to streaming and ffmpeg.
Would try to explain scenario as much as possible.
A web service is intended to receive chunks of video from a user. those chunks need to be simultaneously sent to the web for live streaming for a seamless viewing.
So the videos need to be queued up for streaming to the web so that it looks like a long single video. and the strict requirement is not to make any temp file on disk.
Did read something about pipes but am completely alien to that concept as well.
Kindly tell how / whether this can be achieved from FFMPEG or any other free tool .
Language used is PHP . The received videos also need to be saved to disk in parallel for new users to see from start.
You need to use an RTMP publisher that reads a flv/mpeg/avi/mov file (etc) and then connects to Red5, Wowza, or Flash Media Server.
You don't need tempfiles, just retrieve the video files from the user (in some manner) and then write a php scripts that uses ffmpeg to send them to the streaming server:
ffmpeg -i /home/video.avi -re -acodec libfaac - vcodec libx264 -vpre default -f flv rtmp://serverip/app/streamName

Upload video and extract thumbnail using Amazon s3

i have been working in a video website [platform: php] where i need to upload videos in Amazon S3 server and extract thumbnail.
I have created a bucket and uploaded video file successfully in that bucket. But i don't know how to extract the thumbnail from that uploaded video. So, that's where i stuck.
Any help will be appreciated. Thanks in advance!
Here you've got some options.
First - you can "extract" a thumbnail from the video before you upload it to AWS. Something like: upload video to your server, convert it to appropriate format if needed, take a thumbnail (or thumbnails), save them somewhere (e.g. on S3 or your local server) and then upload the video to S3. The disatvantage of this method is that your local server will have to do a lot of extra work, instead of serving your web visitors.
Second - you can use Amazon EC2 computing service for that: upload video to S3, trigger EC2 (e.g. with cron jobs) to take the video from S3, convert it, take thumbnails and upload the final result (converted video + thumbnails) back to S3. Disatvantages are: it's not very easy to implement this "communication" (you'll have to solve a lot of problems, like ensuring stable converts, creating job queues etc.), plus you'll have to use one more AWS service along with S3.
What's about video converting and getting thumbnails? There are many tools and programs for that. I like using ffmpeg for video converting (also there's PHP wrapper for using it's functionality with php - php-ffmpeg, but using ffmpeg itself (e.g. using php's exec() function) will give you more flexibility and features, please read documentation for more details). FFMpeg can extract thumbnails from videos as well, but it takes some time (there are lots of discussions about how to do it effectively), but I'd suggest you to use ffmpegthumbnailer for this purpose. It has simpler usage and is optimized especially for getting thumbnails from video files.
You should do this on the machine you are using for the upload. Here you have direct file-system access to the file. Once it is in S3 it is accessible via HTTP only.
The tool ffmpeg can be used to create a thumbnail of many video formats.
Example:
ffmpeg -i "video.flv" -ss 00:00:10 -f image2 "thumbnail.jpg"
Would create a thumbnail at video second 10 and save it as thumbnail.jpg
When using PHP you can use system to execute

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

Remote video and thumbnails - all researched out

Greetings all,
I have been working to get thumbnail images for a site of mine and have made some fairly decent progress. I have been able to create thumbnails of images locally and those hosted on a remote server as I had hoped.
The issue I am having is that I am unable to do the same for Videos. I have successfully installed each of the following along with their dependencies and confirm they are all working locally:
ffmpeg (and vicariously ffmpeg-PHP and ffmpegthumnailer)
Imagick (currently working for all simple "image" thumbnail creation, local and remote)
mplayer
As of yet I have been unable to find a method that would allow me to capture a thumbnail from my own video files on a remote server. The reason I am trying to connect to a remote video file is because these videos can range from 5MB to 300MB each and I don't desire to copy the entire movie locally just to create a thumbnail.
I had come across one of these that "may" allow capturing an image from a rtmp stream, which I conveniently do have access to ... but nothing fruitful came of it.
Any ideas would be greatly appreciated,
Thank you,
Silver Tiger
Update from Silver Tiger:
Looks like i had an alternative method via a third party. I used Zendcoder to convert the video files on the fly to a standard format that can play on my web project reliably, and as part of thier service, they will automatically create a dynamic thumbnail and upload it to my Amazon S3 along side the converted Video file.
Crisis averted, but in a roundabout way, and not a solution I could provide as a "solution" to anyone else unfortunately.
If you have ffmpeg installed it should be quite easy. Try something like this
$movie = 'somefile.avi'; // video file
$time = '00:03:34'; // time where to take the snapshot
$cmd = "ffmpeg -i '{$movie}' -an -ss {$time} -an -r 1 -vframes 1 -y thumb.jpg";
$escCmd = escapeshellcmd($cmd);
system($escCmd);
Maybe you could have a script on the remote server to call? This way the thumbnail is generated on the remote server, and then passed back to the front-end server.
The easiest way to do this is to install apache (or whatever you prefer) and host the thumbnail generation scripts on there.
Then all you would need to do is call:
$imageData = file_get_contents('http://remotehost/generateThunmb.php?videoid=bleh');

how to save an image from video/quicktime video?

Hello is there a way in PHP to save an image from video/quicktime video ?
It's not possible in pure PHP. You would have to use an external command line tool like ffmpeg - but that makes the script less portable to other servers.
The only other idea that comes to mind is the Snapshot plugin to the LongTail Video player. With that, you can manually send snapshots of a video playing in the video player (an embeddable Flash player) to a server side script. The process can't be automated, though, and the video will need to be a FLV or MP4 one for this to work.

Categories