[MPlayer-users] Request: some info about AVI and OGM file formats

Martin Collins martin at mkcollins.org
Sun Mar 23 17:16:16 CET 2003


On Sun, 23 Mar 2003 15:51:34 +0100
yardbird <frbiscani at libero.it> wrote:

> I am curious to see your script, if this is possible.

OK, my script follows. It is for encoding PAL TV I have captured as
mjpeg into mpeg4 + vorbis in an ogm container. It takes an editlist
created with mjpegtools, and uses mjpegtools (lav2wav, lav2yuv) to
convert the mjpeg into pcm audio which is piped into oggenc and
yuv4mpeg video which is piped in to mencoder.

#!/bin/sh
#
# name is the basename of the editlist file without extension
# height, width and the offsets are crop parameters
# height and width should be divisible by 16 to make life easier for the encoder
# target_size is in MB
#
if [ $# -ne 6 ] ; then
	echo "encedl name width height x_offset y_offset target_size"
	exit
fi

NAME=$1
WIDTH=$2
HEIGHT=$3
XOFFSET=$4
YOFFSET=$5
TARGET_SIZE=$6

# PAL pixels are not square, set AR to compensate
# only works with mplayer, use -vop scale instead for portability
W=`echo "w = $WIDTH * 1.094 ; d = w % 16 ; w - d" | bc | cut -d. -f1`
ASPECT="$W/$HEIGHT"
echo $ASPECT

# split out the audio and encode it to vorbis
if [ ! -e $NAME.ogg ] ; then
	lav2wav $NAME.edl | oggenc -q 0 -o $NAME.ogg -
	# see http://www.replaygain.org/ for an explanation of this
	vorbisgain $NAME.ogg
fi

# video bitrate - 800 gives <7MB/minute 1000 gives <8MB/minute
#BITRATE=925  # gives 100 mins per 700MB
#BITRATE=1075 # gives 100 mins per 800MB

if [ "$TARGET_SIZE" = 0 ] ; then
	# Size is not important so set an arbitrary bitrate
	BITRATE=1075
else
	# figure out what bitrate we need to get our target size
	OGG_SIZE=`ogginfo $NAME.ogg | grep data | cut -d' ' -f4`
	OVERHEAD=`echo "$TARGET_SIZE / 100 * 1024 * 1024 * 1.5" | bc`
	VIDEO_SIZE=`echo "$TARGET_SIZE * 1024 * 1024 - $OGG_SIZE - $OVERHEAD" | bc`
	MINS=`ogginfo $NAME.ogg | grep Playback | cut -d' ' -f3 | cut -dm -f1`
	SECS=`ogginfo $NAME.ogg | grep Playback | cut -d' ' -f3 | cut -d: -f2 | cut -ds -f1`
	DURATION=`echo "$MINS * 60 + $SECS" | bc`
	BITRATE=`echo "$VIDEO_SIZE * 8 / $DURATION / 1000" | bc`
fi
echo $BITRATE

# first pass of the video to gather statistics for encoding pass
lav2yuv $NAME.edl | \
mencoder -nosound -noaspect \
 -ovc lavc -lavcopts vcodec=mpeg4:trell:subcmp=2:cmp=2:precmp=2:vhq:keyint=100:vqcomp=0.8:vqmin=2:vqmax=31:vpass=1:vlelim=-4:vcelim=9:lumi_mask=0.05:dark_mask=0.01:tcplx_mask=0.01:scplx_mask=0.01:naq:v4mv:aspect=$ASPECT:vbitrate=$BITRATE \
 -vop denoise3d,pp=lb/tn:64:128:256/dr/h1/v1,crop=$WIDTH:$HEIGHT:$XOFFSET:$YOFFSET \
 -o /dev/null -

# second pass of video - actually encode it
lav2yuv $NAME.edl | \
mencoder -nosound -noaspect \
 -ovc lavc -lavcopts vcodec=mpeg4:psnr:trell:subcmp=2:cmp=2:precmp=2:vhq:keyint=100:vqcomp=0.8:vqmin=2:vqmax=31:vpass=2:vlelim=-4:vcelim=9:lumi_mask=0.05:dark_mask=0.01:tcplx_mask=0.01:scplx_mask=0.01:naq:v4mv:aspect=$ASPECT:vbitrate=$BITRATE \
 -vop denoise3d,pp=lb/tn:64:128:256/dr/h1/v1,crop=$WIDTH:$HEIGHT:$XOFFSET:$YOFFSET \
 -o $NAME.divx - | tee out.tmp

# mux the audio and video together into an ogg container
ogmmerge -o $NAME.ogm -A $NAME.divx $NAME.ogg

# make a log file of bitrate, quantizer, psnr
avgquant < divx2pass.log > $NAME.log
cat out.tmp | grep kbit >> $NAME.log
cat out.tmp | grep PSNR >> $NAME.log
cat $NAME.log

# cleanup
rm out.tmp
rm divx2pass.log
rm psnr*.log
#rm $NAME.ogg
#rm $NAME.divx
#rm $NAME.avi



More information about the MPlayer-users mailing list