1

Is it possible to get the video dimensions from a video file? I'm uploading mp4s and wmvs as well as some image files. I would like to grab the dimensions and make it part of the new filename.

I know you can use getImageSize() for pictures but how would I do the same for video. Is there a way to do this?

VC.One
  • 14,790
  • 4
  • 25
  • 57
codernoob8
  • 434
  • 1
  • 9
  • 24
  • You can check https://stackoverflow.com/questions/4847752/how-to-get-video-duration-dimension-and-size-in-php . I'd avoid the accepted answer as it's really old, there are some newer ones in there though. – apokryfos Oct 05 '18 at 16:00

2 Answers2

1

use ID3 libs, for example getID3:

very simple to use :

    $getID3 = new getID3;
    $ThisFileInfo = $getID3->analyze($localtempfilename);

if dont use shared host, use ffmpeg to get info (PHP-FFMpeg/PHP-FFMpeg):

$ffprobe = FFMpeg\FFProbe::create();
$video_dimensions = $ffprobe
    ->streams( $full_video_path )   // extracts streams informations
    ->videos()                      // filters video streams
    ->first()                       // returns the first video stream
    ->getDimensions();              // returns a FFMpeg\Coordinate\Dimension object

feature of ffmpeg:

  1. resize
  2. List item
  3. convert
  4. frame pic (screenshot)
  5. watermark
  6. ...
  • Ive seen this however dont you have to upload it to a loction first and than move it? – codernoob8 Oct 05 '18 at 16:04
  • uploaded files save in to temp folder .... get file info when it's in temp folder ... then move it.... –  Oct 05 '18 at 16:16
  • is there a way to wrap it in a function that returns file width and height for both images and videos? – codernoob8 Oct 05 '18 at 17:13
  • yes , first check file mimetype if video/xxxx run ffpmeg or other ID3 and if mimetype is image/xxxx use getImageSize –  Oct 05 '18 at 17:30
  • @codernoob8 note: id3 can get image, video and audio info –  Oct 05 '18 at 17:31
1
<?php require_once('getid3/getid3.php');
$filename='uploads/4thofJuly_184.mp4';
$getID3 = new getID3;
$file = $getID3->analyze($filename);
echo("Duration: ".$file['playtime_string'].
" / Dimensions: ".$file['video']['resolution_x']." wide by ".$file['video']['resolution_y']." tall".
" / Filesize: ".$file['filesize']." bytes<br />");
$getID3 = new getID3;
$filename='uploads/25PercentOff_710.wmv';
$file = $getID3->analyze($filename);
echo("Duration: ".$file['playtime_string'].
" / Dimensions: ".$file['video']['resolution_x']." wide by ".$file['video']['resolution_y']." tall".
" / Filesize: ".$file['filesize']." bytes<br />");

// Calling getimagesize() function 
$filename="uploads/25PercentOff_960.jpg";
list($width, $height) = getimagesize($filename); 

// Displaying dimensions of the image 
echo "Width of image : " . $width . "<br>"; 

echo "Height of image : " . $height . "<br>"; 
?>
codernoob8
  • 434
  • 1
  • 9
  • 24