There are a number of Youtube channels that I archive using a daily cron script that runs youtube-dl. However, in checking over the videos to make sure my script is working, I noticed for one of the channels I archive, a couple of the most recent videos was being downloaded in 360p instead of 1080p60. I checked the video on Youtube and it was indeed 360p. A few days later, the video finished processing and was at 1080p60.

How can I list all videos in a folder that are under 1080p in resolution so that I can delete them and redownload once Youtube has finished processing?

Is there a way to scipt this with ffmpeg or some other tool?

If there are any suggestions for how to not have this issue in the future, that would be appreciated too.


As mentioned in this answer you can use command like this to get the dimentions of videofile:

ffprobe -v error -select_streams v:0 -show_entries stream=width -of default=nw=1:nk=1 input.mp4

And this will give you output like


and then you can decide what to do with this video

  • The question is "how to list all files…?" You answered "how to test one file?" I was tempted to take your solution, complete the job and answer separately; seems inelegant though. Here's the full solution: find . -type f -exec sh -c '[ "$(ffprobe -v error -select_streams v:0 -show_entries stream=width -of default=nw=1:nk=1 "$1")" -lt 1080 ]' sh {} \; -print. Use it at will to improve the answer. Preemptive filtering according to name (extension) or mime type is possible, see this answer. May 1 '19 at 20:55
exiftool -q -r -if '$MIMEType =~ m{^video/} and
                    $ImageHeight < 1080 and
                    print "$Directory/$FileName\0" and 0' . |
  xargs -r0 echo rm -f

(assuming GNU xargs or compatible).

Would remove all videos whose Image Height is less that 1080 pixels (if you removed the echo) in the current directory, recursively. That assumes file names are (properly) encoded in UTF-8 (though see the -charset option for other charsets).

Instead of piping to xargs rm, you can also store in a file (> list), to do some inspection on that list first:

xargs -r0a list ls -ldrS

If it looks fine:

xargs -r0a list rm

Or store the information in JSON format so you have all the relevant information in an easily readable and parseable format:

exiftool -q -r -j -if '$MIMEType =~ m{^video/}' \
  -ImageWidth -ImageHeight -VideoFrameRate -MIMEType . > list.json

Then review that list, and delete based on some criteria:

PERL_UNICODE= json_xs < list.json -t none -e '
  for (@{$_}) {
    unlink $_->{SourceFile} if
      $_->{ImageHeight} < 1080 || $_->{VideoFrameRate} < 60

(note that I found that for FLV files, it was Videoframerate instead of VideoFrameRate, you may want to watch out for this kind of inconsistency).

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.