最新消息: 新版网站上线了!!!

php利用ffmpeg获取相当信息并截图

  1. $movie = new ffmpeg_movie('4.mp4'); 
  2. $width=$movie->getFrameWidth(); 
  3. $height=$movie->getFrameHeight(); 
  4. $count= $movie->getFrameCount(); 
  5. print $count . ''; 
  6. $n = round ( $count/16 ); 
  7. print $n . ''; 
  8. for ( $i = 1; $i <= 1; $i ++ ) { 
  9.     $img = 'screencap' . $i . '.png'; 
  10.     $x = $n * $i; 
  11.     $f = $movie->getFrame($x); 
  12.     $gd_image = $f->toGDImage(); 
  13.     imagepng($gd_image, $img); 
  14.     imagedestroy($gd_image); 
  15.     echo "
    \n"; 
  16. } 
  17. $extension = "ffmpeg"; 
  18. $extension_soname = $extension . "." . PHP_SHLIB_SUFFIX; 
  19. $extension_fullname = PHP_EXTENSION_DIR . "/" . $extension_soname; 
  20.  
  21. // load extension 
  22. if (!extension_loaded($extension)) { 
  23.     dl($extension_soname) or die("Can't load extension $extension_fullname\n"); 
  24. } 
  25.  
  26. if (php_sapi_name() != 'cli') { 
  27.     echo '
    '; 
  28. } 
  29.  
  30. printf("ffmpeg-php version string: %s\n", FFMPEG_PHP_VERSION_STRING); 
  31. printf("ffmpeg-php build date string: %s\n", FFMPEG_PHP_BUILD_DATE_STRING); 
  32. printf("libavcodec build number: %d\n", LIBAVCODEC_BUILD_NUMBER); 
  33. printf("libavcodec version number: %d\n", LIBAVCODEC_VERSION_NUMBER); 
  34.  
  35. print_class_methods("ffmpeg_movie"); 
  36. print_class_methods("ffmpeg_frame"); 
  37.  
  38. // get an array for movies from the test media directory 
  39. $movies = getDirFiles(dirname(__FILE__) . '/tests/test_media'); 
  40.  
  41. echo "--------------------\n\n"; 
  42. foreach($movies as $movie) { 
  43.     $mov = new ffmpeg_movie($movie); 
  44.     printf("file name = %s\n", $mov->getFileName()); 
  45.     printf("duration = %s seconds\n", $mov->getDuration()); 
  46.     printf("frame count = %s\n", $mov->getFrameCount()); 
  47.     printf("frame rate = %0.3f fps\n", $mov->getFrameRate()); 
  48.     printf("comment = %s\n", $mov->getComment()); 
  49.     printf("title = %s\n", $mov->getTitle()); 
  50.     printf("author = %s\n", $mov->getAuthor()); 
  51.     printf("copyright = %s\n", $mov->getCopyright()); 
  52.     printf("get bit rate = %d\n", $mov->getBitRate()); 
  53.     printf("has audio = %s\n", $mov->hasAudio() == 0 ? 'No' : 'Yes'); 
  54.     if ($mov->hasAudio()) { 
  55.         printf("get audio stream id= %s\n", $mov->getAudioStreamId()); 
  56.         printf("get audio codec = %s\n", $mov->getAudioCodec()); 
  57.         printf("get audio bit rate = %d\n", $mov->getAudioBitRate()); 
  58.         printf("get audio sample rate = %d \n", $mov->getAudioSampleRate()); 
  59.         printf("get audio channels = %s\n", $mov->getAudioChannels()); 
  60.     } 
  61.     printf("has video = %s\n", $mov->hasVideo() == 0 ? 'No' : 'Yes'); 
  62.     if ($mov->hasVideo()) { 
  63.         printf("frame height = %d pixels\n", $mov->getFrameHeight()); 
  64.         printf("frame width = %d pixels\n", $mov->getFrameWidth()); 
  65.         printf("get video stream id= %s\n", $mov->getVideoStreamId()); 
  66.         printf("get video codec = %s\n", $mov->getVideoCodec()); 
  67.         printf("get video bit rate = %d\n", $mov->getVideoBitRate()); 
  68.         printf("get pixel format = %s\n", $mov->getPixelFormat()); 
  69.         printf("get pixel aspect ratio = %s\n", $mov->getPixelAspectRatio()); 
  70.         $frame = $mov->getFrame(10); 
  71.         printf("get frame = %s\n", is_object($frame) ? 'true' : 'false'); 
  72.         printf("  get frame number = %d\n", $mov->getFrameNumber()); 
  73.         printf("  get frame width = %d\n", $frame->getWidth()); 
  74.         printf("  get frame height = %d\n", $frame->getHeight()); 
  75.     } 
  76.     echo "\n--------------------\n\n"; 
  77. } 
  78.  
  79. if (php_sapi_name() != 'cli') { 
  80.     echo ''; 
  81. } 
  82.  
  83. /* FUNCTIONS */ 
  84. function print_class_methods($class) { 
  85.     echo "\nMethods available in class '$class':\n"; 
  86.     $methods = get_class_methods($class); 
  87.     if (is_array($methods)) { 
  88.         foreach($methods as $method) { 
  89.             echo $method . "\n"; 
  90.         } 
  91.     } else { 
  92.         echo "No Methods Defined\n"; 
  93.     } 
  94. } 
  95.  
  96. function getDirFiles($dirPath) 
  97. { 
  98.     if ($handle = opendir($dirPath)) 
  99.     { 
  100.         while (false !== ($file = readdir($handle))) { 
  101.             $fullpath = $dirPath . '/' . $file; 
  102.             if (!is_dir($fullpath) && $file != "CVS" && $file != "." && $file != "..") 
  103.                 $filesArr[] = trim($fullpath); 
  104.         } 
  105.         closedir($handle); 
  106.     } 
  107.  
  108.     return $filesArr; 
  109. } 
  110.  
  111. ?> 

转载请注明:谷谷点程序 » php利用ffmpeg获取相当信息并截图