2

I need to get a list of filenames and path along with the duration of the file. All are video files. Some files are in subfolders as well. I need the list sorted according to duration. My goal is to delete the files which have a duration lower than 2 minutes. Is there someway I can do it through terminal or GUI?

1

You are out of luck without using external programmes, file videoname.xyz does not return the duration of the videos. On the other hand, avprobe (ffprobe) from the package libav-tools does!

You would need to perform a recursive directory walk (e.g. in Python), call avprobe (via a subprocess), parse the duration from the output and store play length and filename in a suitable structure.

1

this should give you a list of mp4s less than 120 seconds in the folder specified including sub folders

find ~/pathtofolder -iname '*.mp4' -type f > vidfiles && while read f; do echo -n "$f: "; ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "$f"; done < vidfiles | awk '$NF<120' > shortvids

Just change the ~/pathtofolder to your target location.

The list will be in a file called shortvids

I apologize for not sorting but I don't see the need if the only files in the list are the short videos.

If you would like to change the duration, near the end change '$NF<120' to the number of seconds. For example '$NF<300' would mean "duration less than 5 minutes(or 300 seconds)"

of course you can also find durations greater than or equal to by changing the sign ie. < to > or =

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.