【转载】FFmpegPHP的安装使用详解
来源:互联网 发布:视频人声消音软件 编辑:程序博客网 时间:2024/06/06 00:51
FFmpegPHP封装,没有提供视频转换的接口。(至少我没找到,如果大家知道还望赐教。)
我使用的集成环境APMServ。
1.下载ffmpeg-php:http://sergey89.ru/files/ffmpeg-php-win32-all.zip
2. 解压ffmpeg-php-win32-all.zip 后有下面几个文件:
avcodec-51.dll
avformat-51.dll
avutil-49.dll
php_ffmpeg.dll
pthreadGC2.dll
3. 将四个文件拷贝到windows/system32文件夹下面
avcodec-51.dll, avformat-51.dll, avutil-49.dll, pthreadGC2.dll
4.将php_ffmpeg.dll拷贝到php的ext目录下。
5. 然后需要到apache/bin文件下找到php.ini文件下允许使用dll文件加入extension=php_ffmpeg.dll 并允许 extension=php_gd2.dll, extension=php_gettext.dll这两个设置。(去掉前面的分号)
extension=php_gd2.dll
extension=php_gettext.dll
extension=php_ffmpeg.dll
6. 重新启动APMServ后使用phpinfo()函数看到一下信息配置:
以上就表明ffmpeg在php环境中配置成功了。
7. 下面我们建立一个php的页面来测试是不是可以使用ffmpeg的一些函数功能。建立testvideo.php文件
代码如下:
<?phpextension_loaded('ffmpeg');
$ffmpegInstance = new ffmpeg_movie('D:\Program Files\APMServ5.2.6\www\htdocs\test.mpg');
echo "getDuration: " . $ffmpegInstance->getDuration()."<br>" .
"getFrameCount: " . $ffmpegInstance->getFrameCount()."<br>" .
"getFrameRate: " . $ffmpegInstance->getFrameRate()."<br>" .
"getFilename: " . $ffmpegInstance->getFilename()."<br>" .
"getComment: " . $ffmpegInstance->getComment()."<br>" .
"getTitle: " . $ffmpegInstance->getTitle()."<br>" .
"getAuthor: " . $ffmpegInstance->getAuthor()."<br>" .
"getCopyright: " . $ffmpegInstance->getCopyright()."<br>" .
"getArtist: " . $ffmpegInstance->getArtist()."<br>" .
"getGenre: " . $ffmpegInstance->getGenre()."<br>" .
"getTrackNumber: " . $ffmpegInstance->getTrackNumber()."<br>" .
"getYear: " . $ffmpegInstance->getYear()."<br>" .
"getFrameHeight: " . $ffmpegInstance->getFrameHeight()."<br>" .
"getFrameWidth: " . $ffmpegInstance->getFrameWidth()."<br>" .
"getPixelFormat: " . $ffmpegInstance->getPixelFormat()."<br>" .
"getBitRate: " . $ffmpegInstance->getBitRate()."<br>" .
"getVideoBitRate: " . $ffmpegInstance->getVideoBitRate()."<br>" .
"getAudioBitRate: " . $ffmpegInstance->getAudioBitRate()."<br>" .
"getAudioSampleRate: " . $ffmpegInstance->getAudioSampleRate()."<br>" .
"getVideoCodec: " . $ffmpegInstance->getVideoCodec()."<br>" .
"getAudioCodec: " . $ffmpegInstance->getAudioCodec()."<br>" .
"getAudioChannels: " . $ffmpegInstance->getAudioChannels()."<br>" .
"hasAudio: " . $ffmpegInstance->hasAudio();
8.执行后如果拿到视频的一些信息如下就表示环境配置成功了,那我们就可以开始开发我们的视频操作。
执行结果:
略....
9.实现视频的截图。(接上面的php代码)
$ff_frame = $ffmpegInstance->getFrame(20);//截取视频第20帧的图像
$gd_image = $ff_frame->toGDImage();
$img=$_SERVER['DOCUMENT_ROOT']."/test2.jpg";//要生成图片的绝对路径
imagejpeg($gd_image, $img);//创建jpg图像
imagedestroy($gd_image);//销毁一图像
10.关于ffmpeg-php的API。
- path_to_media - File path of video or audio file to open.
- persistent - Whether to open this media as a persistent resource. See the PHP documentation for more info about persistent resources
NOTE: This only works for files with constant bit rate.
$movie->getAudioBitRate() Return the audio bit rate of the media file in bits per second. $movie->getAudioSampleRate() Return the audio sample rate of the media file in bits per second. $movie->getFrameNumber() Return the current frame index. $movie->getVideoCodec() Return the name of the video codec used to encode this movie as a string. $movie->getAudioCodec() Return the name of the audio codec used to encode this movie as a string. $movie->getAudioChannels() Return the number of audio channels in this movie as an integer. $movie->hasAudio() Return boolean value indicating whether the movie has an audio stream. $movie->hasVideo() Return boolean value indicating whether the movie has a video stream. $movie->getFrame([Integer framenumber]) Returns a frame from the movie as an ffmpeg_frame object. Returns false if the frame was not found.- framenumber - Frame from the movie to return. If no framenumber is specified, returns the next frame of the movie.
ffmpeg_frame object methods
NOTE: This function will not be available if GD is not enabled.
$frame->getWidth() Return the width of the frame. $frame->getHeight() Return the height of the frame. $frame->getPTS() alias $frame->getPresentationTimestamp() Return the presentation time stamp of the frame. $frame->resize(Integer width, Integer height [, Integer crop_top [, Integer crop_bottom [, Integer crop_left [, Integer crop_right ]]]]) Resize and optionally crop the frame. (Cropping is built into ffmpeg resizing so I'm providing it here for completeness.)- width - New width of the frame (must be an even number).
- height - New height of the frame (must be an even number).
- croptop - Remove [croptop] rows of pixels from the top of the frame.
- cropbottom - Remove [cropbottom] rows of pixels from the bottom of the frame.
- cropleft - Remove [cropleft] rows of pixels from the left of the frame.
- cropright - Remove [cropright] rows of pixels from the right of the frame.
NOTE: Cropping is always applied to the frame before it is resized. Crop values must be even numbers. $frame->crop(Integer crop_top [, Integer crop_bottom [, Integer crop_left [, Integer crop_right ]]]) Crop the frame.
- croptop - Remove [croptop] rows of pixels from the top of the frame.
- cropbottom - Remove [cropbottom] rows of pixels from the bottom of the frame.
- cropleft - Remove [cropleft] rows of pixels from the left of the frame.
- cropright - Remove [cropright] rows of pixels from the right of the frame.
NOTE: Crop values must be even numbers. $frame->toGDImage() Returns a truecolor GD image of the frame.
NOTE: This function will not be available if GD is not enabled.
ffmpeg_animated_gif object methods
- output_file_path - Location in the filesystem where the animated gif will be written.
- width - Width of the animated gif.
- height - Height of the animated gif.
- frame_rate - Frame rate of the animated gif in frames per second..
- loop_count - Number of times to loop the animation. Put a zero here to loop forever or omit this parameter to disable looping.
- frame_to_add - The ffmpeg_frame object to add to the end of the animated gif.
- 【转载】FFmpegPHP的安装使用详解
- FFmpegPHP的安装使用详解
- 转载TortoiseSVN的使用详解
- ArcSDE安装详解(转载)
- group by 的使用详解--转载
- 转载TortoiseSVN的使用详解 二
- Java中vector的使用详解 (转载)
- log4j的使用详解(转载)
- 【转载】OpenVPN下载、安装、配置及使用详解
- RabbitMQ安装和使用详解(转载+实践)
- CocoaPods安装使用转载转载
- 转载:Hive的安装以及使用
- 转载 Nginx的安装与使用
- Filebench的安装与使用[转载]
- #pragma使用详解(转载)
- Firebug使用详解(转载)
- epoll使用详解[转载]
- Makefile使用详解[转载]
- Mysql_insert_id的一个缺陷 ——呃原来手册上写着
- MySQL 程序概述----读mysql手册笔记
- 一个JS题
- 数组模拟无限级分类及可伸缩——php&&js(jQuery)
- 【转】 php性能效率优化
- 【转载】FFmpegPHP的安装使用详解
- 视频几个相关术语
- 如何将想要的程序添加到“打开方式”
- 转:uploadify HTTP Error (302)错误的原因
- Java过滤器与SpringMVC拦截器之间的关系与区别
- 主机屋免费虚拟主机(一)
- IDC:互联网数据中心
- 美团robust热修复入门填坑
- 文件大小单位转换函数-getFileSize($bytes)