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

  • Home
  • SEARCH
  • 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 6008373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:48:54+00:00 2026-05-23T01:48:54+00:00

In my previous post I learned how to extract the duration from ffmpeg for

  • 0

In my previous post I learned how to extract the duration from ffmpeg for one file.

ffmpeg -i file.mp4 2>&1 | grep Duration | awk '{print $2}' | tr -d ,

which would output something similar to 00:08:07.98.

What I would like to end up with is a script, where I can say

get_duration.sh *

and it would add all the duration lengths and output something similar to 04:108:1107.198.

It doesn’t have to convert minutes to hours and so on. It would be nice though =)

I can list all the length by

for f in *; do
  ffmpeg -i "$f" 2>&1 | grep Duration | awk '{print $2}' | tr -d ,;
done

But how do I add these strange formatted numbers?

  • 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-05-23T01:48:55+00:00Added an answer on May 23, 2026 at 1:48 am

    Using the following awk script should work fine:

    BEGIN { h=0; m=0; s=0; cs=0; }
    /Duration:/  { 
      split($2, time_arr, ":");
      h = h + time_arr[1];
      m = m + time_arr[2];
      split(time_arr[3],time_arr2,".");
      s = s + time_arr2[1];
      cs = cs + time_arr2[2];
      }
    END {
      s = s + int(cs/100);
      cs = cs % 100;
      m = m + int(s / 60);
      s = s % 60;
      h = h + int(m / 60);
      m = m % 60;
      printf "%02d:%02d:%02d.%02d\n", h, m, s, cs;
    }
    

    Put this in add_durations.awk, then you can do:

    for f in *; do ffmpeg -i "$f" 2>&1; done | awk -f add_durations.awk
    

    Note this will also convert the hours etc for you :).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this function from a plugin (from a previous post) // This method
After seeing a previous post Making Applications programmed in .NET languages work on older
This question is related to a previous post of mine Here . Basically, I
As an addition to my previous post on Creating a web server in pure
After I messed up the description of my previous post on this I have
I'm experiencing the same problem in this previous stackoverflow.com post . Specifically, I seem
In previous releases there were 3 ways to pass data from controller to view
I'm using some code to extract from a Google Url the keyword of the
I couldn't get the POST value in servlet page. my previous question related to
In previous versions of jQuery tabs there was an option to automatically set the

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.