How do you calculate duration / length of mp4 video using php?

How do you get / calculate duration / length of mp4 video with php?

I tried using this , but it only works for f4v .: & L; Can you help me with mp4?

+4
source share
3 answers

I could not get to work with tandu.

Here is what ultimately worked for me:

$ffmpeg_output = shell_exec("ffmpeg -i \"$file\" 2>&1"); if( preg_match('/.*Duration: ([0-9:]+).*/', $ffmpeg_output, $matches) ) { echo $matches[1]; } else { echo "$file failed\n"; } 

Hope this helps someone.

+4
source

I also wanted to do this recently. I have done a lot of research on this and there is no native way in php. One of the suggestions of ffmpeg-php , but it doesn't seem to work for me. Another method is to use the ffmpeg command line:

 exec("ffmpeg -i \"{$videofile}\" 2>&1"); $search='/Duration: (.*?),/'; $duration=preg_match($search, $duration, $matches, PREG_OFFSET_CAPTURE, 3); 
+2
source

This can be done in pure php using the php-reader library. This library is a complete implementation of ISO Base Media File Format, or ISO/IEC 14496-12 in pure php. You can then trust the metadata header all the time or calculate it yourself based on stbl blocks.

+1
source

Source: https://habr.com/ru/post/1339311/


All Articles