1#!/usr/local/bin/perl
2#
3# Created on: Wed 28 Jul 2010 03:41:45 PM
4# Last saved: Thu 10 Feb 2011 05:10:44 PM
5
6use PDL;
7use PDL::IO::Pic;
8use PDL::NiceSlice;
9
10# This is a simple program to create a demo MPEG-1
11# movie via the wmpeg() routine in PDL::IO::Pic
12# and to test the functionality of using ffmpeg
13# in place of the outdated mpeg_encoder.
14
15# a simple parabolic trajectory ("bouncing ball")
16# for 30 128x80 image frames
17our $coords = pdl( q[
18                    [  0   1   0]
19                    [  4   9   1]
20                    [  8  17   2]
21                    [ 12  25   3]
22                    [ 16  32   4]
23                    [ 20  38   5]
24                    [ 24  43   6]
25                    [ 28  48   7]
26                    [ 32  53   8]
27                    [ 36  57   9]
28                    [ 40  60  10]
29                    [ 44  62  11]
30                    [ 48  64  12]
31                    [ 52  66  13]
32                    [ 56  66  14]
33                    [ 60  66  15]
34                    [ 64  66  16]
35                    [ 68  65  17]
36                    [ 72  63  18]
37                    [ 76  60  19]
38                    [ 80  57  20]
39                    [ 84  54  21]
40                    [ 88  50  22]
41                    [ 92  45  23]
42                    [ 96  39  24]
43                    [100  33  25]
44                    [104  27  26]
45                    [108  19  27]
46                    [112  11  28]
47                    [116   3  29]
48                   ] );
49
50our $frames = zeros byte, 128, 80, 30;
51our $val = pdl(byte,250);  # start with white
52
53# make the square ball bounce
54$frames->range($coords,[10,10,1]) .= $val;
55
56# now make the movie
57$frames = $frames->(*3)->copy;
58# the encoding type is from the suffix
59# .mp4 seems to work better than .mpg on
60# Windows Media Player
61$frames->wmpeg('bounce.mp4');  # use bounce.gif for animated GIF
62                               # output (uncompressed => big)
63