Skip to content

Instantly share code, notes, and snippets.

@aktau
Last active October 28, 2023 14:26
Show Gist options
  • Save aktau/6660848 to your computer and use it in GitHub Desktop.
Save aktau/6660848 to your computer and use it in GitHub Desktop.
ffmpeg detect interlacing
#!/bin/bash
# for a blogpost on this, check: http://www.aktau.be/2013/09/22/detecting-interlaced-video-with-ffmpeg/
# detect interlacing with the ffmpeg "idet" filter, the longer
# you let this run, the better, though it's never 100% accurate
# flags:
# -an = discard audio, we don't need it
# -f rawvideo = output raw video
# -y NUL = discard the output (one can use /dev/null on UNIX operating systems, NUL works for all)
# -i ... = the input file to check
# -frames:v 100 = extract the first 100 frames
# -filter:v idet = insert the "idet" filter, which will output whether it has detected interlaced frame
ffmpeg -filter:v idet -frames:v 100 -an -f rawvideo -y NUL -i ~/Downloads/PSY\ -\ Gangnam\ Style\ -\ iHeartRadio\ Music\ Festival\ 2012\ 1080i60\ H.264\ 35Mbps.mkv
# Example output (this is interlaced, TFF style)
# [Parsed_idet_0 @ 0x1ccf7c0] Single frame detection: TFF:167 BFF:0 Progressive:1 Undetermined:0
# [Parsed_idet_0 @ 0x1ccf7c0] Multi frame detection: TFF:168 BFF:0 Progressive:0 Undetermined:0
ffmpeg -filter:v idet -frames:v 100 -an -f rawvideo -y NUL -i ~/Downloads/startrek1.mov
# Example output (this is not interlaced):
# [Parsed_idet_0 @ 0x1bcf720] Single frame detection: TFF:0 BFF:0 Progressive:564 Undetermined:84
# [Parsed_idet_0 @ 0x1bcf720] Multi frame detection: TFF:0 BFF:0 Progressive:623 Undetermined:25
# scan all files, uses GNU parallel
locate -0 '.mov' | parallel -0 ./ffmpeg -filter:v idet -frames:v 100 -an -f rawvideo -y NUL -i {} 2>&1 | egrep 'idet|Input'
@aktau
Copy link
Author

aktau commented Jul 4, 2022

Thanks all. I've updated the gist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment