Get Audio and video metadata with PHP

ffprobe as a part of ffmpeg is an extremely powerful command line tool that can modify, encode, convert all sorts of video and audio files. You can simply call it in PHP with shell_exec. In my example I wanted to have the creation date and time as part of file names. If you throw together home videos from varoius sources (cellphones, cameras etc) this is the best way to get chronological order automatically. Of course you should adjust the paths and file extension to your own needs. $path='g:/+video-home/'; $path2=str_replace('/','\\',$path); $d = dir($path); while (false !== ($file = $d->read())) { if (substr($file,-4)=='.MOV') { $x=shell_exec('c:\\[pathto]\\ffprobe.exe -show_format '.$path2.$file); //$x will simply be a string with format information $date=substr($x,strpos($x,'creation_time=')+14,19); if ($date) { $date=str_replace(':','',$date); $date=str_replace('-','',$date); $date=str_replace(' ','_',$date); rename ($path2.$file,$path2.$date.'.MOV');}}} $d->close(); This is just one example out of many possibilities to use ffprobe. -show_entries can also be used. Check the documentation.
Questions? Corrections? Ideas? Comments? PeerAxel@aol.com main index
Disclaimer

This site is based at: radiovibrations.com/php/com-port-access.htm