Hans Petter Langtangen 11 年之前
父節點
當前提交
de4bcb4860
共有 4 個文件被更改,包括 45 次插入58 次删除
  1. 31 38
      doc/src/tut/basics.do.txt
  2. 6 18
      doc/src/tut/src-tut/vehicle0.py
  3. 7 1
      doc/src/tut/src-tut/vehicle1.py
  4. 1 1
      pysketcher/shapes.py

+ 31 - 38
doc/src/tut/basics.do.txt

@@ -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}

+ 6 - 18
doc/src/tut/src-tut/vehicle0.py

@@ -67,8 +67,11 @@ def move(t, fig):
 files = animate(fig, tp, move, moviefiles=True,
                 pause_per_frame=0)
 
-os.system('convert -delay 20 %s anim.gif' % files)
-os.system('ffmpeg -i "tmp_frame_%04d.png" -b 800k -r 25 -vcodec mpeg4 -y -qmin 2 -qmax 31 anim.mpeg')
+files_wildcard = files.split('%')[0]) + '*.png'
+os.system('convert -delay 20 %s* anim.gif' % (files_wildcard)
+os.system('ffmpeg -r 12 -i %s -c:v flv anim.flv' % files)
+os.system('ffmpeg -r 12 -i %s -c:v libvpx anim.webm' % files)
+os.system('ffmpeg -r 12 -i %s -c:v libtheora anim.ogg' % files)
 
 try:
     from scitools.std import movie
@@ -78,22 +81,7 @@ except ImportError:
         'scitools is installed by sudo apt-get install python-scitools\n'
         'on Ubuntu or by sudo python setup.py install if the code is\n'
         'downloaded from http://code.google.com/p/scitools.')
-
 # HTML page showing individual frames
-movie(files, encoder='html', fps=4, output_file='anim.html')
-
-# Standard GIF file
-movie(files, encoder='convert', fps=4, output_file='anim2.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='anim3.mpeg', vodec='mpeg2video')
-# or
-movie(files, encoder='ppmtompeg', fps=24,
-      output_file='anim2.mpeg')  # requires the netpbm package
+movie(files_wildcard, encoder='html', fps=4, output_file='anim.html')
 
 raw_input()

+ 7 - 1
doc/src/tut/src-tut/vehicle1.py

@@ -68,7 +68,13 @@ def move(t, fig):
 files = animate(fig, tp, move, moviefiles=True,
                 pause_per_frame=0)
 
+files_wildcard = files.split('%')[0]) + '*.png'
+os.system('convert -delay 20 %s* anim.gif' % (files_wildcard)
+os.system('ffmpeg -r 12 -i %s -c:v flv anim.flv' % files)
+os.system('ffmpeg -r 12 -i %s -c:v libvpx anim.webm' % files)
+os.system('ffmpeg -r 12 -i %s -c:v libtheora anim.ogg' % files)
+os.system('ffmpeg -r 12 -i %s -c:v flv anim.flv' % files)
 from scitools.std import movie
-movie(files, encoder='html', output_file='anim')
+movie(files_wildcard, encoder='html', output_file='anim')
 
 raw_input()

+ 1 - 1
pysketcher/shapes.py

@@ -125,7 +125,7 @@ def animate(fig, time_points, action, moviefiles=False,
             drawing_tool.savefig('%s%04d.png' % (framefilestem, n))
 
     if moviefiles:
-        return '%s*.png' % framefilestem
+        return '%s%%04d.png' % framefilestem
 
 
 class Shape: