Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
(defn get-length
(let [cmd (str
"ffmpeg -i '"
"' 2>&1 | grep Duration | cut -d ' ' -f 4 | sed s/,//"
output (.start (ProcessBuilder. (into-array ["/bin/bash" "-c" cmd])))
info (slurp (.getInputStream output))]
(let [[h m s] (clojure.string/split info #":" ) ]
(* (Long/parseLong h ) 60 60)1
(* (Long/parseLong m) 60)
(Float/parseFloat s)))))

This comment has been minimized.

Copy link

tallpeak commented Feb 6, 2019

;; This might be easier to use on Windows, since I removed grep and split and perhaps bash/sh dependencies

(require '[ :refer [sh]])
(require '[clojure.string :as str])
(defn get-length
    (let [ out (sh "ffmpeg" "-i" path)
           outall (let [{:keys [out err]} out] (str out err))
           DurationLine (apply str (filter #(.contains % "Duration") (str/split outall #"\n")))
           duration (str/split (first (str/split DurationLine #",")) #":")
           [_junk h m s] duration ]
       (* (Long/parseLong (str/trim h) ) 60 60)1
       (* (Long/parseLong m) 60)
       (Float/parseFloat s))))

(def path "/mnt/big/backup/somefile.mpg")
(get-length path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.