0

How can I get a video duration and print it out as an php output,

like echo $duration.

So far I used this command:

ffprobe -i C:\FFMpeg\bunny.mp4 -show_format | findstr duration

to looks for the video duration.

I got some output plus this:

...
Unsupported codec with id 0 for input stream 2
Unsupported codec with id 0 for input stream 3
duration=60.095000

I do not know how to get that duration and print in down.

utdev
  • 3,942
  • 8
  • 40
  • 70
  • 1
    Possible duplicate of [How to get video duration, dimension and size in PHP?](http://stackoverflow.com/questions/4847752/how-to-get-video-duration-dimension-and-size-in-php) – Pieter van den Ham Jun 30 '16 at 08:26

3 Answers3

1

OK I did it finally, but I do not know if it is the best practice, but for me it is ok at the moment, what I did is saving the duration in a temporary text file.

Command:

cd C:\FFMpeg\bin; .\ffprobe -i " . $path . " -show_format | findstr duration > C:\xampp\htdocs\bass\storage\generator\projects\duration.txt

Now I will access that file with php and get the content of it.

utdev
  • 3,942
  • 8
  • 40
  • 70
0

Should use 'ffmpeg' instead of 'ffprobe '

ffmpeg -i C:\FFMpeg\bunny.mp4
webzar
  • 104
  • 8
0

Instead of using a temporary text file, you could use popen() to execute the command (including | findstr duration if you want), and read from the returned file pointer the same way as you read from the file, e. g.

$handle = popen($command, 'r');
$line = fgets($handle);
pclose($handle);
Armali
  • 18,255
  • 14
  • 57
  • 171