栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > PHP

php使用ffmpeg获取视频信息并截图的实现方法

PHP 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

php使用ffmpeg获取视频信息并截图的实现方法

本文实例讲述了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 '';
}

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程序设计有所帮助。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/43442.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号