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

Freedo
  • 1,205
  • 6
  • 31
  • 57

2 Answers2

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.

pLumo
  • 22,231
  • 2
  • 41
  • 66
  • Perfect. Indeed much simpler than trying to do math with the output of bc stored in /dev/stdin – Freedo Nov 20 '20 at 09: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).

Stéphane Chazelas
  • 522,931
  • 91
  • 1,010
  • 1,501
  • 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 – Freedo Nov 20 '20 at 09:55