meta data for this page
Video Encoding
Instructions for encoding videos with mencoder. The demostrated settings are for 30 fps. Frame size is preferred to be divideable by 16.
Creating frame list
Create a title image, the same size as all other content. Add 5 seconds of title first:
bash$ for f in {1..150}; do echo title3d.png >> vidcont.txt; done
Mencoder does not read PPM files, so they have to be converted to e.g. PNG:
bash$ for f in *.ppm; do echo $f; convert -depth 8 $f foo/${f%ppm}png; done
Then add all your frames:
bash$ ls -1 --color=none foo/*.png >> vidcont.txt
Now vidcont.txt
is your frame list. You can preview your video with
bash$ mplayer mf://@vidcont.txt -mf type=png:fps=30
MPEG 4 / AVI
Excerpt from ~/.mplayer/mencoder.conf
[mpeg4cg] profile-desc="MPEG4 for computer graphics" ovc=lavc=yes lavcopts=vcodec=mpeg4:vbitrate=1400 ffourcc=XVID lavcopts=mbd=2:mv0=yes:trell=yes:v4mv=yes:cbp=yes:last_pred=3:predia=2:dia=2 lavcopts=vmax_b_frames=2:vb_strategy=1:precmp=2:cmp=2:subcmp=2:preme=2 [mpeg4cg-1] profile-desc="mpeg4cg, pass 1" profile=mpeg4cg lavcopts=vpass=1:turbo=yes [mpeg4cg-2] profile-desc="mpeg4cg, pass 2" profile=mpeg4cg lavcopts=vpass=2
These settings are based on the very high quality setting at mencoder libavcodec example settings. About the standard mpeg4, see http://wiki.multimedia.cx/index.php?title=ISO_MPEG-4 .
The 2-pass encoding is done by:
bash$ mencoder mf://@vidcont.txt -mf type=png:fps=30 -profile mpeg4cg-1 -o video.avi bash$ mencoder mf://@vidcont.txt -mf type=png:fps=30 -profile mpeg4cg-2 -o video.avi
MPEG 1
Excerpt from ~/.mplayer/mencoder.conf
[mpeg1cg] profile-desc="universal MPEG1 for computer graphics" of=mpeg=yes mpegopts=format=mpeg1:tsaf=yes:muxrate=2000 noskip=yes ovc=lavc=yes lavcopts=vcodec=mpeg1video:vbitrate=1152:keyint=15:mbd=2:aspect=4/3 [mpeg1cg-1] profile-desc="mpeg1cg, pass 1" profile=mpeg1cg lavcopts=vpass=1:turbo=yes [mpeg1cg-2] profile-desc="mpeg1cg, pass 2" profile=mpeg1cg lavcopts=vpass=2
These settings are based on encoding to mpeg format instructions for “suitable to be played on systems with minimal multimedia support”. Notice the 4:3 aspect ratio.
The 2-pass encoding is done by:
bash$ mencoder mf://@vidcont.txt -mf type=png:fps=30 -profile mpeg1cg-1 -o video.mpg bash$ mencoder mf://@vidcont.txt -mf type=png:fps=30 -profile mpeg1cg-2 -o video.mpg
MPEG 1 high VBR for Windows XP
Excerpt from ~/.mplayer/mencoder.conf
[mpeg1cgh] profile-desc="universal MPEG1 for computer graphics, 1.8Mbps raw" of=rawvideo=yes noskip=yes ovc=lavc=yes lavcopts=vcodec=mpeg1video:vbitrate=1835:keyint=15:mbd=2:aspect=4/3 [mpeg1cgh-1] profile-desc="mpeg1cg, pass 1" profile=mpeg1cgh lavcopts=vpass=1:turbo=yes [mpeg1cgh-2] profile-desc="mpeg1cg, pass 2" profile=mpeg1cgh lavcopts=vpass=2
The 2-pass encoding is done by:
bash$ mencoder mf://@vidcont.txt -mf type=png:fps=30 -profile mpeg1cgh-1 -o video.raw bash$ mencoder mf://@vidcont.txt -mf type=png:fps=30 -profile mpeg1cgh-2 -o video.raw bash$ mplex -f 0 -b 230 -r 3500 video.raw -o video.mpg
Mplex command is part of mjpegtools package. First the raw mpeg1 video is encoded, and put into mpg-container with mplex, because mencoder's mpeg muxer does something wrong. The end result is a video, that should work on a Windows XP out-of-the-box, but as a file is larger than needed. It compresses up to the expected video file size.
Preprocessing Tricks
Creating composite images with ImageMagick convert
> http://www.imagemagick.org/Usage/layers/
bash$ convert -depth 8 -size 384x288 xc:black pic1.ppm -flip -composite pic2.ppm -geometry 100x50+0+50 -composite output.png