Movies: Difference between revisions

From GRASS-Wiki
Jump to navigation Jump to search
Line 58: Line 58:


==== Examples ====
==== Examples ====
===== Animate on screen =====
<pre>
<pre>
### Animate on screen
GRASS_WIDTH=640 GRASS_HEIGHT=500 \
GRASS_WIDTH=640 GRASS_HEIGHT=500 \
   d.mon start=x0
   d.mon start=x0
g.region rast=elevation.dem n=4927830 s=4912980
g.region rast=elevation.dem n=4927830 s=4912980


Line 78: Line 79:


</pre>
</pre>
===== Animate to files =====
<pre>
<pre>
### Animate to file
# set up base map
# set up base map
g.region rast=elevation.dem n=4927830 s=4912980
g.region rast=elevation.dem n=4927830 s=4912980
Line 120: Line 122:


</pre>
</pre>
===== Encode as animated GIF =====
* ''Using the gifsicle encoder''
* ''View in a web browser''
<pre>
<pre>
#### encode as animated GIF with gifsicle
for IMG in ganim*.ppm ; do  # convert each frame from PPM to GIF
for IMG in ganim*.ppm ; do  # convert each frame from PPM to GIF
   ppmquant 256 $IMG | ppmtogif > "`basename $IMG .ppm`.gif"
   ppmquant 256 $IMG | ppmtogif > "`basename $IMG .ppm`.gif"
Line 128: Line 133:
gifsicle -O2 --delay 20 --no-loopcount --colors 256 ganim_*.gif > ganim.gif
gifsicle -O2 --delay 20 --no-loopcount --colors 256 ganim_*.gif > ganim.gif
\rm ganim_0*.gif
\rm ganim_0*.gif
# view in a web browser
</pre>


===== Encode as animated PNG (MNG) =====
* ''Using the ImageMagick "convert" encoder''
* ''View with ImageMagick's "display"''
<pre>
convert -delay 20 ganim_*.ppm ganim.mng
</pre>
</pre>
<pre>


#### encode as animated PNG (MNG) with ImageMagick
===== Encode as FLI =====
convert -delay 20 ganim_*.ppm ganim.mng
* ''Using the ppm2fli encoder''
# view with "display"
* ''View with mplayer or xanim''


</pre>
<pre>
<pre>
#### encode as FLI with ppm2fli
ls ganim_*.ppm > frames.txt
ls ganim_*.ppm > frames.txt
ppm2fli -g"${GRASS_WIDTH}x${GRASS_HEIGHT}" -O -s 15 frames.txt ganim.fli
ppm2fli -g"${GRASS_WIDTH}x${GRASS_HEIGHT}" -O -s 15 frames.txt ganim.fli
\rm frames.txt
\rm frames.txt
# view with mplayer or xanim
</pre>
 
===== Encode as MPEG-4 Xvid =====
* ''Using the mencoder encoder''
* ''View with mplayer or similar''


</pre>
<pre>
<pre>


#### encode as MPEG-4 Xvid
# doesn't like GRASS's PPMs, convert to PNG
# doesn't like GRASS's PPMs, convert to PNG
for IMG in ganim*.ppm ; do
for IMG in ganim*.ppm ; do
Line 156: Line 165:
mencoder "mf://ganim_*.png" -mf "type=png:fps=5" -o ganim.avi -ovc xvid -xvidencopts bitrate=1024
mencoder "mf://ganim_*.png" -mf "type=png:fps=5" -o ganim.avi -ovc xvid -xvidencopts bitrate=1024
\rm ganim_0*.png
\rm ganim_0*.png
# view with mplayer
</pre>
</pre>




[[Category:FAQ]]
[[Category:FAQ]]

Revision as of 01:40, 5 February 2007

Q: How to construct high-quality MPEG-4 movies (animations) from a series of still frames?

Maris wrote:

Encode all .png files in directory to out.avi with 15 frames per second:

mencoder "mf:///path/to/files/*.png" -mf fps=15 -o out.avi # put -ovc here, see next lines
## for DivX - libavcodec MPEG 4 (DivX5), use:
-ovc lavc -lavcopts vcodec=mpeg4:vhq:vbitrate=1800 -ffourcc MP4S
## for XviD, use:
-ovc xvid -xvidencopts bitrate=1024
## for DivX4, use:
-ovc divx4 -divx4opts q=5

Uses mplayer's encoder. Choose one of encoding formats and append to end of "mencoder" line. Unfortunately only way to know quality settings is by encoding, watching result and reendocing with different params.

Notice - by default encoding with lavc will set video fourcc to FMP4, that can be decoded with ffdshow. Option -ffourcc MP4S will change it to MPS4 ("official" MS fourcc for mpeg4) and video will be playable on Windows by standart MS mpeg4 decoder. It may lead to side effects, if MS mpeg4 decoder is buggy. More info: http://www.itdp.de/mplayer-users/2005-03/msg00069.html



