3232(def video-path
3333 " notebooks/movie/Video_003.mp4" )
3434
35- ; ; A conveneince function for displaying a video
36- ; ; in Quarto (till we handle this better in
37- ; ; an upcoming Clay release):
38- (defn video [path]
39- (kind/md
40- (str " {{"
41- \<
42- " video "
43- path
44- \>
45- " }}" )))
46-
47- (video video-path)
35+ (kind/video
36+ {:src video-path})
4837
4938; ; Let us explore it with clj-media:
5039
@@ -118,12 +107,16 @@ first-image
118107 image->small-tensor
119108 bufimg/tensor->image)
120109
121- ; ; Now let us collect the small tensors:
110+ ; ; Now let us collect the small tensors.
111+ ; ; We will take just 70 frames of the video,
112+ ; ; simply because it is enough for demonstrating
113+ ; ; the methods of this tutorial.
122114
123115(def small-tensors
124116 (into []
125- (map (comp image->small-tensor
126- clj-media.model/image))
117+ (comp (take 70 )
118+ (map (comp image->small-tensor
119+ clj-media.model/image)))
127120 (clj-media/frames
128121 (clj-media/file video-path)
129122 :video
@@ -269,7 +262,7 @@ first-image
269262 tensor-normalize
270263 (dfn/* 255 )
271264 dtype/->int-array
272- (tensor/reshape [120 160 350 ])
265+ (tensor/reshape [120 160 70 ])
273266 (tensor/transpose [2 0 1 ])
274267 (->> (mapv bufimg/tensor->image))))
275268
@@ -296,7 +289,7 @@ first-image
296289
297290(def generated-frames
298291 (let [frame-rate 7
299- seconds 50
292+ seconds 10
300293 num-frames (* seconds frame-rate)]
301294 (into []
302295 (map-indexed (fn [pts image]
@@ -310,4 +303,5 @@ first-image
310303 (clj-media/make-media frame-format generated-frames)
311304 target-path)
312305
313- (video target-path)
306+ (kind/video
307+ {:src target-path})
0 commit comments