Remote video and thumbnails - all researched out - php

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');

Related

Resize images in AWS S3

I have a PHP REST API that hosts all images in the Amazon S3. I'm looking for a plugin, or trick, to resize the images using GET params. For example:
http://my-bucket.s3.amazon.com/image.jpg?width=300&height=300
I found this plugin, but a member of my team said it is ASP.NET based and doesn't fit to my PHP API project. Should I use a script hosted in EC2 to resize those images? Is there other way? Ideas are welcome.
Thanks!
I suggest setting up your own PHP service to resize images based on the query string values, as you describe. Yes, the PHP service could be hosted on AWS EC2 or another hosting platform. The service would need to receive the query string such as:
http://example.com/images/image.jpg?width=300&height=300
This would need to be configured (perhaps using mod_rewrite [1]) to receive the name of the image (example: 'image.jpg') and pass the query string size values into your PHP script. The script would then find your image on S3, resize it using an image library (such as ImageMagick / PHP GD or PHPThumb [2]) save it (or not) back to S3 and also pass the image data back through on the original request.
I wish you good fortune!
[1] https://httpd.apache.org/docs/current/mod/mod_rewrite.html
[2] http://phpthumb.sourceforge.net/
There is two options available:
1) LAMBDA : if you want to go with AWS services itself the lambda is a good solution for you
http://docs.aws.amazon.com/lambda/latest/dg/walkthrough-s3-events-adminuser.html
There are AWS lambda code which can generate thumbnails based on configured values. The AWS Lambda console itself has some of them which you could tweak into a working system. The link to the console will not work unless you are logged in.
2) ThirdParty : you can use third party resizer like
Timthumb : https://github.com/GabrielGil/TimThumb
TimThumb is a simple, flexible, PHP script that resizes images. (make sure your directory having public access)
Imagine:
https://github.com/avalanche123/Imagine
Best image processing lib for a few years now. OOP, unit tested, easy to use and MIT licensed. If someone knows another one of the same quality I would be surprised and like to know about it as well. :)
EasyphpThumbnail : http://www.mywebmymail.com/?q=content/easyphpthumbnail-class
The EasyPhpThumbnail Image Effects class allows you to handle image manipulation and PHP thumbnail generation for GIF, JPG and PNG on-the-fly. The class is FREE, 100% PHP based, available for PHP4 (from 4.3.11) and PHP5, is easy to use and provides lots of functionality with over 60 manipulations:

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

How to control the bitrate of youtube video on the go

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.

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

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).

Categories