php使用ffmpeg擷取視頻資訊並截圖的實現方法,phpffmpeg_PHP教程

來源:互聯網
上載者:User

php使用ffmpeg擷取視頻資訊並的實現方法,phpffmpeg


本文執行個體講述了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 extensionif (!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相關內容感興趣的讀者可查看本站專題:《PHP圖形與圖片操作技巧匯總》、《php操作office文檔技巧總結(包括word,excel,access,ppt)》、《php日期與時間用法總結》、《php物件導向程式設計入門教程》、《php字串(string)用法總結》、《php+mysql資料庫操作入門教程》及《php常見資料庫操作技巧匯總》

希望本文所述對大家PHP程式設計有所協助。

http://www.bkjia.com/PHPjc/1125246.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1125246.htmlTechArticlephp使用ffmpeg擷取視頻資訊並的實現方法,phpffmpeg 本文執行個體講述了php使用ffmpeg擷取視頻資訊並的方法。分享給大家供大家參考,具體...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.