views:

2978

answers:

4

Hello all,

I am converting a .avi file to .flv file using ffmpeg. As it takes a long time to convert a file I would like to display a progress bar. Can someone please guide me on how to go about the same.

I know that ffmpeg somehow has to output the progress in a text file and I have to read it using ajax calls. But how do I get ffmpeg to output the progress to the text file?

Thank you very much.

+1  A: 

Calling php's system function blocks that thread, so you'll need to spawn off 1 HTTP request for performing the conversion, and another polling one for reading the txt file, that's being generated.

Or, better yet, clients submit the video for conversion and then another process is made responsible for performing the conversion. That way the client's connection won't timeout while waiting for the system call to terminate. Polling is done in the same way as above.

Allain Lalonde
+6  A: 

FFmpeg uses stdout for outputing media data and stderr for logging/progress information. You just have to redirect stderr to a file or to stdin of a process able to handle it.

With a unix shell this is something like:

ffmpeg {ffmpeg arguments} 2> logFile

or

ffmpeg {ffmpeg arguments} 2| processFFmpegLog

Anyway, you have to run ffmpeg as a separate thread or process.

mouviciel
A: 

FFMPEG-ProgressBar with Ajax/JavaScript/PHP: https://sourceforge.net/projects/ffmpegprogress/

Dave
+2  A: 

There is an article in Russian which describes how to solve your problem.

The point is to catch Duration value before encoding and to catch time=... values during encoding.

--skipped--
Duration: 00:00:24.9, start: 0.000000, bitrate: 331 kb/s
--skipped--
frame=   41 q=7.0 size=     116kB time=1.6 bitrate= 579.7kbits/s
frame=   78 q=12.0 size=     189kB time=3.1 bitrate= 497.2kbits/s
frame=  115 q=13.0 size=     254kB time=4.6 bitrate= 452.3kbits/s
--skipped--
balazar