             (prod/update! (assoc production :state "encoded"))))))
     ;; otherwise move the production to state :pending-volume-split
     (prod/update! (assoc production :state "pending-split"))))
+
+(defn encode-multiple
+  [production sample-rate bitrate]
+  (dotimes [volume (:volumes production)]
+    (let [volume (inc volume) ; we want from 1..n instead of 0..n-1
+          result (encode-production production bitrate volume sample-rate)]
+      (if (not= 0 (:exit result))
+        (log/errorf "Encoding failed with %s" (:err result))
+        (do
+          ;; downgrade to daisy202
+          (downgrade production)
+          ;; create an iso
+          (create-iso production volume)))))
+  ;; set the state to encoded
+  (prod/update! (assoc production :state "encoded")))


(defn downgrade
  [production]
  (pipeline2/daisy3-to-daisy202))

(defn encode
  [production]

  "Pack a production in an iso file"
  [{:keys [title publisher]
    :or {title "FIXME:" publisher "FIXME:"} ; title and publisher shouldn't be empty
    :as production} & [volume]]
  (let [encoded-path (.getPath (path/encoded-path production volume))
        iso-path (path/iso-path production volume)
        iso-name (.getPath (path/iso-name production volume))]
    (fs/mkdir iso-path)
    (sh "genisoimage"
        "-quiet"
