                            "-crf" 51 "-preset" "ultrafast" "/dev/null"))]
     (when-let [crop (-> (re-seq #"crop=[0-9:]*" output) distinct sort last)]
       (when-not (.endsWith crop ":0:0") crop))))
+
+(defn deinterlace
+  [spec]
+  (merge spec
+         (when (detect-interlace (:input spec))
+           {:deinterlace "pullup,dejudder,idet,yadif=deint=interlaced:mode=1"})))
 
 (defn crop
   "Returns an updated spec with crop information."

(defn filter-video
  "Returns an updated spec with video filters applied (crop and scale)."
  [spec]
  (-> spec crop scale))

(defn encode-video?
  "Returns whether the video stream should be transcoded."

    (when (zero? (:exit exec))
      (json/read-str (:out exec) :key-fn keyword))))

(defn detect-interlace
  [input]
  (let [output (:err (exec "ffmpeg" "-y" "-ss" 300 "-i" input "-f" "matroska"
                           "-t" 120 "-an" "-sn" "-vf" "idet" "/dev/null"))]
    (when-let [frames (re-find #"Multi frame detection:.*" output)]
      (let [[top bottom prog und] (parse-ints frames)]
        #_(> (+ top bottom) (/ (+ top bottom prog und) 10))))))

(defn detect-crop
  "Performs crop detection, returning the filter argument or nil."
  [input]
