Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8083435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:28:28+00:00 2026-06-05T17:28:28+00:00

I am working on creating a progress bar for ffmpeg in java. So for

  • 0

I am working on creating a progress bar for ffmpeg in java. So for that I need to execute a command, then read all of the progress:

String[] command = {"gnome-terminal", "-x", "/bin/sh", "-c","ffmpeg -i /home/tmp/F.webm /home/tmp/converted1.mp4"};

Process process = Runtime.getRuntime().exec(command);

This runs perfectly. However, I need to capture the all of the progress to make a progress bar. So how can I read that data from java?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T17:28:30+00:00Added an answer on June 5, 2026 at 5:28 pm

    Here’s a complete example for you which should get you started

    import java.io.*;
    import java.util.Scanner;
    import java.util.regex.Pattern;
    
    class Test {
      public static void main(String[] args) throws IOException {
        ProcessBuilder pb = new ProcessBuilder("ffmpeg","-i","in.webm","out.mp4");
        final Process p = pb.start();
    
        new Thread() {
          public void run() {
    
            Scanner sc = new Scanner(p.getErrorStream());
    
            // Find duration
            Pattern durPattern = Pattern.compile("(?<=Duration: )[^,]*");
            String dur = sc.findWithinHorizon(durPattern, 0);
            if (dur == null)
              throw new RuntimeException("Could not parse duration.");
            String[] hms = dur.split(":");
            double totalSecs = Integer.parseInt(hms[0]) * 3600
                             + Integer.parseInt(hms[1]) *   60
                             + Double.parseDouble(hms[2]);
            System.out.println("Total duration: " + totalSecs + " seconds.");
    
            // Find time as long as possible.
            Pattern timePattern = Pattern.compile("(?<=time=)[\\d.]*");
            String match;
            while (null != (match = sc.findWithinHorizon(timePattern, 0))) {
              double progress = Double.parseDouble(match) / totalSecs;
              System.out.printf("Progress: %.2f%%%n", progress * 100);
            }
          }
        }.start();
    
      }
    }
    

    Output:

    Total duration: 117.7 seconds.
    Progress: 7.71%
    Progress: 16.40%
    Progress: 25.00%
    Progress: 33.16%
    Progress: 42.67%
    Progress: 51.35%
    Progress: 60.57%
    Progress: 69.07%
    Progress: 78.02%
    Progress: 86.49%
    Progress: 95.94%
    Progress: 99.97%
    

    You may also consider using some kind of Java bindings for ffmpeg such as jjmpeg which may provide what you need in a more robust way.

    EDIT

    With ffmpeg 2.0, time output is HH:mm:ss.S so the timePattern needs a to incorporate a :

    Pattern timePattern = Pattern.compile("(?<=time=)[\\d:.]*");
    

    In addition, the dur will need to be split on : and summed together

    String[] matchSplit;
    while (null != (match = sc.findWithinHorizon(timePattern, 0))) {
        matchSplit = match.split(":")
        double progress = Integer.parseInt(matchSplit[0]) * 3600 +
            Integer.parseInt(matchSplit[1]) * 60 +
            Double.parseDouble(matchSplit[2]) / totalSecs;
    //...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on creating a single command that will run mulitple things on the
I am working on creating a progress meter that comes from the bottom up
I'm working on creating an HTML form that has an image in the background.
I am working on creating a model where I want all of the decimal
I am currently working on creating a header file that acts like the standard
I am working on a project that is responsible for creating a job which
I'm working on creating a for-loop that calls a javascript effect and applies it
I'm working on creating a WCF web service that communicates via JSON. I got
I am working on creating a Windows Phone app that will play a series
I am working on creating a RESTful API that supports cross-domain requests, JSON/JSONP support,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.