changeset 532:a3bdff5554ad

completed clojure functions to generate final video.
author Robert McIntyre <rlm@mit.edu>
date Mon, 25 Jun 2012 11:15:08 -0500
parents c6ad363e36f7
children 60da469773e5
files clojure/com/aurellem/run/final_cut.clj todo.org
diffstat 2 files changed, 67 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
     1.1 --- a/clojure/com/aurellem/run/final_cut.clj	Sun Jun 24 17:18:22 2012 -0500
     1.2 +++ b/clojure/com/aurellem/run/final_cut.clj	Mon Jun 25 11:15:08 2012 -0500
     1.3 @@ -54,32 +54,74 @@
     1.4     (mapv #(.getCanonicalPath %) (next (sort (file-seq dir)))))
     1.5  
     1.6  (defn composite-frames-command
     1.7 -  [screenshot ram-map target]
     1.8 -  ["convert"
     1.9 -   "-size" "318x276" "xc:white"
    1.10 -   screenshot   "-geometry" "+10+10"  "-composite"
    1.11 -   ram-map      "-geometry" "+180+10" "-composite"
    1.12 -   target])
    1.13 +  [screenshot ram-map target move]
    1.14 +  (let [actual-keys (set move)
    1.15 +        keys [:a :b :start :select :u :d :l :r]
    1.16 +        button-on-name  ["-size" "5x5" "xc:red"]
    1.17 +        button-off-name ["-size" "5x5" "xc:black"]]
    1.18 +    ["convert"
    1.19 +     "-size" "318x276" "xc:white"
    1.20 +     (map
    1.21 +      (fn [index]
    1.22 +        (let [position ["-geometry"
    1.23 +                        (str "+" (+ 30 (* index 8))
    1.24 +                             "+" "225") "-composite"]]
    1.25 +          (if (actual-keys (keys index))
    1.26 +            [button-on-name  position]
    1.27 +            [button-off-name position])))
    1.28 +      (range (count keys)))
    1.29 +     screenshot   "-geometry" "+10+10"  "-composite"
    1.30 +     ram-map      "-geometry" "+180+10" "-composite"
    1.31 +     target]))
    1.32  
    1.33  (defn generate-composite-frames!
    1.34 -  ([^File rendered-dir]
    1.35 -     (let [final-frames (File. rendered-dir "final")
    1.36 -           _ (.mkdir final-frames)
    1.37 -           screenshots (file-names (File. rendered-dir "frames"))
    1.38 -           ram-maps    (file-names (File. rendered-dir "ram-map"))
    1.39 -           targets (map #(File. final-frames (format "%07d.png"))
    1.40 -                        (range (count screenshots)))]
    1.41 -       (dorun
    1.42 -        (map
    1.43 -         ;;         (comp ;;clojure.java.shell/sh
    1.44 -         ;;          println
    1.45 -         ;;          flatten
    1.46 -         composite-frames-command
    1.47 -         screenshots ram-maps targets))
    1.48 +  [^File rendered-dir moves]
    1.49 +  (let [final-frames (File. rendered-dir "final")
    1.50 +        _ (.mkdir final-frames)
    1.51 +        screenshots (file-names (File. rendered-dir "frames"))
    1.52 +        ram-maps    (file-names (File. rendered-dir "ram-map"))
    1.53 +        targets (map #(.getCanonicalPath
    1.54 +                       (File. final-frames (format "%07d.bmp" %)))
    1.55 +                     (range (count screenshots)))]
    1.56 +    (dorun
    1.57 +     (map
    1.58 +      (comp
    1.59 +       (partial apply clojure.java.shell/sh)
    1.60 +       flatten
    1.61 +       (partial apply composite-frames-command)
    1.62 +       (fn [a b c d] (println c) [a b c d]))
    1.63 +      screenshots ram-maps targets moves))))
    1.64  
    1.65 -       ))
    1.66 -  ([] (generate-composite-frames! render-dir)))
    1.67 +
    1.68 +(defn final-cut! [^File render-dir]
    1.69 +  (let [movie (File. render-dir "final.ogg")
    1.70 +        final (File. render-dir "final")]
    1.71 +    (.delete movie)
    1.72 +    (clojure.java.shell/sh
    1.73 +     "ffmpeg" "-r" "60"
    1.74 +     "-i" (str (.getCanonicalPath final) "/" "%07d.bmp")
    1.75 +     "-i" (.getCanonicalPath (File. render-dir "audio.wav"))
    1.76 +     "-b:a" "128k"
    1.77 +     "-b:v" "9000k"
    1.78 +     "-c:a" "libvorbis"
    1.79 +     "-c:v" "libtheora"
    1.80 +     (.getCanonicalPath movie)) nil))
    1.81 +     
    1.82    
    1.83 +(comment
    1.84  
    1.85 +  ;; step 1
    1.86 +  
    1.87 +  (render-files!
    1.88 +   render-dir (root)
    1.89 +   (take 9000 (first (control-checkpoint))))
    1.90  
    1.91 -  
    1.92 \ No newline at end of file
    1.93 +  ;; step 2
    1.94 +  
    1.95 +  (generate-composite-frames!
    1.96 +   render-dir 
    1.97 +   (take 9000 (first (control-checkpoint))))
    1.98 +
    1.99 +  ;; step 3
   1.100 +  (final-cut! render-dir)
   1.101 +  )
   1.102 \ No newline at end of file
     2.1 --- a/todo.org	Sun Jun 24 17:18:22 2012 -0500
     2.2 +++ b/todo.org	Mon Jun 25 11:15:08 2012 -0500
     2.3 @@ -1,11 +1,11 @@
     2.4 -* vba-clojure [2/7]
     2.5 +* vba-clojure [3/7]
     2.6    - [X] create ram display
     2.7    - [ ] derpy hack 
     2.8    - [X] sound recording
     2.9    - [ ] fix unnecessary pauses before take-over
    2.10    - [ ] design demo choreography
    2.11    - [ ] implement choreography
    2.12 -  - [ ] clojure function to assemble final video
    2.13 +  - [X] clojure function to assemble final video
    2.14  
    2.15  * fimfiction [0/1]
    2.16    - [ ] clojure catalogue