The example in this article describes how PHP uses FFmpeg to get video information and screenshots. Share to everyone for your reference, specific as follows:
$movie = new Ffmpeg_movie (' 4.mp4 ');
$width = $movie->getframewidth ();
$height = $movie->getframeheight ();
$count = $movie->getframecount (); Print $count.
'';
$n = Round ($count/16); Print $n.
''; for ($i = 1; $i <= 1; $i + +) {$img = ' screencap '. $i.
'. png ';
$x = $n * $i;
$f = $movie->getframe ($x);
$GD _image = $f->togdimage ();
Imagepng ($gd _image, $img);
Imagedestroy ($GD _image);
echo "\ n";
} $extension = "FFmpeg"; $extension _soname = $extension. "." .
Php_shlib_suffix; $extension _fullname = Php_extension_dir. "/" .
$extension _soname; Load extension if (!extension_loaded ($extension)) {DL ($extension _soname) or Die ("Can" t load extension $extension _ful
Lname\n ");
if (Php_sapi_name ()!= ' CLI ') {echo ';} printf ("ffmpeg-php version string:%s\n", ffmpeg_php_version_string);
printf ("ffmpeg-php Build date string:%s\n", ffmpeg_php_build_date_string);
printf ("Libavcodec build Number:%d\n", libavcodec_build_number); printf ("Libavcodec version nuMber:%d\n ", libavcodec_version_number);
Print_class_methods ("Ffmpeg_movie");
Print_class_methods ("Ffmpeg_frame"); Get a array for movies from the test media directory $movies = Getdirfiles (dirname (__file__).
'/tests/test_media ');
echo "--------------------\ n";
foreach ($movies as $movie) {$mov = new Ffmpeg_movie ($movie);
printf ("File name =%s\n", $mov->getfilename ());
printf ("duration =%s seconds\n", $mov->getduration ());
printf ("Frame count =%s\n", $mov->getframecount ());
printf ("Frame rate =%0.3f fps\n", $mov->getframerate ());
printf ("comment =%s\n", $mov->getcomment ());
printf ("title =%s\n", $mov->gettitle ());
printf ("Author =%s\n", $mov->getauthor ());
printf ("Copyright =%s\n", $mov->getcopyright ());
printf ("get bit rate =%d\n", $mov->getbitrate ()); printf ("has audio =%s\n", $mov->hasaudio () = = 0?
' No ': ' Yes ';
if ($mov->hasaudio ()) {printf ("Get audio stream id=%s\n", $mov->getaudiostreamid ()); printf ("Get Audio codec =%s\n", $mov->getaudiocodec ());
printf ("get audio bit rate =%d\n", $mov->getaudiobitrate ());
printf ("get audio sample rate =%d \ n", $mov->getaudiosamplerate ());
printf ("Get audio channels =%s\n", $mov->getaudiochannels ()); printf ("has video =%s\n", $mov->hasvideo () = = 0?
' No ': ' Yes ';
if ($mov->hasvideo ()) {printf ("frame height =%d pixels\n", $mov->getframeheight ());
printf ("Frame width =%d pixels\n", $mov->getframewidth ());
printf ("Get video stream id=%s\n", $mov->getvideostreamid ());
printf ("get-Video codec =%s\n", $mov->getvideocodec ());
printf ("get bit rate =%d\n", $mov->getvideobitrate ());
printf ("Get pixel format =%s\n", $mov->getpixelformat ());
printf ("get pixel aspect ratio =%s\n", $mov->getpixelaspectratio ());
$frame = $mov->getframe (10); printf ("Get frame =%s\n", Is_object ($frame)?
' True ': ' false '); printf ("Get Frame number =%d\n ", $mov->getframenumber ());
printf ("Get frame width =%d\n", $frame->getwidth ());
printf ("Get frame height =%d\n", $frame->getheight ());
echo "\ n--------------------\ n \ nthe"; } if (Php_sapi_name ()!= ' CLI ') {echo ';}/* Functions/function Print_class_methods ($class) {echo "\nmethods av
Ailable in class ' $class ': \ n ";
$methods = Get_class_methods ($class); if (Is_array ($methods)) {foreach ($methods as $method) {echo $method.
"\ n";
} else {echo ' No Methods defined\n '; }} function Getdirfiles ($dirPath) {if ($handle = Opendir ($dirPath)) {While false!== ($file = Readdir ($handle) ) {$fullpath = $dirPath. '/' .
$file;
if (!is_dir ($fullpath) && $file!= "CVS" && $file!= "." && $file!= "...")
$FILESARR [] = Trim ($fullpath);
} closedir ($handle);
return $FILESARR;
}?>
The effect is as shown in the following illustration:
More interested in PHP related content readers can view the site topics: "PHP graphics and pictures Operating skills summary", "PHP operation Office Document Skills Summary (including word,excel,access,ppt)", "PHP date and Time usage summary", " Introduction to PHP object-oriented programming, "PHP string (String) Usage Summary", "Php+mysql Database Operations Introduction Tutorial" and "PHP Common database Operation tips Summary"
I hope this article will help you with the PHP program design.