php-ffmpeg获取视频时长 [英] php-ffmpeg get video duration
本文介绍了php-ffmpeg获取视频时长的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我尝试使用php-ffmpeg包装器和ffprobe获取视频的时长时,我得到了一个巨大的对象,而不仅仅是时长.
When I try to get the duration of a video using the php-ffmpeg wrapper and ffprobe, I get a huge object instead of just the duration.
$ffprobe = FFMpeg\FFProbe::create();
$ffprobe->format($this->videoFile)
->get('duration');
$ this-> videoFile是/home/admin/........./5422346433.mp4
$this->videoFile is /home/admin/........./5422346433.mp4
因此它指向正确的文件,持续时间在下方的巨型对象中列出
So it points to right file and the duration is listed in the giant object down in
[[-show_format-/home/admin/web/admin.simplewebevents.com/public_html/cron/649652027.mp4][1]] => Array
(
[0] => FFMpeg\FFProbe\DataMapping\Format Object
(
[properties:FFMpeg\FFProbe\DataMapping\AbstractData:private] => Array
(
[filename] => /home/admin/web/admin.simplewebevents.com/public_html/cron/649652027.mp4
[nb_streams] => 2
[nb_programs] => 0
[format_name] => mov,mp4,m4a,3gp,3g2,mj2
[format_long_name] => QuickTime / MOV
[start_time] => 0.000000
[duration] => 5736.833333
[size] => 668381267
[bit_rate] => 932056
[probe_score] => 100
[tags] => Array
(
[major_brand] => mp42
[minor_version] => 0
[compatible_brands] => mp42mp41isomavc1
[creation_time] => 2016-12-04 18:25:58
)
)
)
[1] =>
)
)
但是显然-> get('duration')不会返回持续时间.
But apparently ->get('duration') doesnt return the duration.
我也尝试过
$ffprobe
->streams($this->videoFile) // extracts streams informations
->videos() // filters video streams
->first() // returns the first video stream
->get('duration');
推荐答案
$ffprobe
->streams($this->videoFile)
->videos()
->first()
->get('duration');
返回持续时间.因此,我必须将该命令存储到变量中.获取持续时间的正确方法是:
RETURNS the duration. So I have to store that command into a variable. The correct way to get the duration is:
$duration = $ffprobe
->streams($this->videoFile)
->videos()
->first()
->get('duration');
这篇关于php-ffmpeg获取视频时长的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文