Saturday, May 4, 2024
 Popular · Latest · Hot · Upcoming
3
rated 0 times [  3] [ 0]  / answers: 1 / hits: 1524  / 2 Years ago, thu, may 19, 2022, 6:13:06

I would like to know how I can know the total duration of selected audio/video files in one of the Linux file managers, if it's possible.



I use Ubuntu 18.04 LTS, and its default file manager is Files AKA Nautilus.


More From » 18.04

 Answers
2

Here is a Nautilus Script

- Select files in nautilus

- Right-click on it

- In context menu, select Script > NameOfScript



enter image description here





Installation:

Install the mediainfo program if not present sudo apt install mediainfo

Save the script to a file in ~/.local/share/nautilus/scripts

Make it executable chmod +x ~/.local/share/nautilus/scripts/scriptname

Visit the scripts directory once with nautilus nautilus ~/.local/share/nautilus/scripts



#!/bin/bash

# Selected fileslist to Array
OLDIFS=$IFS
IFS=$'
'
fileArray=($NAUTILUS_SCRIPT_SELECTED_FILE_PATHS)
IFS=$OLDIFS

# Length of array: total num of selected files
NbFiles=${#fileArray[@]}

# The loop
for (( i=0; i < ${NbFiles}; i++ ));
do
# Get duration if file is media (audio or video)
buff=$(file -N -i "${fileArray[$i]}" | grep -E 'audio|video')
if [ ! -z "$buff" ]
then
# mediainfo gives duration in milliseconds, easy to sum up
MediaDuration=$(mediainfo --Output='General;%Duration%' "${fileArray[$i]}")
TotalDuration=$((TotalDuration + MediaDuration))
NbMedia=$((NbMedia + 1))
fi
done

# Format Duration: milliseconds to H:M:S
Seconds=$((TotalDuration / 1000))
FormattedDuration=$(printf '%02dh:%02dm:%02ds
' $(($Seconds/3600)) $(($Seconds%3600/60)) $(($Seconds%60)))

# Build report
ReportText="${NbFiles} File"
test $NbFiles -gt 1 && ReportText="${ReportText}s"
ReportText="${ReportText} selected
"
test $NbMedia -gt 0 && ReportText="${ReportText}${NbMedia} media file" || ReportText="${ReportText}No media file"
test $NbMedia -gt 1 && ReportText="${ReportText}s"
test $NbMedia -gt 0 && ReportText="${ReportText}
Total duration: ${FormattedDuration}"

zenity --info --no-wrap --text="${ReportText}"

[#5123] Friday, May 20, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
attagjump

Total Points: 272
Total Questions: 127
Total Answers: 124

Location: Taiwan
Member since Fri, Sep 17, 2021
3 Years ago
;