温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

如何在php中利用ffmpeg获取视频信息

发布时间:2021-02-04 18:00:18 来源:亿速云 阅读:345 作者:Leah 栏目:开发技术

本篇文章给大家分享的是有关如何在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_fullname\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 an array for movies from the test media directory
$movies = getDirFiles(dirname(__FILE__) . '/tests/test_media');
echo "--------------------\n\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 video 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\n";
}
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 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;
}
?>

以上就是如何在php中利用ffmpeg获取视频信息,小编相信有部分知识点可能是我们日常工作会见到或用到的。希望你能通过这篇文章学到更多知识。更多详情敬请关注亿速云行业资讯频道。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI