Search code examples
phpvideoffmpegffmpeg-php

How to get video size of compressed video by ffmpeg?


Hi we are using ffmpeg for compressing the video through php script, now what i need is i want to get the video size of compressed image, but am getting an video path so kindly guide me how i need to over come this?

Below is the code what i used for compressing the video

original path

$path = "sample.mp4";

Command to compress

exec("ffmpeg -i sample.mp4 -vcodec h264 -acodec aac -strict -2 compressed_video.mp4);

The command what i used for getting video size

$compressed_video_information = exec("ls -h1 compressed_video.mp4);
echo $compressed_video_information;

I get just file path instaed of getting video file size, so someone help me how to overcome this issue?


Solution

  • -h option (ex: ls -lh) displays size in human readable form(KB/MB/GB etc..)

    exec("ls -lh compressed_video.mp4",$out);// pass file path here
    $size=explode(' ',$out[0]);
    print_r($size[4]);