render-videos.scm 13.1 KB
Newer Older
1 2 3 4 5 6 7
;;; This module extends GNU Guix and is licensed under the same terms, those
;;; of the GNU GPL version 3 or (at your option) any later version.
;;;
;;; Copyright © 2021 Inria

;; To build videos of the talks, with openings and closings, run:
;;
8
;;   guix build -m render-videos.scm
9
;;
10
;; The result will a set of post-processed webm videos.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38

(use-modules (guix) (guix channels) (guix inferior) (guix profiles)
             (guix git-download) (guix modules)
             (gnu packages) (gnu packages tex)
             (srfi srfi-9)
             (ice-9 match))


;;;
;;; Rendering BigBlueButton videos.
;;;

(define bbb-render
  (origin
    (method git-fetch)
    (uri (git-reference (url "https://github.com/plugorgau/bbb-render")
                        (commit "a3c10518aedc1bd9e2b71a4af54903adf1d972e5")))
    (file-name "bbb-render-checkout")
    (sha256
     (base32 "1sf99xp334aa0qgp99byvh8k39kc88al8l2wy77zx7fyvknxjy98"))))

(define rendering-profile
  (profile
   (content (specifications->manifest
             '("gstreamer" "gst-editing-services" "gobject-introspection"
               "gst-plugins-base" "gst-plugins-good"
               "python-wrapper" "python-pygobject" "python-intervaltree")))))

