[MPlayer-users] Fitting a big file on a 700mb cd with mencoder?

Jesse McDonald JesseMcDonald at letu.edu
Mon Jul 26 09:57:28 CEST 2004


You may have already solved this problem, but I came up with a script
for this exact purpose. It calculates the bitrate necessary to give any
required filesize and reencodes. It assumes that you aren't changing the
codec (which is assumed to match your default codec). My default values
for the encoding are as follows:

# From ~/.mplayer/mencoder
oac=lavc=on
ovc=lavc=on
lavcopts=vcodec=mpeg4:acodec=mp2:abitrate=96:vme=5:vbitrate=800:vlelim=-4:vcelim=7:lumi_mask=0.07:dark_mask=0.10:mbd=0:vrc_eq=(tex/avgTex+1)^0.5:v4mv=on:vqblur=0.2:keyint=132:vdpart=on:vpsize=500:sc_threshold=-1000

(In case of wrapping, lavcopts is the last line. It's rather long.)

With these options I get 750MB / hour at 480x320 when recording from a
TV card (Pinnacle PCTV Rave) with the command-line parameters "-vf
pp=ci,scale=480:-2,denoise3d -af volume=10:sc -zoom -lavcopts
vbitrate=1600". That's before editing, and it works well enough with a
wide range of bitrates. On my 1.53GHz system (dual processor, but that
doesn't change much here), it has a 65% CPU load. I would consider the
quality near-broadcast -- very few noticable defects, most of which are
probably bugs and not the bitrate. (There's not much blurriness or
blocking, even when scaling (without postprocessing) to full screen, but
there are occasionally (~1 per 30 min) some places with the wrong colors
entirely.) Using libavcodec for the audio encoding is *much* faster, but
gives you MP2 audio, not MP3. Some Windows video editors (namely
VirtualDub) couldn't handle that last I tried and would only edit the
video stream.

Anyway, here's the script. I'm assuming version 1.0pre5 of mplayer:

#-----------------------------cut----------------------------------
#!/bin/sh

if [ $# -lt 2 ]; then
	echo 'Usage: recode-to-size old_file.avi new_file.avi [size]';
	exit 1;
fi

# File names
OLDFILE="$1";
NEWFILE="$2";

# Target filesize in MB
TARGET=$((${3:-700} * 1024**2));

# Current filesize
OLDSIZE=$(($(stat -c '%s' "$OLDFILE")));
if [ $? -ne 0 -o $OLDSIZE -le 0 ]; then
	echo "$OLDFILE does not appear to exist.";
	exit 1;
fi

if [ $OLDSIZE -le $TARGET ]; then
	echo "This file is already small enough!";
fi

# Existing video bitrate
OLD_BITRATE=$(($(
	mplayer "$OLDFILE" -identify -frames 0 2>/dev/null \
		| fgrep ID_VIDEO_BITRATE \
		| cut -c 11-
)));
if [ $? -ne 0 -o $OLD_BITRATE -le 0 ]; then
	echo "Unable to get the existing bitrate ($OLD_BITRATE).";

	# Calculate the bitrate
	# Length of file in seconds
	# Evaluate in a numeric context just to be on the safe side...
	DURATION=$(($(
		mplayer "$OLDFILE" -identify -frames 0 2>/dev/null \
			| fgrep ID_LENGTH \
			| cut -c 11-
	)));
	if [ $? -ne 0 -o $DURATION -le 0 ]; then
		echo "Unable to get the video duration ($DURATION).";
		exit 1;
	fi

	# 100000 is a rough estimate for audio (96 kbps) and overhead
	OLD_BITRATE=$((8 * $OLDSIZE / $DURATION - 100000));

	exit 1;
fi

# Calculated new video bitrate
NEW_BITRATE=$((($OLD_BITRATE * 95 / 100) * $TARGET / $OLDSIZE));

echo "Recoding from $OLD_BITRATE to $NEW_BITRATE bps..."

mencoder -oac copy -lavcopts vbitrate=$NEW_BITRATE "$OLDFILE" \
	-o "$NEWFILE"
#-----------------------------cut----------------------------------

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: <http://lists.mplayerhq.hu/pipermail/mplayer-users/attachments/20040726/75a8fa31/attachment.pgp>


More information about the MPlayer-users mailing list