本篇文章主要介绍php 调用ffmpeg获取视频信息的方法,感兴趣的朋友参考下,希望对大家有所帮助。
ffmpeg是一套可以用来记录、转换数字音频、视频,并能将其转化为流的开源计算机程序,包含了libavcodec,保证高可移值性和编解码质量。
本文将介绍使用php调用ffmpeg获取视频信息,调用ffmpeg首先需要服务器上安装了ffmpeg,安装方法很简单,可自行搜索。
代码如下:
<?php // 定义ffmpeg路径及命令常量 define('FFMPEG_CMD', '/usr/local/bin/ffmpeg -i "%s" 2>&1'); /** * 使用ffmpeg获取视频信息 * @param String $file 视频文件 * @return Array */ function getVideoInfo($file){ ob_start(); passthru(sprintf(FFMPEG_CMD, $file)); $video_info = ob_get_contents(); ob_end_clean(); // 使用输出缓冲,获取ffmpeg所有输出内容 $ret = array(); // Duration: 00:33:42.64, start: 0.000000, bitrate: 152 kb/s if (preg_match("/Duration: (.*?), start: (.*?), bitrate: (\d*) kb\/s/", $video_info, $matches)){ $ret['duration'] = $matches[1]; // 视频长度 $duration = explode(':', $matches[1]); $ret['seconds'] = $duration[0]*3600 + $duration[1]*60 + $duration[2]; // 转为秒数 $ret['start'] = $matches[2]; // 开始时间 $ret['bitrate'] = $matches[3]; // bitrate 码率 单位kb } // Stream #0:1: Video: rv20 (RV20 / 0x30325652), yuv420p, 352x288, 117 kb/s, 15 fps, 15 tbr, 1k tbn, 1k tbc if(preg_match("/Video: (.*?), (.*?), (.*?)[,\s]/", $video_info, $matches)){ $ret['vcodec'] = $matches[1]; // 编码格式 $ret['vformat'] = $matches[2]; // 视频格式 $ret['resolution'] = $matches[3]; // 分辨率 list($width, $height) = explode('x', $matches[3]); $ret['width'] = $width; $ret['height'] = $height; } // Stream #0:0: Audio: cook (cook / 0x6B6F6F63), 22050 Hz, stereo, fltp, 32 kb/s if(preg_match("/Audio: (.*), (\d*) Hz/", $video_info, $matches)){ $ret['acodec'] = $matches[1]; // 音频编码 $ret['asamplerate'] = $matches[2]; // 音频采样频率 } if(isset($ret['seconds']) && isset($ret['start'])){ $ret['play_time'] = $ret['seconds'] + $ret['start']; // 实际播放时间 } $ret['size'] = filesize($file); // 视频文件大小 $video_info = iconv('gbk','utf8', $video_info); return array($ret, $video_info); } // 输出视频信息 $video_info = getVideoInfo('myvideo.avi'); print_r($video_info[0]); ?>
输出:
Array ( [duration] => 00:33:42.64 [seconds] => 2022.64 [start] => 0.000000 [bitrate] => 152 [vcodec] => rv20 (RV20 / 0x30325652) [vformat] => yuv420p [resolution] => 352x288 [width] => 352 [height] => 288 [acodec] => cook (cook / 0x6B6F6F63) [asamplerate] => 22050 [play_time] => 2022.64 [size] => 38630744 )
以上就是本文的全部内容,希望对大家的学习有所帮助。
相关推荐:
PHP区分 企业微信浏览器 | 普通微信浏览器 | 其他浏览器
以上是php 实现调用ffmpeg获取视频信息的方法的详细内容。更多信息请关注PHP中文网其他相关文章!

Thedifferencebetweenunset()andsession_destroy()isthatunset()clearsspecificsessionvariableswhilekeepingthesessionactive,whereassession_destroy()terminatestheentiresession.1)Useunset()toremovespecificsessionvariableswithoutaffectingthesession'soveralls

stickysessensureuserRequestSarerOutedTothesMeServerForsessionDataConsisterency.1)sessionIdentificeAssificationAssigeaSsignAssignSignSuserServerServerSustersusiseCookiesorUrlModifications.2)一致的ententRoutingDirectSsssssubsequeSssubsequeSubsequestrequestSameSameserver.3)loadBellankingDisteributesNebutesneNewuserEreNevuseRe.3)

phpoffersvarioussessionsionsavehandlers:1)文件:默认,简单的ButMayBottLeneckonHigh-trafficsites.2)Memcached:高性能,Idealforsforspeed-Criticalapplications.3)REDIS:redis:similartomemememememcached,withddeddeddedpassistence.4)withddeddedpassistence.4)databases:gelifforcontrati forforcontrati,有用

PHP中的session是用于在服务器端保存用户数据以在多个请求之间保持状态的机制。具体来说,1)session通过session_start()函数启动,并通过$_SESSION超级全局数组存储和读取数据;2)session数据默认存储在服务器的临时文件中,但可通过数据库或内存存储优化;3)使用session可以实现用户登录状态跟踪和购物车管理等功能;4)需要注意session的安全传输和性能优化,以确保应用的安全性和效率。

PHPsessionsstartwithsession_start(),whichgeneratesauniqueIDandcreatesaserverfile;theypersistacrossrequestsandcanbemanuallyendedwithsession_destroy().1)Sessionsbeginwhensession_start()iscalled,creatingauniqueIDandserverfile.2)Theycontinueasdataisloade

绝对会话超时从会话创建时开始计时,闲置会话超时则从用户无操作时开始计时。绝对会话超时适用于需要严格控制会话生命周期的场景,如金融应用;闲置会话超时适合希望用户长时间保持会话活跃的应用,如社交媒体。

服务器会话失效可以通过以下步骤解决:1.检查服务器配置,确保会话设置正确。2.验证客户端cookies,确认浏览器支持并正确发送。3.检查会话存储服务,如Redis,确保其正常运行。4.审查应用代码,确保会话逻辑正确。通过这些步骤,可以有效诊断和修复会话问题,提升用户体验。

session_start()iscucialinphpformanagingusersessions.1)ItInitiateSanewsessionifnoneexists,2)resumesanexistingsessions,and3)setsasesessionCookieforContinuityActinuityAccontinuityAcconActInityAcconActInityAcconAccRequests,EnablingApplicationsApplicationsLikeUseAppericationLikeUseAthenticationalticationaltication and PersersonalizedContentent。


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

WebStorm Mac版
好用的JavaScript开发工具

MinGW - 适用于 Windows 的极简 GNU
这个项目正在迁移到osdn.net/projects/mingw的过程中,你可以继续在那里关注我们。MinGW:GNU编译器集合(GCC)的本地Windows移植版本,可自由分发的导入库和用于构建本地Windows应用程序的头文件;包括对MSVC运行时的扩展,以支持C99功能。MinGW的所有软件都可以在64位Windows平台上运行。

ZendStudio 13.5.1 Mac
功能强大的PHP集成开发环境

禅工作室 13.0.1
功能强大的PHP集成开发环境

EditPlus 中文破解版
体积小,语法高亮,不支持代码提示功能