|
|
@@ -405,55 +405,48 @@ We can also ask `animate` to store each frame in a file:
|
|
|
files = animate(fig, tp, move_vehicle, moviefiles=True,
|
|
|
pause_per_frame=0.2)
|
|
|
!ec
|
|
|
-The `files` variable, here `'tmp_frame*.png'`,
|
|
|
-is a string expressing the family of frame files.
|
|
|
-This string can be used directly in commands for making a movie
|
|
|
-out of the files.
|
|
|
-A simple approach is to generate an animated GIF file with help of
|
|
|
-the `convert` program from the ImageMagick software suite:
|
|
|
+The `files` variable, here `'tmp_frame_%04d.png'`,
|
|
|
+is the printf-specification used to generate the individual
|
|
|
+plot files. We can use this specification to make a video
|
|
|
+file via `ffmpeg` (or `avconv` on Debian-based Linux systems such
|
|
|
+as Ubuntu). Videos in the Flash and WebM formats can be created
|
|
|
+by
|
|
|
+
|
|
|
+!bc sys
|
|
|
+Terminal> ffmpeg -r 12 -i tmp_frame_%04d.png -c:v flv anim.flv
|
|
|
+Terminal> ffmpeg -r 12 -i tmp_frame_%04d.png -c:v libvpx anim.webm
|
|
|
+!ec
|
|
|
+An animated GIF movie can also be made using the `convert` program
|
|
|
+from the ImageMagick software suite:
|
|
|
+
|
|
|
!bc sys
|
|
|
Terminal> convert -delay 20 tmp_frame*.png anim.gif
|
|
|
Terminal> animate anim.gif # play movie
|
|
|
!ec
|
|
|
-The delay between frames governs the speed of the movie.
|
|
|
-The `anim.gif` file can be embedded in a web page and shown as
|
|
|
-a movie when the page is loaded into a web browser (just insert
|
|
|
-`<img src="anim.gif">` in the HTML code).
|
|
|
+The delay between frames, in units of 1/100 s,
|
|
|
+governs the speed of the movie.
|
|
|
+To play the animated GIF file in a web page, simply insert
|
|
|
+`<img src="anim.gif">` in the HTML code.
|
|
|
+
|
|
|
+The individual PNG frames can be directly played in a web
|
|
|
+browser by running
|
|
|
|
|
|
-The tool `ffmpeg` can alternatively be used to create an MPEG movie, e.g.,
|
|
|
!bc sys
|
|
|
-Terminal> ffmpeg -i "tmp_frame_%04d.png" -b 800k -r 25 \
|
|
|
- -vcodec mpeg4 -y -qmin 2 -qmax 31 anim.mpeg
|
|
|
+Terminal> scitools movie output_file=anim.html fps=5 tmp_frame*
|
|
|
!ec
|
|
|
-An easy-to-use Python interface to movie-making tools is provided by the
|
|
|
-SciTools package:
|
|
|
+or calling
|
|
|
+
|
|
|
!bc pycod
|
|
|
from scitools.std import movie
|
|
|
-
|
|
|
-# HTML page showing individual frames
|
|
|
movie(files, encoder='html', output_file='anim.html')
|
|
|
+!ec
|
|
|
+in Python. Load the resulting file `anim.html` into a web browser
|
|
|
+to play the movie.
|
|
|
|
|
|
-# Standard GIF file
|
|
|
-movie(files, encoder='convert', output_file='anim.gif')
|
|
|
-
|
|
|
-# AVI format
|
|
|
-movie('tmp_*.png', encoder='ffmpeg', fps=4,
|
|
|
- output_file='anim.avi') # requires ffmpeg package
|
|
|
-
|
|
|
-# MPEG format
|
|
|
-movie('tmp_*.png', encoder='ffmpeg', fps=4,
|
|
|
- output_file='anim2.mpeg', vodec='mpeg2video')
|
|
|
-# or
|
|
|
-movie(files, encoder='ppmtompeg', fps=24,
|
|
|
- output_file='anim.mpeg') # requires the netpbm package
|
|
|
-!ec
|
|
|
-When difficulties with encoders and players arise, the simple
|
|
|
-web page for showing a movie, here `anim.html` (generated by the
|
|
|
-first `movie` command above), is a safe method that you always
|
|
|
-can rely on.
|
|
|
-You can try loading `anim.html` into a web browser, after first
|
|
|
-having run the present example in the file
|
|
|
-"`vehicle0.py`": "${src_path_pysketcher}/vehicle0.py". Alternatively, you can view a ready-made "movie": "${src_path_tut}/mov-tut/anim.html_vehicle0/anim.html".
|
|
|
+Try to run "`vehicle0.py`": "${src_path_pysketcher}/vehicle0.py" and
|
|
|
+then load `anim.html` into a browser, or play one of the `anim.*`
|
|
|
+video files. Alternatively, you can view a ready-made "movie":
|
|
|
+"${src_path_tut}/mov-tut/anim.html_vehicle0/anim.html".
|
|
|
|
|
|
=== Animation: Rolling the Wheels ===
|
|
|
label{sketcher:vehicle1:anim}
|