Q: How to generate an animated GIF, FLI, or MNG?

A: for animations of 300 frames or less, animated GIF, FLI, or MNG formats are smaller files and better quality (ie frames stored as PNG not JPEG). Create with gifsicle, ppm2fli, or for MNG use ImageMagick's 'convert'. With more than 300 frames the players usually have memory issues. Animated GIFs are playable in any web browser of course and also in OpenOffice.




Q: How to create dynamic surface movies in NVIZ

A: See slides from the FOSS4G 2006 workshop: http://skagit.meas.ncsu.edu/~helena/grasswork/foss4g/FOSS4G06WKSVisual4anim.odp

See also the example at the bottom of the NVIZ keyframe animator panel help page.



Q: How to animate a time series of raster maps?

A: Use



Q: How to animate a series of maps, including decorations?

A: Use the xmon drivers (d.mon) to render the displays to a window via a shell script loop, then switch from the x0 to PNGdriver to save as a series of PNG or PPM images. Use a method answered in a FAQ above to combine those into a single animation.

Examples

Animate on screen
GRASS_WIDTH=640 GRASS_HEIGHT=500 \
  d.mon start=x0

g.region rast=elevation.dem n=4927830 s=4912980

for NUM in `seq 1 0.5 10` ; do
   d.rast elevation.dem --quiet
   d.vect roads
   d.vect bugsites icon=basic/circle col=black fcol=green \
      size=`echo "21-($NUM * 2)" | bc`

   echo "symbol basic/arrow2 25 80 `echo "10*$NUM" | bc` 80:80:80 125:125:255" | d.graph

   echo "Spearfish, South Dakota" | d.text size=4.5 at=1,2.25
   d.barscale at=59.8,93.6 tcol=grey
done

Animate to files
# set up base map
g.region rast=elevation.dem n=4927830 s=4912980
export GRASS_WIDTH=640
export GRASS_HEIGHT=500
export GRASS_PNGFILE=base.ppm
export GRASS_PNG_READ=FALSE
d.mon start=PNG
  d.rast elevation.dem
  d.vect roads
  echo "Spearfish, South Dakota" | d.text size=4.5 at=1,2.25
  d.barscale at=59.8,93.6 tcol=grey
d.mon stop=PNG

# loop to draw variable parts as new frames
i=0
export GRASS_PNG_READ=TRUE
for NUM in `seq 1 0.5 10` ; do
   i=`expr $i + 1`
   FRAMENUM=`echo $i | awk '{printf("%03d", $1)}'`
   echo "Processing frame $FRAMENUM ..."
   export GRASS_PNGFILE="ganim_${FRAMENUM}.ppm"
   cp base.ppm "$GRASS_PNGFILE"
   d.mon start=PNG --quiet
   d.vect bugsites icon=basic/circle col=black fcol=green \
      size=`echo "21-($NUM * 2)" | bc`

   echo "symbol basic/arrow2 25 80 `echo "10*$NUM" | bc` 80:80:80 125:125:255" | d.graph
   d.mon stop=PNG --quiet
done

# repeat the last frame a few times
for EXTRA in 1 2 3 ; do
 i=`expr $i + 1`
 FRAMENUM=`echo $i | awk '{printf("%03d", $1)}'`
 cp base.ppm "ganim_${FRAMENUM}.ppm"
done
\rm base.ppm

Encode as animated GIF
  • Using the gifsicle encoder
  • View in a web browser
for IMG in ganim*.ppm ; do   # convert each frame from PPM to GIF
  ppmquant 256 $IMG | ppmtogif > "`basename $IMG .ppm`.gif"
done
gifsicle -O2 --delay 20 --no-loopcount --colors 256 ganim_*.gif > ganim.gif
\rm ganim_0*.gif
Encode as animated PNG (MNG)
  • Using the ImageMagick "convert" encoder
  • View with ImageMagick's "display"
convert -delay 20 ganim_*.ppm ganim.mng
Encode as FLI
  • Using the ppm2fli encoder
  • View with mplayer or xanim
ls ganim_*.ppm > frames.txt
ppm2fli -g"${GRASS_WIDTH}x${GRASS_HEIGHT}" -O -s 15 frames.txt ganim.fli
\rm frames.txt
Encode as MPEG-4 Xvid
  • Using the mencoder encoder
  • View with mplayer or similar

# doesn't like GRASS's PPMs, convert to PNG
for IMG in ganim*.ppm ; do
  pnmtopng $IMG > "`basename $IMG .ppm`.png"
done
mencoder "mf://ganim_*.png" -mf "type=png:fps=5" -o ganim.avi -ovc xvid -xvidencopts bitrate=1024
\rm ganim_0*.png