php使用ffmpeg获取视频信息并截图的实现方法
发布时间:2020-12-12 21:28:49 所属栏目:PHP教程 来源:网络整理
导读:本篇章节讲解php使用ffmpeg获取视频信息并截图的方法。供大家参考研究具体如下: getFrameWidth();$height=$movie->getFrameHeight();$count= $movie->getFrameCount();print $count . '';$n = round ( $count/16 );print $n . '';for ( $i = 1; $
本篇章节讲解php使用ffmpeg获取视频信息并截图的方法。分享给大家供大家参考,具体如下: 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程序设计有所帮助。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |