>  기사  >  백엔드 개발  >  ffmpeg를 사용하여 비디오 정보를 얻고 php_php 팁에서 스크린샷을 찍는 방법

ffmpeg를 사용하여 비디오 정보를 얻고 php_php 팁에서 스크린샷을 찍는 방법

WBOY
WBOY원래의
2016-05-16 19:53:291518검색

이 기사의 예에서는 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 &#63; '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 &#63; '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) &#63; '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;
}
&#63;>

작동 효과는 아래와 같습니다.

더 많은 PHP 관련 콘텐츠에 관심이 있는 독자는 이 사이트의 특별 주제를 확인할 수 있습니다. "PHP 그래픽 및 그림 조작 기술 요약", "PHP 조작 기술 요약 Office 문서(워드, 엑셀 포함), 액세스, ppt)", "php 날짜 및 시간 사용 요약", "php 객체지향 프로그래밍 입문 튜토리얼", " php 문자열(string ) 사용법 요약", "php mysql 데이터베이스 작업 입문 튜토리얼" 및 "php 일반 데이터베이스 작업 기술 요약"

이 기사가 PHP 프로그래밍에 종사하는 모든 사람에게 도움이 되기를 바랍니다.

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.