473,803 Members | 2,909 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

create video screen cap with PHP

Does anyone out there know of a way to capture a frame (at random, if
possible) of a movie file with PHP?

TIA

--
Karl Groves
www.karlcore.com
Aug 13 '06 #1
8 2698
On Sun, 13 Aug 2006 16:44:11 -0500, Karl Groves wrote:
Does anyone out there know of a way to capture a frame (at random, if
possible) of a movie file with PHP?
The easiest way will be to call out to mplayer to do it. You'll have to
do it twice, once to get the length of the movie (and then optionally a
second time if you don't want the first frame).

mplayer -identify -ss 20:00 -vo jpeg -ao null -frames 1 video.avi

This will print out (amongst many many other things):

ID_LENGTH=4498. 26

This ID_LENGTH is the the length of the movie in seconds.

Calling mplayer like this will create a file called 000001.jpg which
you'll need to rename (and implement some locking PHP-side to ensure you
don't run two mplayer instances simultaneously which will whack the same
file).

So, along with exec($cmdline, &$output) you have all you need :-)

Cheers,
Andy
--
Andy Jeffries MBCS CITP ZCE | gPHPEdit Lead Developer
http://www.gphpedit.org | PHP editor for Gnome 2
http://www.andyjeffries.co.uk | Personal site and photos

Aug 15 '06 #2
On Tue, 15 Aug 2006 12:48:41 +0000, Andy Jeffries wrote:
mplayer -identify -ss 20:00 -vo jpeg -ao null -frames 1 video.avi
Sorry, forgot to mention -ss mm:ss is the offset. Here I use 20 minutes
in, but you should call it with 00:00 initially to get the first frame in
case the movie isn't 20 minutes long ;-)

Cheers,
Andy

--
Andy Jeffries MBCS CITP ZCE | gPHPEdit Lead Developer
http://www.gphpedit.org | PHP editor for Gnome 2
http://www.andyjeffries.co.uk | Personal site and photos

Aug 15 '06 #3
Andy Jeffries <ne**@andyjeffr ies.co.ukwrote in
news:pa******** *************** ****@andyjeffri es.co.uk:
On Sun, 13 Aug 2006 16:44:11 -0500, Karl Groves wrote:
>Does anyone out there know of a way to capture a frame (at random, if
possible) of a movie file with PHP?

The easiest way will be to call out to mplayer to do it. You'll have to
do it twice, once to get the length of the movie (and then optionally a
second time if you don't want the first frame).

mplayer -identify -ss 20:00 -vo jpeg -ao null -frames 1 video.avi

This will print out (amongst many many other things):

ID_LENGTH=4498. 26

This ID_LENGTH is the the length of the movie in seconds.

Calling mplayer like this will create a file called 000001.jpg which
you'll need to rename (and implement some locking PHP-side to ensure you
don't run two mplayer instances simultaneously which will whack the same
file).

So, along with exec($cmdline, &$output) you have all you need :-)

Thanks for the excellent response.
Do you have, perhaps, a more comprehensive example? I don't have much
experience with using exec(), except for using it to perform ImageMagick
commands.

--
Karl Groves
www.karlcore.com
Aug 15 '06 #4
On Tue, 15 Aug 2006 09:01:09 -0500, Karl Groves wrote:
To be honest, you should have everything you need above and my normal
response would be RTFM/try it and come back with some code even if it has
problems for us to fix.

However, I'm in a good mood so below is some code I've just knocked and
had a quick test with. It works fine. The locking code could do with a
usleep/while loop to keep trying in the event of a lock failure, but the
basics are surely close enough now for you.

It also gets round a bug where (on the movie I was testing it on at least)
the first frame image is always the start of the movie, but the second
frame is the real one.

#!/usr/bin/env php
<?php

function movie_get_lengt h_in_seconds($m ovie_filename)
{
$cmd = "mplayer -identify -vo null -ao null -frames 1 ".
"$movie_filenam e 2>&1 | grep ID_LENGTH";
$output = exec($cmd);
list(,$length) = explode("=", $output); return $length;
}

function movie_take_scre enshot($movie_f ilename, $time_in_second s,
$image_filename )
{
if (mkdir(".movie. lck")) { // Try to get a lock
$cmd = "mplayer -ss $time_in_second s -vo jpeg ".
"-ao null -frames 2 $movie_filename " 2>&1 | ".
"grep ID_LENGTH";
exec($cmd);
rename("0000000 2.jpg", "$image_filenam e");
unlink("0000000 1.jpg");
rmdir(".movie.l ck"); // Release lock
return true;
}
return false; // Could not obtain lock
}

