Snippets

Krzysztof Ożóg Example FFProbe classs usage

Updated by Krzysztof Ożóg

File snippet.php Modified

  • Ignore whitespace
  • Hide word diff
         }
 
         $video->setDuration((int) $videoFormat['duration']);
+        $video->setCodec($videoFormat['codec_name']);
+        $video->setWidth((int) $videoFormat['width']);
+        $video->setHeight((int) $videoFormat['height']);
 
         [...]
    
Updated by Krzysztof Ożóg

File snippet.php Modified

  • Ignore whitespace
  • Hide word diff
+<?php
+
 public function getVideoMetadata(Video $video)
 {
         [...]
         $videoData = json_decode($ffprobe->probeStreams($filepath), true);
         $video->setData($videoData);
 
-        $video_video = array();
+        $videoFormat = array();
         // get first video stream 
         foreach ($videoData as $format) {
             if ($format['codec_type'] == 'video') {
-                $video_video = $format;
+                $videoFormat = $format;
                 break;
             }
         }
 
-        $video->setDuration((int) $video_video['duration']);
+        $video->setDuration((int) $videoFormat['duration']);
 
         [...]
    
Created by Krzysztof Ożóg

File snippet.php Added

  • Ignore whitespace
  • Hide word diff
+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);
+
+        $video_video = array();
+        // get first video stream 
+        foreach ($videoData as $format) {
+            if ($format['codec_type'] == 'video') {
+                $video_video = $format;
+                break;
+            }
+        }
+
+        $video->setDuration((int) $video_video['duration']);
+
+        [...]
+   
+}
HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.