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

内容发布更新时间 : 2024/9/18 13:30:47星期一 下面是文章的全部内容请认真阅读。

本文实例讲述了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 = \

$extension_soname = $extension . \

$extension_fullname = PHP_EXTENSION_DIR . \ // load extension

if (!extension_loaded($extension)) {

  dl($extension_soname) or die(\ }

if (php_sapi_name() != 'cli') {   echo ' '; }

printf(\

printf(\ printf(\VCODEC_BUILD_NUMBER);

printf(\VCODEC_VERSION_NUMBER); print_class_methods(\ print_class_methods(\

// get an array for movies from the test media directory

$movies = getDirFiles(dirname(__FILE__) . '/tests/test_media'); echo \ foreach($movies as $movie) {

  $mov = new ffmpeg_movie($movie);

  printf(\

  printf(\  printf(\  printf(\  printf(\  printf(\  printf(\

  printf(\  printf(\

  printf(\  if ($mov->hasAudio()) {

    printf(\    printf(\    printf(\

    printf(\    printf(\  }

  printf(\  if ($mov->hasVideo()) {

    printf(\    printf(\    printf(\    printf(\    printf(\    printf(\

    printf(\    $frame = $mov->getFrame(10);

    printf(\

    printf(\    printf(\    printf(\  }

  echo \}

if (php_sapi_name() != 'cli') {   echo ''; }

/* FUNCTIONS */

function print_class_methods($class) {

  echo \  $methods = get_class_methods($class);   if (is_array($methods)) {

    foreach($methods as $method) {       echo $method . \    }

  } else {

    echo \   } }

function getDirFiles($dirPath) {

  if ($handle = opendir($dirPath))   {

    while (false !== ($file = readdir($handle))) {       $fullpath = $dirPath . '/' . $file;

      if (!is_dir($fullpath) && $file != \&& $file != \

        $filesArr[] = trim($fullpath);     }

    closedir($handle);   }

  return $filesArr; } ?>

希望本文所述对大家PHP程序设计有所帮助。