Snippets

Krzysztof Ożóg Example FFProbe classs usage

Created by Krzysztof Ożóg last modified
<?php

public function getVideoMetadata(Video $video)
{
        [...]
        $rootPath = $this->getVideosRootPath();
        $ext = pathinfo($video->getOriginal());
        $filepath  = $rootPath.'/'.$video->getUploadToken().'.'.$ext['extension'];
        $video->setSize(filesize($filepath));

        $ffprobe = $this->getFFProbe(); // just construct of FFMProbe class
        $videoData = json_decode($ffprobe->probeStreams($filepath), true);
        $video->setData($videoData);

        $videoFormat = array();
        // get first video stream 
        foreach ($videoData as $format) {
            if ($format['codec_type'] == 'video') {
                $videoFormat = $format;
                break;
            }
        }

        $video->setDuration((int) $videoFormat['duration']);
        $video->setCodec($videoFormat['codec_name']);
        $video->setWidth((int) $videoFormat['width']);
        $video->setHeight((int) $videoFormat['height']);

        [...]
   
}

Comments (0)