Question Video to image

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
winracer

Question Video to image

Post by winracer »

I am working on a script that lets you upload all kinds of video and images. I am wornding if ImageMagick can be used to take a snapshoot of the video and then display it as a image. showing the image on main page.


the script I am using is wrote in php. also my hosting company has imagemagick installed.

thanks for any information . if a script has been written you someone tell me where to get it and if not any information link would be great!
blatant

Re: Question Video to image

Post by blatant »

ffmpeg does the job
especially if you have multiple video formats i would doubt magicks ability to extract (key) frames
ffmpeg has lots of filters for almost every possible codec
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Question Video to image

Post by Bonzo »

I think it can and would search the user section as this would have come up before.
winracer

Re: Question Video to image

Post by winracer »

blatant wrote:ffmpeg does the job
especially if you have multiple video formats i would doubt magicks ability to extract (key) frames
ffmpeg has lots of filters for almost every possible codec

thanks my hosting company does not support ffmpeg that is why I am looking to program something different
winracer

Re: Question Video to image

Post by winracer »

Bonzo wrote:I think it can and would search the user section as this would have come up before.

I searched and did not see a answer. I guess I could have mist it. thanks
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Question Video to image

Post by fmw42 »

I believe that IM uses ffmpeg to do its work on video. That delegate library is needed with IM.
winracer

Re: Question Video to image

Post by winracer »

I found this
http://www.imagemagick.org/Usage/video/
and using below code and it will not create a .gif file any thoughts?




<?php


$name = 'cat.avi';
$new_name = 'cat.gif';
$max_width = "90";
$max_height = "90";


exec("convert -quiet -delay 1 $name $max_widthx$max_height $new_name");
print("<b>New image size:</b>".$new_name.$name."<br>");

echo "<img src=\"".$name."\">";
echo "<img src=\"".$new_name."\">";
?>
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Question Video to image

Post by fmw42 »

you probably need the full path to convert, usually at /usr/local/bin or /usr/bin

try this

<?php
exec("/usr/local/bin/convert -version",$out,$returnval);
print_r($out[0]);
?>

or

in command line try

find /usr | grep "convert"

or

sudo find / | grep "convert"
winracer

Re: Question Video to image

Post by winracer »

fmw42 wrote:you probably need the full path to convert, usually at /usr/local/bin or /usr/bin

try this

<?php
exec("/usr/local/bin/convert -version",$out,$returnval);
print_r($out[0]);
?>

or

in command line try

find /usr | grep "convert"

or

sudo find / | grep "convert"



my paths are


ImageMagick /usr/bin/
ImageMagick (C) /usr/local/bin/convert


I tried this and still will not work

<?php


$name = 'cat.avi';
$new_name = 'cat.gif';
$max_width = "90";
$max_height = "90";


exec(" /usr/local/bin/convert -quiet -delay 1 $name $max_widthx$max_height $new_name");
print("<b>Names:</b>".$new_name.$name."<br>");

echo "<img src=\"".$name."\">";
echo "<img src=\"".$new_name."\">";
?>
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Question Video to image

Post by fmw42 »

see if it runs from the command line or what errors it tells you and report back.

On the surface this makes no sense for correct syntax:

convert -quiet -delay 1 $name $max_widthx$max_height $new_name

to what does the WidthxHeight refer?

Is that a subsection of the image or a crop or a resize? If the latter two, then you need some operator such as -crop or -resize, if the former, then the size must be specified as image.png[WidthxHeight+xoffset+yoffset] the brackets are important as are the offsets
winracer

Re: Question Video to image

Post by winracer »

fmw42 wrote:see if it runs from the command line or what errors it tells you and report back.

On the surface this makes no sense for correct syntax:

convert -quiet -delay 1 $name $max_widthx$max_height $new_name

to what does the WidthxHeight refer?

Is that a subsection of the image or a crop or a resize? If the latter two, then you need some operator such as -crop or -resize, if the former, then the size must be specified as image.png[WidthxHeight+xoffset+yoffset] the brackets are important as are the offsets

thanks

I changed to

http://www.imagemagick.org/Usage/video/


<?php


$name = 'cat.avi';
$new_name = 'cat.gif';



exec(" /usr/local/bin/convert -quiet -delay 1 $name $new_name");
print("<b>Names:</b>".$new_name.$name."<br>");

echo "<img src=\"".$name."\">";
echo "<img src=\"".$new_name."\">";
?>


but still do not get a cat.gif I can not run from command line. is there away to output error message to screen?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Question Video to image

Post by fmw42 »

try adding the returnval and print_r as in

<?php
exec("/usr/local/bin/convert -version",$out,$returnval);
print_r($out[0]);
?>
winracer

Re: Question Video to image

Post by winracer »

fmw42 wrote:try adding the returnval and print_r as in

<?php
exec("/usr/local/bin/convert -version",$out,$returnval);
print_r($out[0]);
?>

when I add


<?php
exec("convert -version",$out,$returnval);
print_r($out[0]);
?>[/quote]


I get
Version: ImageMagick 6.3.9 12/10/08 Q16 http://www.imagemagick.org
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Question Video to image

Post by Bonzo »

Try:

Code: Select all

<?php

$name = 'cat.avi';
$new_name = 'cat.gif';

$array=array();
echo "<pre>";
exec(" /usr/local/bin/convert $name -quiet -delay 1 $new_name 2>&1", $array); 
echo "<br>".print_r($array)."<br>"; 
echo "</pre>";
print("<b>Names:</b>".$new_name.$name."<br>"); 

echo "<img src=\"".$name."\">";
echo "<img src=\"".$new_name."\">";
?>
When I run this I get:
Array
(
[0] => convert: no tag found `avi:decode' @ delegate.c/InvokeDelegate/863.
[1] => convert: missing an image filename `cat.gif' @ convert.c/ConvertImageCommand/2822.
)
1
winracer

Re: Question Video to image

Post by winracer »

[quote="Bonzo"]Try:

Code: Select all

<?php

$name = 'cat.avi';
$new_name = 'cat.gif';

$array=array();
echo "<pre>";
exec(" /usr/local/bin/convert $name -quiet -delay 1 $new_name 2>&1", $array); 
echo "<br>".print_r($array)."<br>"; 
echo "</pre>";
print("<b>Names:</b>".$new_name.$name."<br>"); 

echo "<img src=\"".$name."\">";
echo "<img src=\"".$new_name."\">";
?>



When I run this I get:


thanks I get this error any thoughts?

Array
(
[0] => convert: Not enough pixel data `cat.avi'.
[1] => convert: missing an image filename `cat.gif'.
)
1
Post Reply