$movie_filename = "test.mpg";
$movie_length = movie_get_lengt h_in_seconds($m ovie_filename);
$random_seconds = rand(0, floor($movie_le ngth));
$was_image_crea ted = movie_take_scre enshot($movie_f ilename,
$random_seconds , "test_image.jpg ");
?>

Cheers,
Andy
--
Andy Jeffries MBCS CITP ZCE | gPHPEdit Lead Developer
http://www.gphpedit.org | PHP editor for Gnome 2
http://www.andyjeffries.co.uk | Personal site and photos

Aug 16 '06 #5
On Wed, 16 Aug 2006 11:55:35 +0000, Andy Jeffries wrote:
function movie_get_lengt h_in_seconds($m ovie_filename) {
$cmd = "mplayer -identify -vo null -ao null -frames 1 ".
"$movie_filenam e 2>&1 | grep ID_LENGTH";
$output = exec($cmd);
list(,$length) = explode("=", $output); return $length;
Somewhere along the posting route, it seems to have snipped some line
endings, but I'm sure you can re-prettify my code :-)

Cheers,
Andy

--
Andy Jeffries MBCS CITP ZCE | gPHPEdit Lead Developer
http://www.gphpedit.org | PHP editor for Gnome 2
http://www.andyjeffries.co.uk | Personal site and photos

Aug 16 '06 #6
Andy Jeffries <ne**@andyjeffr ies.co.ukwrote in
news:pa******** *************** *****@andyjeffr ies.co.uk:
On Wed, 16 Aug 2006 11:55:35 +0000, Andy Jeffries wrote:
>function movie_get_lengt h_in_seconds($m ovie_filename) {
$cmd = "mplayer -identify -vo null -ao null -frames 1 ".
"$movie_filenam e 2>&1 | grep ID_LENGTH";
$output = exec($cmd);
list(,$length) = explode("=", $output); return $length;

Somewhere along the posting route, it seems to have snipped some line
endings, but I'm sure you can re-prettify my code :-)

Cheers,
Thanks for this. I'll give it a shot.

--
Karl Groves
www.karlcore.com
Aug 16 '06 #7

Andy Jeffries wrote:
The easiest way will be to call out to mplayer to do it. You'll have to
do it twice, once to get the length of the movie (and then optionally a
second time if you don't want the first frame).

mplayer -identify -ss 20:00 -vo jpeg -ao null -frames 1 video.avi
Sorry for my ignorance, is mplayer a Linux utility or Windows?

Aug 17 '06 #8
On Thu, 17 Aug 2006 05:15:29 -0700, ImOk wrote:
>The easiest way will be to call out to mplayer to do it. You'll have to
do it twice, once to get the length of the movie (and then optionally a
second time if you don't want the first frame).

mplayer -identify -ss 20:00 -vo jpeg -ao null -frames 1 video.avi

Sorry for my ignorance, is mplayer a Linux utility or Windows?
Primarily Linux, but there's a Windows version too:

http://www.mplayerhq.hu/design7/dload.html

Don't forget to get the codecs pack if you want to use WMV/MOV etc.

Cheers,
Andy

--
Andy Jeffries MBCS CITP ZCE | gPHPEdit Lead Developer
http://www.gphpedit.org | PHP editor for Gnome 2
http://www.andyjeffries.co.uk | Personal site and photos

Aug 17 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
1295
by: Marketta | last post by:
Hi, Can anyone tell me, how to create a screen saver using C#. -- Ever Loving, Marketta
2
12831
by: Brian Hampson | last post by:
I'd like to be able to create either AVI, MPG, or MOV from a series of JPGS (BMPS, etc). I have no clue about where to start, or what to do. I've tried Googling, but to no avail :( Please help. Thanks!
1
9348
by: alfata | last post by:
hi there i'm new to c sharp and i would like to learn more about it and design the first form LOGIN so that i put admin user and pasword i tried everything with no luck so i come here to get some help from you guys thanks
1
1525
by: yatin | last post by:
i urgently want to know how can i take a screen shots of the video in the php, plz give me a suitable example or link. i am using a flb player on this i have to show the screen shots of videos.
2
1418
by: emrapha | last post by:
Hello people, I want you to help me create a media player using visual basic. Can someone help me . thanks
0
770
by: agarwalsunitadhn | last post by:
Hi I am new in window programming. I am working on a window base project in C#.net. and for the new project i have to design a splash screen displayed just for a minute. i dont know hoe to create this. please suggest. thanks
3
14105
by: Abhijit Taur | last post by:
i want to creat an touch screen calculator how should i devlop the windows form?
1
4760
by: Moinoddin | last post by:
i am facing problem in creating video thumbnail. i am working on xampp server. i want to capture video thumbnail while uploading video. If anybody knows then please get back to me...
0
10542
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10309
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10289
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9119
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7600
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5496
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4274
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3795
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2968
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.