Jump to content
Sign in to follow this  

ffmpeg convert and progressbar

Recommended Posts



A problem would be to avi, flv (ffmpeg), I would like to convert to a progress indicator, which shows that, when it will be ready for conversion.

The progress indicator has been "flashing" extends until the process is running.

How can I tell where you are in the process?

$ffmpeg = @ScriptDir & "\ffmpeg.exe"
    $running = '"'& $ffmpeg &'" -i "'& $video_helye &'" -vcodec flv -f flv -r 29.97 -s 320x240 -aspect 4:3 -b 300kb -g 160 -cmp dct  -subcmp dct  -mbd 2 -flags +aic+cbp+mv0+mv4 -trellis 1 -ac 1 -ar 22050 -ab 56kb "'&$milyen_neven&'"'
;~  Run($ffmpeg, "", @SW_MAXIMIZE)
    $ff_mpeg = Run($running,"",@SW_HIDE, $STDERR_CHILD) 
    ProcessSetPriority($ff_mpeg, 0)
    $streamcounter = 0
    While ProcessExists($ff_mpeg)
        If 1 <= $streamcounter Then
            $streamcounter = 0
            $streamcounter = $streamcounter + 10
        GUICtrlSetData($Progress_konv, $streamcounter)

Share this post

Link to post
Share on other sites

First you'll need to read the StdOut stream of ffmpeg in some way.

Then you need to determine the full length of the file.

Then you need to read the current progress of the encoder.

With that data you can do the following: ($Current_progress/$Full_Length)*100 = $progres_Percentage.

$progres_Percentage is wat you want to set the progressbar to.


Local $line, $fulltime, $lastreturn

Local $infile = "1.avi"
Local $outfile = "2.avi"
Local $ffmpeg = @ScriptDir & "\ffmpeg.exe"

GUICreate("My GUI Progressbar", 220, 100, 100, 200)
$process = GUICtrlCreateProgress(10, 10, 200, 20)

Local $PID = Run($ffmpeg & " -i " & $infile & " " & $outfile, @ScriptDir, @SW_HIDE, 0x08) ;run ffmpeg as stdout child
While 1
    $line &= StdoutRead($PID) ;read stdout
    If @error Then ExitLoop ;exit loop when stdout stream ends
    If Not $fulltime Then ;runs if the total length is unknown
        $return = StringRegExp($line,"Duration: (\d{2}):(\d{2}):(\d{2})",1) ;get the full length of the file
        If IsArray($return) Then
            $fulltime = $return[0]*3600 + $return[1]*60 + $return[2] ;convert the length to seconds.
    $array = StringSplit($line,@CRLF)   ;create an array with lines like this: frame= 962 fps=374 q=31.0 size=  2242kB time=40.12 bitrate= 457.7kbits/s
    $return = StringRegExp($array[$array[0]-1],"time=(\d+)",1) ;grab the amount of seconds from the second to last line. (that one is always complete)
    If @error Then ContinueLoop
    If $return[0] <> $lastreturn Then ;if the progress changed this is true
        $lastreturn = Number($return[0])
        GUICtrlSetData($process,Int(($lastreturn/$fulltime)*100)) ;set the processbar
  • Like 1

Share this post

Link to post
Share on other sites

Thank you very much.

The StdoutRead () I tried it, but I did not know how to go after him. :mellow:

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this