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'
@tarunHub
Copy link

Can you share the command to run on windows. because while running its says permission denied.

Code :
res=subprocess.call('ffmpeg -filter:v idet -frames:v 100 -an -f rawvideo -y D:\Inputvideos -i C:\Users\tarun\Desktop\interlacing\Inputvideos\videoplaybackcutv3.mp4')

Output

ffmpeg version N-92486-g8f875a90c4 Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 8.2.1 (GCC) 20181017
configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth
libavutil 56. 23.101 / 56. 23.101
libavcodec 58. 39.100 / 58. 39.100
libavformat 58. 22.100 / 58. 22.100
libavdevice 58. 6.100 / 58. 6.100
libavfilter 7. 44.100 / 7. 44.100
libswscale 5. 4.100 / 5. 4.100
libswresample 3. 4.100 / 3. 4.100
libpostproc 55. 4.100 / 55. 4.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'C:\Users\tarun\Desktop\interlacing\Inputvideos\videoplaybackcutv3.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.22.100
Duration: 00:00:05.02, start: 0.000000, bitrate: 266 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 480x360 [SAR 1:1 DAR 4:3], 170 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 85 kb/s (default)
Metadata:
handler_name : IsoMedia File Produced by Google, 5-11-2011
D:\Inputvideos: Permission denied

@gujiling
Copy link

D:\Inputvideos should be an existing file.

D:\Inputvideos: Permission denied

@cdgriffith
Copy link

On Windows you need to set output to NUL instead of /dev/null

ffmpeg -i video_to_detect.mp4 -filter:v idet -frames:v 100 -an -sn -dn -f rawvideo NUL -y

@azimidev
Copy link

@cdgriffith this is much better and it works, Thank you!

@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