39 40
(define* (video-ges-project bbb-data start end
                            #:key (webcam-size 25))
41 42
  "Return a GStreamer Editing Services (GES) project for the video,
starting at START seconds and ending at END seconds.  BBB-DATA is the raw
43 44
BigBlueButton directory as fetched by bbb-render's 'download.py' script.
WEBCAM-SIZE is the percentage of the screen occupied by the webcam."
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
  (computed-file "video.ges"
                 (with-extensions (list (specification->package "guile-gcrypt"))
                  (with-imported-modules (source-module-closure
                                          '((guix build utils)
                                            (guix profiles)))
                    #~(begin
                        (use-modules (guix build utils) (guix profiles)
                                     (guix search-paths) (ice-9 match))

                        (define search-paths
                          (profile-search-paths #+rendering-profile))

                        (for-each (match-lambda
                                    ((spec . value)
                                     (setenv
                                      (search-path-specification-variable
                                       spec)
                                      value)))
                                  search-paths)

                        ;; XXX: 'make-xges.py' has '--opening-credits' and
                        ;; '--closing-credits' options, but this lead to
                        ;; blank frames for some reason.  Thus, we resort to
                        ;; ffmpeg concatenation below.
                        (invoke "python"
                                #+(file-append bbb-render "/make-xges.py")
                                #+bbb-data #$output
                                "--start" #$(number->string start)
73 74 75
                                "--end" #$(number->string end)
                                "--webcam-size"
                                #$(number->string webcam-size)))))))
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243

(define (ges->webm ges webm)
  "Render GES, a GStreamer Editing Services (GES) project, as WebM."
  (define gst-editing-services
    (specification->package "gst-editing-services"))

  (computed-file webm
                 (with-extensions (list (specification->package "guile-gcrypt"))
                   (with-imported-modules (source-module-closure
                                           '((guix build utils)
                                             (guix profiles)))
                     #~(begin
                         (use-modules (guix build utils) (guix profiles)
                                      (guix search-paths) (ice-9 match))

                         (define search-paths
                           (profile-search-paths #+rendering-profile))

                         (for-each (match-lambda
                                     ((spec . value)
                                      (setenv
                                       (search-path-specification-variable
                                        spec)
                                       value)))
                                   search-paths)

                         (invoke #+(file-append gst-editing-services
                                                "/bin/ges-launch-1.0")
                                 "--load" #+ges "-o" #$output
                                 "--format"
                                 "video/webm:video/x-vp8:audio/x-vorbis"))))))


;;;
;;; Openings and closings.
;;;

(define channels
  (list (channel
         (name 'guix)
         (url "https://git.savannah.gnu.org/git/guix.git")
         ;; https://data.guix.gnu.org/repository/1/branch/master/package/texlive
         (commit "c81457a5883ea43950eb2ecdcbb58a5b144bcd11"))))

(define inferior
  (inferior-for-channels channels))

(define texlive
  ;; XXX: This is terrible but we end using texlive@2018 (the big package);
  ;; texlive@2019 lacks Fira Sans.
  (car (lookup-inferior-packages inferior "texlive"))
  ;; (specification->package "texlive")
  ;; (texlive-union  (list texlive-base texlive-beamer
  ;;                       texlive-fonts-ec texlive-etoolbox
  ;;                       texlive-generic-ulem texlive-cm-super texlive-latex-capt-of
  ;;                       texlive-latex-wrapfig texlive-latex-geometry
  ;;                       texlive-latex-ms texlive-amsfonts texlive-latex-graphics
  ;;                       texlive-latex-pgf))
  )

(define locales (specification->package "glibc-utf8-locales"))
(define imagemagick (specification->package "imagemagick"))
(define ffmpeg (specification->package "ffmpeg"))

(define* (latex->pdf tex pdf
                     #:key
                     (speaker "SPEAKER") (title "TITLE"))
  (computed-file pdf
                 (with-imported-modules '((guix build utils))
                   #~(begin
                       (use-modules (guix build utils))

                       (setenv "GUIX_LOCPATH"
                               #+(file-append locales "/lib/locale"))
                       (setlocale LC_ALL "en_US.utf8")

                       (copy-file #$tex "source.tex")
                       (make-file-writable "source.tex")
                       (substitute* "source.tex"
                         (("TALK TITLE") #$title)
                         (("SPEAKER") #$speaker))
                       (copy-recursively #$(local-file "images"
                                                       #:recursive? #t)
                                         "images")

                       (let loop ((i 3))
                         (unless (zero? i)
                           (invoke #$(file-append texlive "/bin/pdflatex")
                                   "source.tex")
                           (loop (1- i))))
                       (copy-file "source.pdf" #$output)))))

(define (pdf->bitmap pdf png)
  (computed-file png
                 (with-imported-modules '((guix build utils))
                   #~(begin
                       (use-modules (guix build utils))
                       (invoke #$(file-append imagemagick "/bin/convert")
                               "-density" "300"
                               #$pdf #$output)))))

(define* (image->webm image webm
                      #:key (duration 5))
  (computed-file webm
                 (with-imported-modules '((guix build utils))
                   #~(begin
                       (use-modules (guix build utils))
                       (invoke #$(file-append ffmpeg "/bin/ffmpeg")
                               "-loop" "1" "-i" #$image
                               "-t" #$(number->string duration)
                               "-vcodec" "vp8" "-r" "24"
                               "output.webm")

                       ;; XXX: Add empty audio with a "channel layout" that
                       ;; matches that of VIDEO.  If we produce output
                       ;; without audio, the concatenation will lack audio
                       ;; entirely; if we produce output with a different
                       ;; audio channel, concatenation will have garbled
                       ;; audio.
                       (invoke #$(file-append ffmpeg "/bin/ffmpeg")
                               "-f" "lavfi"
                               "-i" "anullsrc=channel_layout=stereo:sample_rate=48000"
                               "-i" "output.webm"
                               "-c:v" "copy" "-c:a" "libvorbis" "-shortest"
                               #$output)))))

(define (opening title speaker)
  (image->webm
   (pdf->bitmap (latex->pdf (local-file "opening.tex") "opening.pdf"
                            #:title title #:speaker speaker)
                "opening.jpg")
   "opening.webm" #:duration 5))

(define closing.webm
  (image->webm
   (pdf->bitmap (latex->pdf (local-file "closing.tex") "closing.pdf")
                "closing.jpg")
   "closing.webm"
   #:duration 3))

(define (video-with-opening/closing name video opening closing)
  (computed-file name
                 (with-imported-modules '((guix build utils))
                   #~(begin
                       (use-modules (guix build utils)
                                    (ice-9 format))

                       (symlink #+opening "opening.webm")
                       (symlink #+video "video.webm")
                       (symlink #+closing "closing.webm")
                       (call-with-output-file "list.txt"
                         (lambda (port)
                           (format port "~{file ~a~%~}"
                                   '("opening.webm" "video.webm"
                                     "closing.webm"))))

                       (invoke #+(file-append ffmpeg "/bin/ffmpeg")
                               "-f" "concat"
                               "-i" "list.txt" "-c" "copy"
                               "output.webm")
                       (copy-file "output.webm" #$output)))))


;;;
;;; Putting it all together.
;;;

(define-record-type <talk>
244
  (talk title speaker start end cam-size data)
245 246 247
  talk?
  (title     talk-title)
  (speaker   talk-speaker)
248 249 250 251
  (start     talk-start)                      ;start time in seconds
  (end       talk-end)                        ;end time
  (cam-size  talk-webcam-size)                ;percentage used for the webcam
  (data      talk-bbb-data))                  ;BigBlueButton data
252

253
(define raw-bbb-data/monday
254 255
  ;; The raw BigBlueButton data as returned by './download.py URL', where
  ;; 'download.py' is part of bbb-render.
256 257 258 259 260 261
  (local-file "bbb-video-data.monday" "bbb-video-data"
              #:recursive? #t))

(define raw-bbb-data/tuesday
  (local-file "bbb-video-data.tuesday" "bbb-video-data"
              #:recursive? #t))
262 263

(define talks
264 265 266 267 268 269 270 271 272 273 274
  (list (talk "Concilier le calcul haute performance avec l'utilisation de bibliothèques tierces ?"
              "Emmanuel Agullo"
              (+ (* 1 60) 43) (+ (* 38 60) 59)
              0                                   ;no webcam
              raw-bbb-data/monday)
        (talk "Douze ans de plateforme — des Modules à Guix"
              "François Rué"
              (+ (* 40 60) 15) (+ (* 76 60) 50)
              25
              raw-bbb-data/monday)
        (talk "Génération d'un environnement contrôlé via Debian Snapshot Archive"
275 276
              "Arnaud Legrand"
              10 (+ (* 45 60) 31)
277
              25;%
278
              raw-bbb-data/tuesday)
279 280 281
        (talk "Guix comme gestionnaire d'environnement logiciel sur un mésocentre HPC"
              "Pierre-Antoine Bouttier"
              (+ (* 46 60) 22) (+ (* 92 60) 09)
282
              0                                   ;no webcam
283
              raw-bbb-data/tuesday)
284 285 286 287
        (talk "Guix et Org mode, deux amis du doctorant sur le chemin vers une thèse reproductible"
              "Marek Felšöci"
              (+ (* 92 60) 29) (+ (* 128 60) 49)
              0                                   ;no webcam
288
              raw-bbb-data/tuesday)))
289 290 291

(define (canonicalize-string str)
  (string-map (lambda (chr)
292 293 294
                (cond ((eqv? chr #\space) #\-)
                      ((char-set-contains? char-set:ascii chr) chr)
                      (else #\-)))
295 296 297 298 299 300 301 302 303 304
              (string-downcase str)))

(define (talk->video talk)
  "Given a talk, return a complete video, with opening and closing."
  (define file-name
    (string-append (canonicalize-string (talk-speaker talk))
                   ".webm"))

  (let ((raw (ges->webm (video-ges-project (talk-bbb-data talk)
                                           (talk-start talk)
305 306 307
                                           (talk-end talk)
                                           #:webcam-size
                                           (talk-webcam-size talk))
308 309 310 311 312 313 314 315 316 317 318 319
                        file-name))
        (opening (opening (talk-title talk) (talk-speaker talk))))
    (video-with-opening/closing file-name raw
                                opening closing.webm)))

(define (talk->manifest-entry talk)
  (manifest-entry
    (name (canonicalize-string (talk-speaker talk)))
    (version "0")
    (item (talk->video talk))))

(manifest (map talk->manifest-entry talks))