php-ffmpeg获取视频时长

swg*_*r14 4 ffmpeg ffmpeg-php

当我尝试使用php-ffmpeg包装器和ffprobe获取视频的持续时间时,我得到一个巨大的对象而不仅仅是持续时间.

$ffprobe = FFMpeg\FFProbe::create();
    $ffprobe->format($this->videoFile)
            ->get('duration'); 
Run Code Online (Sandbox Code Playgroud)

$ this-> videoFile是/home/admin/pat./5422346433.mp4

所以它指向正确的文件,持续时间列在巨大的对象中

[[-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] => 
                    )

            )
Run Code Online (Sandbox Code Playgroud)

但显然 - > get('duration')不会返回持续时间.

我也试过了

$ffprobe
->streams($this->videoFile) // extracts streams informations
->videos()                      // filters video streams
->first()                       // returns the first video stream
->get('duration');
Run Code Online (Sandbox Code Playgroud)

swg*_*r14 8

$ffprobe
    ->streams($this->videoFile)
    ->videos()                   
    ->first()                  
    ->get('duration');
Run Code Online (Sandbox Code Playgroud)

返回持续时间.所以我必须将该命令存储到变量中.获得持续时间的正确方法是:

$duration = $ffprobe
           ->streams($this->videoFile)
           ->videos()                   
           ->first()                  
           ->get('duration');
Run Code Online (Sandbox Code Playgroud)