Sangat Pedas

Using FFProbe In PHP To Get Video File Info [Script]

ffprobe-file-info-phpIn case you haven’t figure it out yet, my next project is a video thingy. Not sure if it will become a business but I like to extend my knowledge and development skills so I’m just building it without worrying too much about making money with this.

Anyway, in my previous post I shared how to install FFMpeg on a (shared web) server because core of any video platform is encoding so you can deliver (fast) to every platform and device. In the meanwhile I already played around with encoding and will write a post on that later.

But if you start encoding the different video files you need to be able to deliver on all platforms, devices and adapting to all bandwidths, you need to know your starting point. No use for instance in generating a mp4 file with a resolution of 1920 x 1080 pixels if the size of the original file is just 640 x 360 pixels. The same applies to the audio stream of the file, no use saving your target file with a higher bit rate for audio than the original file as it will just eat bandwidth without any upside.

So I needed to make a php function that would make all the vital information of the (uploaded) video file easily available. But what seemed like a simple task in the end took me more than a day. It didn’t take me long using ffpmeg to get the info, but unfortunately the info was not complete. So I had to go with ffprobe but using that module through php was a hell of a job for me to get it working since it constantly failed because it couldn’t find a certain library.

Anyway, here’s the result and feel free to drop improvements in the comments.

So the requirement is that you’ve setup FFmpeg as in my previous post where the config setting “-enable-shared” is vital, without that this won’t work.

So there you have the function, I didn’t put all output in the array as I won’t need them all. But if you missing anything I guess you get it now how to add an extra one. Here’s how you can check whether it’s working properly:

This will create similar output as below:

To just get the video bit rate for instance, just address the array as follows:

There you go, I hope I’ve saved you some time and stay tuned for the next video geek post.

Comments are closed.