本文实例讲述了php使用ffmpeg获取视频信息并截图的方法。分享给大家供大家参考,具体如下:
$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_fullnamen");
}
if (php_sapi_name() != 'cli') {
echo '
';
}
printf("ffmpeg-php version string: %sn", ffmpeg_php_version_string);
printf("ffmpeg-php build date string: %sn", ffmpeg_php_build_date_string);
printf("libavcodec build number: %dn", libavcodec_build_number);
printf("libavcodec version number: %dn", libavcodec_version_number);
print_class_methods("ffmpeg_movie");
print_class_methods("ffmpeg_frame");
// get an array for movies from the test media directory
$movies = getdirfiles(dirname(__file__) . '/tests/test_media');
echo "--------------------nn";
foreach($movies as $movie) {
$mov = new ffmpeg_movie($movie);
printf("file name = %sn", $mov->getfilename());
printf("duration = %s secondsn", $mov->getduration());
printf("frame count = %sn", $mov->getframecount());
printf("frame rate = %0.3f fpsn", $mov->getframerate());
printf("comment = %sn", $mov->getcomment());
printf("title = %sn", $mov->gettitle());
printf("author = %sn", $mov->getauthor());
printf("copyright = %sn", $mov->getcopyright());
printf("get bit rate = %dn", $mov->getbitrate());
printf("has audio = %sn", $mov->hasaudio() == 0 ? 'no' : 'yes');
if ($mov->hasaudio()) {
printf("get audio stream id= %sn", $mov->getaudiostreamid());
printf("get audio codec = %sn", $mov->getaudiocodec());
printf("get audio bit rate = %dn", $mov->getaudiobitrate());
printf("get audio sample rate = %d n", $mov->getaudiosamplerate());
printf("get audio channels = %sn", $mov->getaudiochannels());
}
printf("has video = %sn", $mov->hasvideo() == 0 ? 'no' : 'yes');
if ($mov->hasvideo()) {
printf("frame height = %d pixelsn", $mov->getframeheight());
printf("frame width = %d pixelsn", $mov->getframewidth());
printf("get video stream id= %sn", $mov->getvideostreamid());
printf("get video codec = %sn", $mov->getvideocodec());
printf("get video bit rate = %dn", $mov->getvideobitrate());
printf("get pixel format = %sn", $mov->getpixelformat());
printf("get pixel aspect ratio = %sn", $mov->getpixelaspectratio());
$frame = $mov->getframe(10);
printf("get frame = %sn", is_object($frame) ? 'true' : 'false');
printf(" get frame number = %dn", $mov->getframenumber());
printf(" get frame width = %dn", $frame->getwidth());
printf(" get frame height = %dn", $frame->getheight());
}
echo "n--------------------nn";
}
if (php_sapi_name() != 'cli') {
echo '';
}
/* functions */
function print_class_methods($class) {
echo "nmethods available in class '$class':n";
$methods = get_class_methods($class);
if (is_array($methods)) {
foreach($methods as $method) {
echo $method . "n";
}
} else {
echo "no methods definedn";
}
}
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;
}
?>
运行效果如下图所示:
更多关于php相关内容感兴趣的读者可查看本站专题:《php图形与图片操作技巧汇总》、《php操作office文档技巧总结(包括word,excel,access,ppt)》、《php日期与时间用法总结》、《php面向对象程序设计入门教程》、《php字符串(string)用法总结》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》
希望本文所述对大家php程序设计有所帮助。
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:)!