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.
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.
You can do it with
ffmpeg
's-progress
argument andnc
Sadly,
ffmpeg
itself still cannot show a progress bar – also, many of the aforementioned bash- or python-based stop-gap solutions have become dated and nonfunctional.Thus, i recommend giving the brand-new ffmpeg-progressbar-cli a try:
It's a wrapper for the
ffmpeg
executable, showing a colored, centered progress bar and the remaining time.Also, it's open-source, based on Node.js and actively developed, handling most of the mentioned quirks (full disclosure: i'm its current lead developer).
It’s very simple if you use the pipeview command. To do this, transform
to
No need to get into coding!
javascript should tell php to start converting [1] and then do [2] ...
[1] php: start conversion and write status to file (see above):
For the second part we need just javascript to read the file. The following example uses dojo.request for AJAX, but you could use jQuery or vanilla or whatever as well :
[2] js: grab the progress from the file:
Had problems with the second php part. So I am using this instead:
Outputs perfectly.
Would like to see something for multiple uploads for another progress bar. This passing for the current file for one percentage. Then an overall progress bar. Almost there.
Also, if people are having a hard time getting:
To work.
Try:
"1> path" to "1>path" OR "2> path" to "2>path"
Took me awhile to figure it out. FFMPEG kept failing. Worked when I changed to no space.