tags:

views:

168

answers:

3

When I run the conversion in the browser it simply shows the white blank space. Only after the conversion process page will load.

Please suggest how to implement a progress bar which shows the progress to the user when the video conversion takes place.

I have this in my php script

exec("ffmpeg -i filename.flv -sameq -ab 128 -s 640x480 filename.mp4");

so how should I change this script to get the progress details even to a file or directly as ouput in the page. Please can anyone give me a complete script/code to explain it in detail. Because I think I cant get the complete answers and so I am confused on what to do with this

+1  A: 

I don't believe this is possible.

The problem is that you need your PHP script to be aware of the current ffmpeg processing status. If you do an ffmpeg conversion via the command line, it displays the progress to the user, but you don't have access to that output stream when you spawn ffmpeg using commands in PHP like exec.

Rather than try to show the user a true "progress indicator", I suggest that you just lightbox a waiting indicator on the page instead. You can find many images to suit this purpose or generate one via tools like http://ajaxload.info/ .

BBonifield
It would be awkward and inefficient, but I imagine you should be able to redirect the ffmpeg output to a tempfile, which can then be read by php. I'd sooner go for the waiting indicator though - much simpler.
DrDipshit
+1  A: 

It can be done, although it would be good idea to go for a simpler ajax indicator for smaller files, but for larger files >50-80 MBs you can do this:

You can read FFMPEG return values via PHP. ffmpeg (last few lines) returns this:

Press [q] to stop encoding
frame= 1850 fps=115 q=31.0 Lsize=    5789kB time=74.00 bitrate= 640.8kbits/s   
video:5135kB audio:580kB

The time=74.00 is the current file time (NOT execution time). You can use some regex to parse that value and with some math you can get the percentage complete bar.

If you don't know the file time length. FFMPEG first few lines returns this:

Input #0, flv, from 'cf_video_3728.flv':
  Duration: 00:01:14.13, start: 0.000000, bitrate: 864 kb/s

You can parse the Duration and get the total time.

Hope this helps.

Stewie
A: 

You might be interested in reading about COMET.

It is a programming technique that allows you to push information from the server to a browser without the browser having to request it.

Here's an article explaining how to implement it with PHP via the use of a hidden iframe.

http://www.zeitoun.net/articles/comet_and_php/start

Perhaps you could use this in conjunction with the answer Stewie provided relating to reading the return values from ffmpeg.

jessegavin