File: wmpeg.pl

package info (click to toggle)
pdl 1%3A2.025-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 11,768 kB
  • sloc: perl: 43,919; fortran: 13,113; ansic: 9,366; makefile: 37; sh: 32; sed: 6
file content (62 lines) | stat: -rw-r--r-- 1,930 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/perl
#
# Created on: Wed 28 Jul 2010 03:41:45 PM 
# Last saved: Thu 10 Feb 2011 05:10:44 PM 

use PDL;
use PDL::IO::Pic;
use PDL::NiceSlice;

# This is a simple program to create a demo MPEG-1
# movie via the wmpeg() routine in PDL::IO::Pic
# and to test the functionality of using ffmpeg
# in place of the outdated mpeg_encoder.

# a simple parabolic trajectory ("bouncing ball")
# for 30 128x80 image frames
our $coords = pdl( q[
                    [  0   1   0]
                    [  4   9   1]
                    [  8  17   2]
                    [ 12  25   3]
                    [ 16  32   4]
                    [ 20  38   5]
                    [ 24  43   6]
                    [ 28  48   7]
                    [ 32  53   8]
                    [ 36  57   9]
                    [ 40  60  10]
                    [ 44  62  11]
                    [ 48  64  12]
                    [ 52  66  13]
                    [ 56  66  14]
                    [ 60  66  15]
                    [ 64  66  16]
                    [ 68  65  17]
                    [ 72  63  18]
                    [ 76  60  19]
                    [ 80  57  20]
                    [ 84  54  21]
                    [ 88  50  22]
                    [ 92  45  23]
                    [ 96  39  24]
                    [100  33  25]
                    [104  27  26]
                    [108  19  27]
                    [112  11  28]
                    [116   3  29]
                   ] );

our $frames = zeros byte, 128, 80, 30;
our $val = pdl(byte,250);  # start with white

# make the square ball bounce
$frames->range($coords,[10,10,1]) .= $val;

# now make the movie
$frames = $frames->(*3)->copy;
# the encoding type is from the suffix
# .mp4 seems to work better than .mpg on
# Windows Media Player
$frames->wmpeg('bounce.mp4');  # use bounce.gif for animated GIF
                               # output (uncompressed => big)