java ffmpeg linux 截图_php使用ffmpeg获取视频信息并截图的实现方法

本文实例讲述了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;

}

?>

运行效果如下图所示:

f308e1040293bc85cb678535c7b313b2.png

希望本文所述对大家PHP程序设计有所帮助。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值