0

How can I find all video files with such that the duration is in a specific interval.

For example find all video files with a duration between 20 and 40 minutes.

2

The following script will do the job for you. It assumes the videos are in a directory (not all over your system).

The script also assumes you have avprobe installed, which is part of avconv. Should be same syntax as ffprobe (part of ffmpeg) if you have that instead. If the output from ffprobe is different the script will need editing.

The duration is require in seconds however - saves make a calculation.

#!/bin/sh

# NOTE: Assumes you have avprobe installed and the full path
# to it is /usr/bin/avprobe - if not, edit.

# Where are the videos?
MASTER="/home/tigger/Videos"
# Duration min in seconds (1200 = 20min)
DUR_MIN="1200"
# Duration max in seconds (2400 = 40min)
DUR_MAX="2400"

# Get a list of files
LIST=`find "$MASTER" -type f`

# In case of a space in file names, split on return
IFS_ORIG=$IFS
IFS="
"

valid="\nList of videos with duration between $DUR_MIN and $DUR_MAX seconds"

# Loop over the file list and probe each file.
for v in $LIST
do
    printf "Checking ${v}\n"
    dur=`/usr/bin/avprobe -v error -show_format_entry duration "${v}"`
    if [ -n $dur ]
    then
        # Convert the float to int
        dur=${dur%.*}
        if [ $dur -ge $DUR_MIN -a $dur -le $DUR_MAX ]
        then
            valid="${valid}\n$v"
        fi
    fi
done

printf "${valid}\n"
exit

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.