Get total duration of video files in a directory in hours

Get total duration of video files in a directory in hours

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

答案1

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.

答案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).

相关内容