php使用ffmpeg獲取視頻信息并截圖的實現(xiàn)方法
來源:易賢網(wǎng) 閱讀:2330 次 日期:2016-08-25 15:09:43
溫馨提示:易賢網(wǎng)小編為您整理了“php使用ffmpeg獲取視頻信息并截圖的實現(xiàn)方法”,方便廣大網(wǎng)友查閱!

本文實例講述了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程序設(shè)計有所幫助。

更多信息請查看網(wǎng)絡(luò)編程
易賢網(wǎng)手機(jī)網(wǎng)站地址:php使用ffmpeg獲取視頻信息并截圖的實現(xiàn)方法
由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復(fù)僅供參考,敬請考生以權(quán)威部門公布的正式信息和咨詢?yōu)闇?zhǔn)!

2025國考·省考課程試聽報名

  • 報班類型
  • 姓名
  • 手機(jī)號
  • 驗證碼
關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 加入群交流 | 手機(jī)站點 | 投訴建議
工業(yè)和信息化部備案號:滇ICP備2023014141號-1 云南省教育廳備案號:云教ICP備0901021 滇公網(wǎng)安備53010202001879號 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號
云南網(wǎng)警備案專用圖標(biāo)
聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關(guān)注公眾號:hfpxwx
咨詢QQ:526150442(9:00—18:00)版權(quán)所有:易賢網(wǎng)
云南網(wǎng)警報警專用圖標(biāo)