Mercurial > vba-clojure
comparison clojure/com/aurellem/run/final_cut.clj @ 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 |
comparison
equal
deleted
inserted
replaced
531:c6ad363e36f7 | 532:a3bdff5554ad |
---|---|
52 | 52 |
53 (defn file-names [#^File dir] | 53 (defn file-names [#^File dir] |
54 (mapv #(.getCanonicalPath %) (next (sort (file-seq dir))))) | 54 (mapv #(.getCanonicalPath %) (next (sort (file-seq dir))))) |
55 | 55 |
56 (defn composite-frames-command | 56 (defn composite-frames-command |
57 [screenshot ram-map target] | 57 [screenshot ram-map target move] |
58 ["convert" | 58 (let [actual-keys (set move) |
59 "-size" "318x276" "xc:white" | 59 keys [:a :b :start :select :u :d :l :r] |
60 screenshot "-geometry" "+10+10" "-composite" | 60 button-on-name ["-size" "5x5" "xc:red"] |
61 ram-map "-geometry" "+180+10" "-composite" | 61 button-off-name ["-size" "5x5" "xc:black"]] |
62 target]) | 62 ["convert" |
63 "-size" "318x276" "xc:white" | |
64 (map | |
65 (fn [index] | |
66 (let [position ["-geometry" | |
67 (str "+" (+ 30 (* index 8)) | |
68 "+" "225") "-composite"]] | |
69 (if (actual-keys (keys index)) | |
70 [button-on-name position] | |
71 [button-off-name position]))) | |
72 (range (count keys))) | |
73 screenshot "-geometry" "+10+10" "-composite" | |
74 ram-map "-geometry" "+180+10" "-composite" | |
75 target])) | |
63 | 76 |
64 (defn generate-composite-frames! | 77 (defn generate-composite-frames! |
65 ([^File rendered-dir] | 78 [^File rendered-dir moves] |
66 (let [final-frames (File. rendered-dir "final") | 79 (let [final-frames (File. rendered-dir "final") |
67 _ (.mkdir final-frames) | 80 _ (.mkdir final-frames) |
68 screenshots (file-names (File. rendered-dir "frames")) | 81 screenshots (file-names (File. rendered-dir "frames")) |
69 ram-maps (file-names (File. rendered-dir "ram-map")) | 82 ram-maps (file-names (File. rendered-dir "ram-map")) |
70 targets (map #(File. final-frames (format "%07d.png")) | 83 targets (map #(.getCanonicalPath |
71 (range (count screenshots)))] | 84 (File. final-frames (format "%07d.bmp" %))) |
72 (dorun | 85 (range (count screenshots)))] |
73 (map | 86 (dorun |
74 ;; (comp ;;clojure.java.shell/sh | 87 (map |
75 ;; println | 88 (comp |
76 ;; flatten | 89 (partial apply clojure.java.shell/sh) |
77 composite-frames-command | 90 flatten |
78 screenshots ram-maps targets)) | 91 (partial apply composite-frames-command) |
79 | 92 (fn [a b c d] (println c) [a b c d])) |
80 )) | 93 screenshots ram-maps targets moves)))) |
81 ([] (generate-composite-frames! render-dir))) | |
82 | |
83 | 94 |
84 | 95 |
96 (defn final-cut! [^File render-dir] | |
97 (let [movie (File. render-dir "final.ogg") | |
98 final (File. render-dir "final")] | |
99 (.delete movie) | |
100 (clojure.java.shell/sh | |
101 "ffmpeg" "-r" "60" | |
102 "-i" (str (.getCanonicalPath final) "/" "%07d.bmp") | |
103 "-i" (.getCanonicalPath (File. render-dir "audio.wav")) | |
104 "-b:a" "128k" | |
105 "-b:v" "9000k" | |
106 "-c:a" "libvorbis" | |
107 "-c:v" "libtheora" | |
108 (.getCanonicalPath movie)) nil)) | |
109 | |
85 | 110 |
111 (comment | |
112 | |
113 ;; step 1 | |
114 | |
115 (render-files! | |
116 render-dir (root) | |
117 (take 9000 (first (control-checkpoint)))) | |
118 | |
119 ;; step 2 | |
120 | |
121 (generate-composite-frames! | |
122 render-dir | |
123 (take 9000 (first (control-checkpoint)))) | |
124 | |
125 ;; step 3 | |
126 (final-cut! render-dir) | |
127 ) |