Skip to content

Commit a554c7b

Browse files
committed
Log the ideal bitrate
1 parent 90ad85a commit a554c7b

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

src/clj/mdr2/encode/core.clj

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,22 +111,26 @@
111111
code](https://www.colincrawley.com/cc/wp-content/plugins/audio-file-size-calculator/audiofilesizecalculator.js)"
112112
[production]
113113
(let [dtb (path/recorded-path production)
114+
mono? (dtb/mono? dtb)
114115
duration (quot (dtb/audio-length dtb) 1000) ; convert from millisecs to secs
115116
;; apparently stereo doesn't use twice as much space if you
116117
;; use joint stereo compression mode, so no need to divide by
117118
;; two. The legacy system just added a tolerance of 2% for
118119
;; stereo productions.
119-
sampling-ratio (if (dtb/mono? dtb) 1 1.02)
120+
sampling-ratio (if mono? 1 1.02)
120121
;; BitRate is measured in kilobits per second
121122
;; BitRate (kbps) = (File Size (bytes) / Duration (seconds)) * 8/1000
122123
max-bitrate (* (/ max-capacity duration sampling-ratio) (/ 8 1000))]
123-
(->> bitrates
124-
;; only use bitrate 32 for periodicals
125-
(filter #(or (= (:production_type production) "periodical") (> % 32)))
126-
;; for stereo productions use only bitrates larger or equal than 96
127-
(filter #(or (dtb/mono? dtb) (>= % 96)))
128-
(filter #(<= % max-bitrate))
129-
(apply max 0))))
124+
(let [bitrate (->> bitrates
125+
;; only use bitrate 32 for periodicals
126+
(filter #(or (= (:production_type production) "periodical") (> % 32)))
127+
;; for stereo productions use only bitrates larger or equal than 96
128+
(filter #(or mono? (>= % 96)))
129+
(filter #(<= % max-bitrate))
130+
(apply max 0))]
131+
(log/infof "Calculating ideal bitrate for %s as %s (mono? %s, duration %d secs, sampling-ratio %s, max-bitrate %f)"
132+
(:id production) bitrate mono? duration sampling-ratio (float max-bitrate))
133+
bitrate)))
130134

131135
(defn clean-up
132136
"Clean up temporary files of a production, namely the mp3 encoded

0 commit comments

Comments
 (0)