search
Homephp教程php手册PHP中使用php5-ffmpeg撷取视频图片实例

这篇文章主要介绍了PHP中使用php5-ffmpeg撷取视频图片实例,本文使用一个AVI格式视频为例,讲解了如何撷取视频画面为图片,需要的朋友可以参考下

前几天在玩 FFmpeg 的时后,突然发现 Ubuntu 上多了 php5-ffmpeg 这个扩充套件,就想来玩玩看,看好不好用,有两个结论:
读取影片取决于 FFmpeg 的支援性,如果想要什么格式都支援的话,建议自己重新编译 FFmpeg。
效率并没有我想像中的快,,两分钟的影片取十张图,大约 30 秒。
安装方法:

复制代码 代码如下:


sudo apt-get install ffmpeg php5-ffmpeg php5-gd


撷图测试范例:

复制代码 代码如下:


$page = 10;   
$prefix = 'screencap';   
   
$mov = new ffmpeg_movie('gt.avi');   
$count = $mov->getFrameCount();   
$range = (int)round($count/($page+1));   
   
for($i=1; $i    $frameNum = $range*$i;   
   $imgFile = $prefix.'_'.$i.'.png';   
   
   $frame = $mov->getFrame($frameNum);   
   if(!$frame){ continue; }   
   
   $gdImage = $frame->toGDImage();   
   if(!$gdImage){ continue; }   
   
   imagepng($gdImage, $imgFile);   
   imagedestroy($gdImage);   
   
   echo 'PHP中使用php5-ffmpeg撷取视频图片实例
';   
}  

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use