;;  This example plays a movie forwards and backwards

;;  at the same time. frames from the head and tail of the

;;  movie are composited on each other using gfx:image2image

;;  with a 50% transperency and then displayed.


;;  NOTE That you will get very poor performance trying

;;  to playback movies with framerates other than 1

;;  in particular this relates to movies in h264 format etc.


;;  For best performance playback in reverse use formats such

;;  as Motion JPEG, or Apple Intermediate.



(define canvas (gfx:make-canvas))

(define movie (gfx:load-movie "/tmp/myfilm.mov"))

(define mlgth (- (gfx:get-movie-duration movie) 1.0))

(define frame-length (* *second* 0.1))

(define loop

   (lambda (time mtime)

      (let* ((frame1 (gfx:get-movie-frame movie mtime))

             (frame2 (gfx:get-movie-frame movie (- mlgth mtime))))

         ; composit frame2 on frame1 with a 50% transparency

         (gfx:image2image frame2 frame1 0.5)

         (gfx:draw-image time canvas frame1 1.0)

         (set! time (+ time frame-length))

         (objc:release time frame1 frame2)

         (if (< mtime mlgth)

             (callback (- time 1000) 'loop time (+ mtime 0.1))))))

(loop (now) 0.0)