A bit hacky, but:
for f in *.avi; do
echo "Testing $f"
ffmpeg -i "$f" 2>&1 | awk '/Duration/ { split($2,a,":"); exit a[1]*3600+a[2]*60+a[3] < 30 ? 3 : O }'
[[ $? -eq 3 ]] && rm -i -- "$f"
done
This assumes you have ffmpeg
installed. rm
will ask you before removing a file, but you can remove the -i
if you're sure it does what you want.
A portable Ruby script that will not ask for confirmation – but you can replace f.delete
with puts f
to check what it would do:
ruby <<"EOF"
Dir.glob("*.avi").each { |f|
ff = %x( ffmpeg -i "#{f}" 2>&1 )
d = ff.match(/Duration: ([0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{2})/)[1].split(":").map{|s| s.to_i}
s = (d[0]*60*60 + d[1]*60 + d[2])
f.delete if s < 30
}
EOF