1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

looking for ffmpeg Progress Bar ????

Discussion in 'PHP' started by shuman202, Dec 18, 2012.

  1. #1
    hello,
    i've been looking everywhere on the internet about how to show a progress bar while converting a video
    i found those answes
    http://stackoverflow.com/questions/11441517/ffmpeg-progress-bar-encoding-percentage-in-php
    http://stackoverflow.com/questions/747982/can-ffmpeg-show-a-progress-bar
    http://stackoverflow.com/questions/3770927/ffmpeg-video-encoding-progress-bar
    i tried all of them but nothing did work for me
    i found a php class
    http://sourceforge.net/projects/ffmpegprogress/
    but if full of bugs and errors
    i use that code'
    exec('ffmpeg -i office.flv -r 24 output.avi');
    Code (markup):
    to convert flv to avi it works but i need a progress bar
    i hope someone can help me
     
    shuman202, Dec 18, 2012 IP
  2. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #2
    Since the conversion is running in an external program, you won't be getting progress data, so you can't run a progress bar. To do that you have to do the conversion in your program, and you have to write the code so it updates the progress bar.
     
    Rukbat, Dec 20, 2012 IP
  3. Popmedic

    Popmedic Greenhorn

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #3
    try this function, not a progress bar but... you can use a gem for that...

    def exec_ffmpeg src_path, dst_path
        cmd = "ffmpeg -i \"%s\" -acodec libfaac -ac 2 -ab 128k -vcodec libx264 -threads 0 \"%s\" 2>&1" %
                                [src_path, dst_path]
     
        puts "%s" % cmd.gsub(/2\>\&1$/,'')
        puts "press 'q' to quit"
        progress = nil
        dur_secs = nil
        frame_rate = nil
        frames = 0
        dur_str = '00:00:00.000'
        ostr = ''
        ffmpeg = IO.popen(cmd)
        ffmpeg.each("\r") do |line|
            if dur_secs == nil && line =~ /Duration:\s*(\d*):(\d*):(\d*\.\d*)/
                dur_str = $1.to_s + ":" + $2.to_s + ":" + $3.to_s
                dur_secs = ($3.to_f + ($2.to_i * 60).to_f + ($1.to_i * 360).to_f)
                puts "Video Duration:" + dur_str
            end
            if frame_rate == nil && line =~ /Stream.+\, (\d+\.{0,1}\d{0,3}) fps\,/
                frame_rate = $1.to_f
                frames = dur_secs * frame_rate
                puts "Total Frames: %i" % frames.to_i
                puts "Frame Rate: %.3f fps" % frame_rate
            end
            if line =~ /frame=(\s.?(\d*))/
                cframe = $1.to_i
                csecs = 0
                if line =~ /time=\s*(\d*):(\d*):(\d*\.\d*)/
                    csecs = ($3.to_f + ($2.to_i * 60).to_f + ($1.to_i * 360).to_f)
                    csecs_str = $1.to_s + ":" + $2.to_s + ":" + $3.to_s
                elsif line =~ /time=\s*(\d*\.\d*)/
                    csecs $1.to_f
                    t = Time.at(csecs).gmtime
                    csecs_str = "%0.2i:%0.2i:%0.2i.%3i" % [t.hour, t.min, t.sec, t.nsec]
                end
                if line =~ /fps=\s*(\d*)/
                    cfps = $1.to_i
                else
                    cfps = 0
                end
                if line =~ /bitrate=\s*(\d*\.\d*kbits)/
                    br = $1
                else
                    br = "???"
                end
                ostr = "  %3.2f%% ( %s ) @frame:%i fps:%i bitrate:%s" %
                    [((csecs/dur_secs)*100), csecs_str, cframe, cfps, br]
                print ostr + ("\b" * (ostr.length + 4))
            end
        end
        print "\n"
    end
    
    Code (markup):
    My current version of ffmpeg:

    ffmpeg version 0.10.2 Copyright (c) 2000-2012 the FFmpeg developers
    built on May 5 2012 07:55:39 with clang 3.1 (tags/Apple/clang-318.0.58)
    configuration: --prefix=/Volumes/MetaPop/ffmpeg-build/sw/ --enable-gpl --enable-pthreads --enable-version3 --enable-libspeex --enable-libvpx --disable-decoder=libvpx --enable-libfaac --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libx264 --enable-avfilter --enable-libopencore_amrwb --enable-libopencore_amrnb --enable-filters --arch=x86 --enable-runtime-cpudetect --cc=clang --enable-nonfree
    libavutil 51. 35.100 / 51. 35.100
    libavcodec 53. 61.100 / 53. 61.100
    libavformat 53. 32.100 / 53. 32.100
    libavdevice 53. 4.100 / 53. 4.100
    libavfilter 2. 61.100 / 2. 61.100
    libswscale 2. 1.100 / 2. 1.100
    libswresample 0. 6.100 / 0. 6.100
    libpostproc 52. 0.100 / 52. 0.100


    If you are using a different version of ffmpeg the output could be different. Adjust the regular expressions for your version of ffmpeg. If you can't figure the regular expressions out, post what the output from your version looks like and I can try and help.
     
    Last edited: Feb 28, 2013
    Popmedic, Feb 28, 2013 IP
  4. shuman202

    shuman202 Well-Known Member

    Messages:
    638
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    145
    Digital Goods:
    1
    #4
    thank you for that i'll try it
     
    shuman202, Mar 1, 2013 IP
  5. Popmedic

    Popmedic Greenhorn

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #5
    I think the tricky part was that ffmpeg writes its output to stdout and stderr, so the " 2>&1" takes care of that. Here's my latest debugged version of this in Ruby is at: https://github.com/popmedic/ffmpeg-cl-wrappers
     
    Popmedic, Mar 8, 2013 IP
  6. shuman202

    shuman202 Well-Known Member

    Messages:
    638
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    145
    Digital Goods:
    1
    #6
    yeah this is the trick you should use the stdout to get the total video time and the current time and you can build the progress bar by using those 2
     
    shuman202, Mar 9, 2013 IP
  7. MCMatt

    MCMatt Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #7
    Have you tried this one? It was updated more recently
    https://sourceforge.net/projects/ffmpegprogress2/
     
    MCMatt, Feb 27, 2017 IP