0

Based from: Get total duration of video files in a directory

But I need my output to be in hours. Been trying for some time to make this one line output to hours:

find . -maxdepth 1 -exec ffprobe -v quiet -of csv=p=0 -show_entries format=duration {} \; | paste -sd+ -| bc

Any help? Hope it's not a duplicate because all the answer there only output in seconds which is bad and I don't have hope anyone will add to that question anymore

3
  • 2
    To get hours from seconds, you just need to divide by 60 × 60. Commented Nov 20, 2020 at 9:42
  • But how to do that after BC? The output is stored in the stdin, which is why i'm struggling to use it Commented Nov 20, 2020 at 9:48
  • See stackoverflow.com/questions/12199631/… Commented Nov 20, 2020 at 9:50

2 Answers 2

2

Instead of | paste -sd+ -| bc, you can use awk:

find ... | awk '{s+=$0} END {print s/3600}'

This will print hours with decimals, but if you want more advanced output like Hours:Minutes:Seconds, check e.g. here or here or check the exiftool option from the link in your Question.

1
  • Perfect. Indeed much simpler than trying to do math with the output of bc stored in /dev/stdin Commented Nov 20, 2020 at 9:54
2

That boils down to how to divide a number from the output of a command by 3600.

Which you could do with:

... | awk '{print $0 / 3600}'

Though here, you can do the whole thing with:

exiftool -r -n -q -p '${Duration;$_ = (our $total += $_) / 3600}' . | tail -n 1

(or $_ = ConvertDuration(our $total += $_) to express it like 4 days 22:14:59).

1
  • My issue was that most of the answers for how to divide the output of a command by 3600 is that my value was in the /dev/stdin and not really a variable Commented Nov 20, 2020 at 9:55

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.