digitalFAQ.com Forums [Archives]

digitalFAQ.com Forums [Archives] (http://www.digitalfaq.com/archives/)
-   Video Encoding and Conversion (http://www.digitalfaq.com/archives/encode/)
-   -   KVCD using Menkoder? (http://www.digitalfaq.com/archives/encode/6958-kvcd-menkoder.html)

russiansexpat 12-02-2003 07:17 AM

KVCD using Menkoder?
 
http://www.digitalfaq.com/archives/error.gif

It is a template script, not interactive. If you are a developer (I'm a not) you can encapsulate into interactive script or GUI, gtk preferable.

In the script you have at least to chose resolution width*height, fps (if you change them), mpeg (1 or 2) and vcd type for multiplexing and imaging.
Video bitrate can be entered in commad line, so don't edit it.
Edit the section between dash lines. The script is capable to scale into NTSC/PAL dimensions if the source is fit - width is used as a base to scale (with original aspect ratio), so scaled height have to be within allowed height for NTSC or PAL.
It is assumed that you know xvcd and svcd specifications and familiar with mencoder options.

(I've just checked on a stream capture that telecine from 10fps to 27.97fps is bearable, but still the problems with video-audion sync. The same situation with inverse telecine from 27.97fps to 25fps).

russiansexpat 12-02-2003 11:24 AM

Code:

#!/bin/bash
#
# Copyright (C) 2003-2038 russiansexpat
#
# script:      mpeg(1,2,3,4) conversion to (S,X)VCD with quantisation matrix
#              and auto-splitting into multiple CDs and writing them.
#
# requires:    mencoder mplayer ffmpeg tcmplex vcdimager cdrdao

for exe in mencoder mplayer ffmpeg tcmplex vcdimager cdrdao; do
  if [ -z "`which $exe`" ]; then
      echo "ERROR: $exe must be in your path $PATH"
      exit 1
  fi
done

MATRIX="\
intra_matrix=\
8,9,12,22,26,27,29,34,\
9,10,14,26,27,29,34,37,\
12,14,18,27,29,34,37,38,\
22,26,27,31,36,37,38,40,\
26,27,29,36,39,38,40,48,\
27,29,34,37,38,40,48,58,\
29,34,37,38,40,48,58,69,\
34,37,38,40,48,58,69,79:\
inter_matrix=\
16,18,20,22,24,26,28,30,\
18,20,22,24,26,28,30,32,\
20,22,24,26,28,30,32,34,\
22,24,26,30,32,32,34,36,\
24,26,28,32,34,34,36,38,\
26,28,30,32,34,36,38,40,\
28,30,32,34,36,38,42,42,\
30,32,34,36,38,40,42,44\
"

VBITRATE=1152 # 1 = 1000 bits

#---------- below you can edit parameters ----------

SWS=0 # fast bilinear
#SWS=2 # bicubic (for upscaling)
#SWS=9 # lanczos (quality? slow)

VFILTER="denoise3d,eq2,"

#FPS=",telecine,lavcdeint -fps 29.97 -ofps 29.97"
#FPS=" -ofps 29.97"  # NTSC
#FPS=" -ofps 25"    # PAL
#FPS=" -ofps 23.976" # NTSC pulldowned
#FPS=",ivtc=1 -ofps 23.976"
#FPS=" -ofps 10" # must for variable and progressive fps

# for vcd
WID=352
#HEI=240
HEI=288
VCODEC=mpeg1video
AUDIORATE=128
MUXMODE="-m 1 -F tcmplex.tmp"
IMAMODE="-t vcd2"

# for svcd
#WID=480
#HEI=480
#HEI=576
#VCODEC=mpeg2video
#AUDIORATE=224
#MUXMODE="-m s -F tcmplex.tmp"
#IMAMODE="-t svcd"

LAVCOPTS=":vlelim=-4:vcelim=7:lumi_mask=0.05:dark_mask=0.01"

PASS="single"
#PASS="1st 2nd"

NOTverbose="2> /dev/null"
#NOTverbose="&> /dev/null"

#CDSIZE=735 # 74min CD
CDSIZE=795 # 80min CD
#CDSIZE=895 # 90min CD

CDOPT="--force --reload --eject"
CDDEV="--device 0,4,0"

#---------- above you can edit parameters ----------

function usage() {
  echo
  echo "Usage:  $HOWCALLED <shrunk name> <file or mplayer source> [variable video bitrate kbs [$VBITRATE]]"
  echo
  echo "result: (S,X)VCD and mpeg(1,2) encoded with $HOWCALLED."
  echo
exit 1
}

HOWCALLED=`basename $0`
[ $# -lt 2 ] && usage

case $1 in
  -*)
      usage
  ;;
  *)
      NAME=$1
      shift 1
  ;;
esac

DIR="`pwd`"
FILE=$1
if [ "$1" == "`basename \"$1\"`" ]; then
  FILE="$DIR/$1"
fi
shift 1

if [ "$1"x != "x" ]; then
  VBITRATE=$1
  shift 1
fi

COMMAND_LINE_MENCODER=$*

rm -rf divx2pass.log
rm -rf frameno.avi

for word in $PASS ; do
  VIDEO="video.mpg"
  [ "$word" == "single"  ] && pass=""
  [ "$word" == "1st"  ] && pass=":vpass=1"
  [ "$word" == "1st"  ] && VIDEO="/dev/null"
  [ "$word" == "2nd"  ] && pass=":vpass=2"

  command="mencoder -sws $SWS -vf ${VFILTER}scale=$WID:-3,expand=0:$HEI${FPS} \
  -forceidx -of mpeg -nosound \
  -ovc lavc -lavcopts vcodec=$VCODEC:$MATRIX:mbd=2:vbitrate=$VBITRATE:vrc_minrate=300:vrc_maxrate=2300:vrc_buf_size=320:keyint=25${LAVCOPTS}$pass \
  $COMMAND_LINE_MENCODER $FILE -o $VIDEO"

  echo "$command $NOTverbose"
  eval "$command $NOTverbose"
done

rm -rf $NAME.mpv
eval "mplayer -noframedrop -vc dummy -vo null -dumpvideo -dumpfile $NAME.mpv $VIDEO &> /dev/null &"

AUDIO="audio.wav"
rm -f $AUDIO
mkfifo -m 660 $AUDIO

eval "mplayer -noframedrop -vc dummy -vo null -ao pcm -waveheader -aofile $AUDIO $FILE &> /dev/null &"
eval "ffmpeg -y -i $AUDIO -ab $AUDIORATE -ar 44100 -ac 2 -f mp2 $NAME.mpa &"
#eval "lame -h --abr $AUDIORATE --resample 44.1 - $NAME.mpa < $AUDIO &"

wait

rm -f $VIDEO
rm -f $AUDIO

rm -f $NAME??.mpg
echo "maxFileSize = $CDSIZE" > tcmplex.tmp
eval "tcmplex $MUXMODE -i $NAME.mpv -p $NAME.mpa -o $NAME.mpg"
rm -f tcmplex.tmp

for i in $NAME??.mpg; do
  cue="`basename $i .mpg`.cue"
  bin="`basename $i .mpg`.bin"
  rm -f $cue $bin
  eval "vcdimager $IMAMODE -c $cue -b $bin $i"
done

echo -e "\n$HOWCALLED encoding is completed in $SECONDS seconds.\n"

for cue in $NAME??.cue; do
  bin="`basename $cue .cue`.bin"
  echo "PLEASE INSERT BLANK CD IN CD-WRITER, after a keypress we start:"
  read -n 1 null
  eval "cdrdao write $CDOPT $CDDEV $cue"
  echo "CD WRITING IS COMPLETED."
done

exit 0
# last line of this script


russiansexpat 12-05-2003 02:33 AM

Scaling to correct VCD and SVCD aspects is not implemented in this script. There is useful page about video resolutions and aspect ratio conversions:
:arrow: http://www.uwasa.fi/~f76998/video/conversion/
:arrow: http://hkfanatic.com/widescreen/

Currently I use the script for pre- and post-processing for XVCD and SVCD.
If somebody can add scaling into the script?

Code:

#!/bin/bash
#
# Copyright (C) 2003-2038 russiansexpat
#
# script:      mpeg(1,2,3,4) conversion to (S,X)VCD with quantisation matrix
#              and auto-splitting into multiple CDs and writing them.
#
# requires:    mencoder mplayer ffmpeg tcmplex vcdimager cdrdao
#
# does not require: microsoft. This script has not been tested on animals.

for exe in mencoder mplayer ffmpeg tcmplex vcdimager cdrdao; do
  if [ -z "`which $exe`" ]; then
      echo "ERROR: $exe must be in your path $PATH"
      exit 1
  fi
done

MATRIX="\
intra_matrix=\
8,9,12,22,26,27,29,34,\
9,10,14,26,27,29,34,37,\
12,14,18,27,29,34,37,38,\
22,26,27,31,36,37,38,40,\
26,27,29,36,39,38,40,48,\
27,29,34,37,38,40,48,58,\
29,34,37,38,40,48,58,69,\
34,37,38,40,48,58,69,79:\
inter_matrix=\
16,18,20,22,24,26,28,30,\
18,20,22,24,26,28,30,32,\
20,22,24,26,28,30,32,34,\
22,24,26,30,32,32,34,36,\
24,26,28,32,34,34,36,38,\
26,28,30,32,34,36,38,40,\
28,30,32,34,36,38,42,42,\
30,32,34,36,38,40,42,44\
"

VBITRATE=2300 # 1 = 1000 bits

#---------- below you can edit parameters ----------

#AUDIORATE=128
AUDIORATE=224

# see 'man mencoder'
LAVCOPTS=":vlelim=-4:vcelim=7:lumi_mask=0.05:dark_mask=0.01"
#

PASS="single"
#PASS="1st 2nd"

NOTverbose="2> /dev/null"
#NOTverbose="&> /dev/null"

# for vcd
#VCODEC=mpeg1video
#MUXMODE="-m 1 -F tcmplex.tmp"
#IMAMODE="-t vcd2"

# for svcd
VCODEC=mpeg2video
MUXMODE="-m s -F tcmplex.tmp"
IMAMODE="-t svcd"

#CDSIZE=735 # 74min CD
CDSIZE=795 # 80min CD
#CDSIZE=895 # 90min CD

CDOPT="--force --reload --eject"
CDDEV="--device 0,4,0"

#---------- above you can edit parameters ----------

function usage() {
  echo
  echo "Usage:  $HOWCALLED <shrunk name> <file or mplayer source> [variable video bitrate kbs [$VBITRATE]]"
  echo
  echo "result: (S,X)VCD and mpeg(1,2) encoded with $HOWCALLED."
  echo
exit 1
}

HOWCALLED=`basename $0`
[ $# -lt 2 ] && usage

case $1 in
  -*)
      usage
  ;;
  *)
      NAME=$1
      shift 1
  ;;
esac

DIR="`pwd`"
FILE=$1
if [ "$1" == "`basename \"$1\"`" ]; then
  FILE="$DIR/$1"
fi
shift 1

if [ "$1"x != "x" ]; then
  VBITRATE=$1
  shift 1
fi

COMMAND_LINE_MENCODER=$*

rm -rf divx2pass.log
rm -rf frameno.avi

for word in $PASS ; do
  VIDEO="video.mpg"
  [ "$word" == "single"  ] && pass=""
  [ "$word" == "1st"  ] && pass=":vpass=1"
  [ "$word" == "1st"  ] && VIDEO="/dev/null"
  [ "$word" == "2nd"  ] && pass=":vpass=2"

  command="mencoder \
  -forceidx -of mpeg -nosound \
  -ovc lavc -lavcopts vcodec=$VCODEC:$MATRIX:mbd=2:vbitrate=$VBITRATE:vrc_minrate=300:vrc_maxrate=2300:vrc_buf_size=320:keyint=25${LAVCOPTS}$pass \
  $COMMAND_LINE_MENCODER $FILE -o $VIDEO"

  echo "$command $NOTverbose"
  eval "$command $NOTverbose"
done

rm -rf $NAME.mpv
eval "mplayer -noframedrop -vc dummy -vo null -dumpvideo -dumpfile $NAME.mpv $VIDEO &> /dev/null &"

AUDIO="audio.wav"
rm -f $AUDIO
mkfifo -m 660 $AUDIO

eval "mplayer -noframedrop -vc dummy -vo null -ao pcm -waveheader -aofile $AUDIO $FILE &> /dev/null &"
eval "ffmpeg -y -i $AUDIO -ab $AUDIORATE -ar 44100 -ac 2 -f mp2 $NAME.mpa &"
#eval "lame -h --abr $AUDIORATE --resample 44.1 - $NAME.mpa < $AUDIO &"

wait

rm -f $VIDEO
rm -f $AUDIO

rm -f $NAME??.mpg
echo "maxFileSize = $CDSIZE" > tcmplex.tmp
eval "tcmplex $MUXMODE -i $NAME.mpv -p $NAME.mpa -o $NAME.mpg"
rm -f tcmplex.tmp

for i in $NAME??.mpg; do
  cue="`basename $i .mpg`.cue"
  bin="`basename $i .mpg`.bin"
  rm -f $cue $bin
  eval "vcdimager $IMAMODE -c $cue -b $bin $i"
done

echo -e "\n$HOWCALLED encoding is completed in $SECONDS seconds.\n"

for cue in $NAME??.cue; do
  bin="`basename $cue .cue`.bin"
  echo "PLEASE INSERT BLANK CD IN CD-WRITER, after a keypress we start:"
  read -n 1 null
  eval "cdrdao write $CDOPT $CDDEV $cue"
  echo "CD WRITING IS COMPLETED."
done

exit 0
# last line of this script

Just compared - two pass is slow 4 times compared to single pass, but it is still faster than using mpeg2enc form mjpegtools. Also, it appears that taking out video filters and scaling does not speed things up, i.e. most of the time spent by encoder itself. So, maybe to fall back to previous version with video filter, scaling and fps conversion?

Icarus3000 12-05-2003 12:01 PM

Russiansexpat:

You appear to be having an interesting discourse with yourself!

Can you or someone else explain what it is you are talking about?


:roll:

kwag 12-05-2003 02:35 PM

Quote:

Originally Posted by Icarus3000
Russiansexpat:

You appear to be having an interesting discourse with yourself!

Not at all :!:
This is an advanced topic, and very good information :cool:
This is related to Linux and Unix systems.

-kwag

Icarus3000 12-05-2003 03:28 PM

Sorry, I guess this is just out of my league :oops:

I was just curious what he was talking about, as noone else was responding.

russiansexpat 12-05-2003 04:09 PM

http://www.digitalfaq.com/archives/error.gif

Encoder Master 12-06-2003 04:13 AM

:lol:

japie 12-08-2003 01:14 PM

Quote:

Originally Posted by russiansexpat
two pass is slow 4 times compared to single pass, but it is still faster than using mpeg2enc form mjpegtools.

It doesn't have to be, a 2pass with mencoder/ffmpeg is about 1,5 slower than 1 pass, since you can use dev/null as output the first pass.
I use the following: (you need mplayer-cvs for this)
Code:

#!/bin/bash

keyint=24
scale="scale=352:240"
abitrate=112

matrix="8,9,12,22,26,27,29,34,9,10,14,26,27,29,34,37,12,14,18,27,29,34,37,38,22,26,27,31,36,37,38,40,26,27,29,36,39,38,40,48,27,29,34,37,38,40,48,58,29,34,37,38,40,48,58,69,34,37,38,40,48,58,69,79"
inter_matrix="16,18,20,22,24,26,28,30,18,20,22,24,26,28,30,32,20,22,24,26,28,30,32,34,22,24,26,30,32,32,34,36,24,26,28,32,34,34,36,38,26,28,30,32,34,36,38,40,28,30,32,34,36,38,42,42,30,32,34,36,38,40,42,44"

mencoder $1 -of mpeg -ovc lavc -oac lavc -lavcopts \
pass=1:acodec=mp2:abitrate=$abitrate:vcodec=mpeg1video:keyint=$keyint:mbd=2:vrc_minrate=64:vrc_maxrate=3000:vrc_buf_size=320:aspect=16/9:\
intra_matrix=$matrix:inter_matrix=$inter_matrix -vf $scale -o /dev/null
mencoder $1 -of mpeg -ovc lavc -oac lavc -lavcopts \
vpass=2:acodec=mp2:abitrate=$abitrate:vcodec=mpeg1video:keyint=$keyint:mbd=2:vrc_minrate=64:vrc_maxrate=3000:vrc_buf_size=320:aspect=16/9:\
intra_matrix=$matrix:inter_matrix=$inter_matrix -vf $scale -o divx2kvcd.mpg

Quote:

Originally Posted by russiansexpat
Also, it appears that taking out video filters and scaling does not speed things up, i.e. most of the time spent by encoder itself. So, maybe to fall back to previous version with video filter, scaling and fps conversion?

All you do will make encoding slower... (denoise the less and scaling the most)

russiansexpat 12-08-2003 03:51 PM

Below is a version of the script with constant quality encoding, and I put some comments in the code.
It appears to be faster and easy to use, just watch output line of mencoder - last field of this line is a current encoding bitrate, and also in this line you can see estimated time of completion and file size, so you can terminate the script if you don't like them.
Compression is improved, maybe because of ":naq:dia=2:last_pred=2" adaptive quantisation and motion prediction parameters. Currently I can fit 1.5 hour movie at SVCD resolution with vbitrate around 1200 kbps into single CD. Constant quality is less than 6.
(some minor problem with maxrate - when you select high quality, the maxrate is exceeded; nevertheless tcmplex clipped bitrates to 2300 max and vcdimager didn't complain.)

Code:

#!/bin/bash
#
# Copyright (C) 2003-2038 russiansexpat
#
# script:      mpeg(1,2,3,4) conversion to (S,X)VCD with quantisation matrix
#              and auto-splitting into multiple CDs and writing them.
#
# requires:    mencoder mplayer ffmpeg tcmplex vcdimager cdrdao
#
# does not require: microsoft. This script has not been tested on animals.

for exe in mencoder mplayer ffmpeg tcmplex vcdimager cdrdao; do
  if [ -z "`which $exe`" ]; then
      echo "ERROR: $exe must be in your path $PATH"
      exit 1
  fi
done

MATRIX="\
intra_matrix=\
8,9,12,22,26,27,29,34,\
9,10,14,26,27,29,34,37,\
12,14,18,27,29,34,37,38,\
22,26,27,31,36,37,38,40,\
26,27,29,36,39,38,40,48,\
27,29,34,37,38,40,48,58,\
29,34,37,38,40,48,58,69,\
34,37,38,40,48,58,69,79:\
inter_matrix=\
16,18,20,22,24,26,28,30,\
18,20,22,24,26,28,30,32,\
20,22,24,26,28,30,32,34,\
22,24,26,30,32,32,34,36,\
24,26,28,32,34,34,36,38,\
26,28,30,32,34,36,38,40,\
28,30,32,34,36,38,42,42,\
30,32,34,36,38,40,42,44\
"

Q="6" # constant video quality
      # best=2 excellent<=4 good<=7 even=11 for XVCD
      #        excellent<=6 good<=9 even=13 for SVCD

#---------- below you can edit parameters ----------

# audio bitrate
AUDIORATE=128
#AUDIORATE=224

# scaling algorithm
#SWS=0 # fast bilinear
SWS=2 # bicubic (for upscaling)
#SWS=9 # lanczos (quality? slow)

# video filters
VFILTER="pp=de,denoise3d,"

# for frame rate conversions
#FPS=",telecine,lavcdeint -fps 29.97 -ofps 29.97" # to increase fps
#FPS=" -ofps 29.97"  # NTSC
#FPS=" -ofps 25"    # PAL
#FPS=" -ofps 23.976" # NTSC pulldowned
#FPS=",ivtc=1 -ofps 23.976" # to decrease fps

# aspect view of output;
# it should be the same as aspect view of the source mpeg(1,2)
# or equal to width/length if source aspect undefined (example: avi, capture)
# and your player has to be capable to process chosen aspect
#
#ASPECT="1" # 1:1 where have you seen square TV ?!
ASPECT="1.3333" # 4:3 standard TV or monitor
#ASPECT="1.7777" # 16:9 wide screen

# for xvcd
#XY="352:240"
#XY="352:288"
#VCODEC=mpeg1video
#MUXMODE="-m 1 -F tcmplex.tmp"
#IMAMODE="-t vcd2"

# for svcd
#XY="480:480"
XY="480:576"
VCODEC=mpeg2video
MUXMODE="-m s -F tcmplex.tmp"
IMAMODE="-t svcd"

# see 'man mencoder'
LAVCOPTS=":vlelim=-4:vcelim=7:lumi_mask=0.05:dark_mask=0.01:naq:dia=2:last_pred=2"
#

PASS="single"
#PASS="1st 2nd"

# mencoder verbosity
NOTverbose="2> /dev/null"
#NOTverbose="&> /dev/null"

#CDSIZE=735 # 74min CD
CDSIZE=795 # 80min CD
#CDSIZE=895 # 90min CD

# cdrdao parameters
CDOPT="--force --reload --eject"
CDDEV="--device 0,4,0" # SCSI id

#---------- above you can edit parameters ----------

function usage() {
  echo
  echo "Usage:  $HOWCALLED <shrunk name> <file or mplayer source> [quality [$Q]]"
  echo
  echo "qualilty: best=2 excellent<=4 good<=7 even=11 - XVCD"
  echo "                excellent<=6 good<=9 even=13 - SVCD"
  echo
  echo "result: (S,X)VCD and mpeg(1,2) encoded with $HOWCALLED."
  echo
exit 1
}

HOWCALLED=`basename $0`
[ $# -lt 2 ] && usage

case $1 in
  -*)
      usage
  ;;
  *)
      NAME=$1
      shift 1
  ;;
esac

DIR="`pwd`"
FILE=$1
if [ "$1" == "`basename \"$1\"`" ]; then
  FILE="$DIR/$1"
fi
shift 1

if [ "$1"x != "x" ]; then
  Q=$1
  shift 1
fi

COMMAND_LINE_MENCODER=$*

rm -rf divx2pass.log
rm -rf frameno.avi

for word in $PASS ; do
  VIDEO="video.mpg"
  [ "$word" == "single"  ] && pass=""
  [ "$word" == "1st"  ] && pass=":vpass=1"
  [ "$word" == "1st"  ] && VIDEO="/dev/null"
  [ "$word" == "2nd"  ] && pass=":vpass=2"

  command="mencoder -sws $SWS -vf ${VFILTER}scale=$XY${FPS} \
  -forceidx -of mpeg -nosound \
  -ovc lavc -lavcopts aspect=$ASPECT:vcodec=$VCODEC:$MATRIX:mbd=2:vqscale=$Q:vrc_minrate=300:vrc_maxrate=2300:vrc_buf_size=320:keyint=25${LAVCOPTS}$pass \
  $COMMAND_LINE_MENCODER $FILE -o $VIDEO"

  echo "$command $NOTverbose"
  eval "$command $NOTverbose"
done

rm -rf $NAME.mpv
eval "mplayer -noframedrop -vc dummy -vo null -dumpvideo -dumpfile $NAME.mpv $VIDEO &> /dev/null &"

AUDIO="audio.wav"
rm -f $AUDIO
mkfifo -m 660 $AUDIO

eval "mplayer -noframedrop -vc dummy -vo null -ao pcm -waveheader -aofile $AUDIO $FILE &> /dev/null &"
eval "ffmpeg -y -i $AUDIO -ab $AUDIORATE -ar 44100 -ac 2 -f mp2 $NAME.mpa &"
#eval "lame -h --abr $AUDIORATE --resample 44.1 - $NAME.mpa < $AUDIO &"

wait

rm -f $VIDEO
rm -f $AUDIO

rm -f $NAME??.mpg
echo "maxFileSize = $CDSIZE" > tcmplex.tmp
eval "tcmplex $MUXMODE -i $NAME.mpv -p $NAME.mpa -o $NAME.mpg"
rm -f tcmplex.tmp

for i in $NAME??.mpg; do
  cue="`basename $i .mpg`.cue"
  bin="`basename $i .mpg`.bin"
  rm -f $cue $bin
  eval "vcdimager $IMAMODE -c $cue -b $bin $i"
done

echo -e "\n$HOWCALLED encoding is completed in $SECONDS seconds.\n"

for cue in $NAME??.cue; do
  bin="`basename $cue .cue`.bin"
  echo "PLEASE INSERT BLANK CD IN CD-WRITER, after a keypress we start:"
  read -n 1 null
  eval "cdrdao write $CDOPT $CDDEV $cue"
  echo "CD WRITING IS COMPLETED."
done

exit 0
# last line of this script


neturmel 12-09-2003 06:32 AM

That is a really nice thread, got some ideas. But to give you something back, here some thoughts:

if you use mplayer-cvs you can do it like japie wroteabove: audio encoding directly with mencoder, but can using a three pass method, in which you only encode audio once and get a prediction in the end of the first pass, which gives you an estimation of the bitrate one should use for video encoding.

This can be used for setting the vbitrate automatically (as this estimation isn't meant for kvcds, it probably must be trimmed somewhat).

Also, you can use cropdetect and crop to get rid of the black bands and the scale and expand to have your aspect ratio correct.

So here are my modifications of the vbr script for trying yourself:

Code:

#!/bin/bash
#
# Copyright (C) 2003-2038 russiansexpat
# Three pass encoding by neturmel (C) 2003
#
# script:      mpeg(1,2,3,4) conversion to (S,X)VCD with quantisation matrix
#              and auto-splitting into multiple CDs and writing them.
#
# requires:    mencoder mplayer ffmpeg tcmplex vcdimager cdrdao

for exe in mencoder mplayer ffmpeg tcmplex vcdimager cdrdao; do
  if [ -z "`which $exe`" ]; then
      echo "ERROR: $exe must be in your path $PATH"
      exit 1
  fi
done

MATRIX="\
intra_matrix=\
8,9,12,22,26,27,29,34,\
9,10,14,26,27,29,34,37,\
12,14,18,27,29,34,37,38,\
22,26,27,31,36,37,38,40,\
26,27,29,36,39,38,40,48,\
27,29,34,37,38,40,48,58,\
29,34,37,38,40,48,58,69,\
34,37,38,40,48,58,69,79:\
inter_matrix=\
16,18,20,22,24,26,28,30,\
18,20,22,24,26,28,30,32,\
20,22,24,26,28,30,32,34,\
22,24,26,30,32,32,34,36,\
24,26,28,32,34,34,36,38,\
26,28,30,32,34,36,38,40,\
28,30,32,34,36,38,42,42,\
30,32,34,36,38,40,42,44\
"

VBITRATE=1152 # 1 = 1000 bits

#---------- below you can edit parameters ----------

SWS=0 # fast bilinear
#SWS=2 # bicubic (for upscaling)
#SWS=9 # lanczos (quality? slow)

# Some possible filters
VFILTER="pp=de,denoise3d,"
#VFILTER="denoise3d,eq2,"
#VFILTER="noise=luma[h]:chroma[h],hqdn3d=4:3:6,"

# some LAVCOPTS
#LAVCOPTS=":vlelim=-4:vcelim=7:lumi_mask=0.05:dark_mask=0.01"
LAVCOPTS="mbd=2:vlelim=-4:vcelim=7:lumi_mask=0.05:dark_mask=0.01:naq:dia=2:last_pred=2"
#LAVCOPTS="mbd=2:mv0:trell:cbp:precmp=2:cmp=2:subcmp=2:predia=2:dia=2:preme=2:vme=5:naq"

#FPS=",telecine,lavcdeint -fps 29.97 -ofps 29.97"
#FPS=" -ofps 29.97"  # NTSC
#FPS=" -ofps 25"    # PAL
#FPS=" -ofps 23.976" # NTSC pulldowned
#FPS=",ivtc=1 -ofps 23.976"
#FPS=" -ofps 10" # must for variable and progressive fps

# for vcd
WID=352
#HEI=240
HEI=288
VCODEC=mpeg1video
AUDIORATE=128
MUXMODE="-m 1 -F tcmplex.tmp"
IMAMODE="-t vcd2"

# for svcd
#WID=480
#HEI=480
#HEI=576
#VCODEC=mpeg2video
#AUDIORATE=224
#MUXMODE="-m s -F tcmplex.tmp"
#IMAMODE="-t svcd"

#PASS="single"
PASS="1st 2nd"

#NOTverbose="2> /dev/null"
#NOTverbose="&> /dev/null"

#CDSIZE=735 # 74min CD
CDSIZE=795 # 80min CD
#CDSIZE=895 # 90min CD

CDOPT="--force --reload"
CDDEV="--device 0,0,0"

#---------- above you can edit parameters ----------

function usage() {
  echo
  echo "Usage:  $HOWCALLED <shrunk name> <file or mplayer source> [variable video bitrate kbs [$VBITRATE]]"
  echo
  echo "result: (S,X)VCD and mpeg(1,2) encoded with $HOWCALLED."
  echo
exit 1
}

HOWCALLED=`basename $0`
[ $# -lt 2 ] && usage

case $1 in
  -*)
      usage
  ;;
  *)
      NAME=$1
      shift 1
  ;;
esac

DIR="`pwd`"
FILE=$1
if [ "$1" == "`basename \"$1\"`" ]; then
  FILE="$DIR/$1"
fi
shift 1

if [ "$1"x != "x" ]; then
  VBITRATE=$1
  shift 1
fi

COMMAND_LINE_MENCODER=$*

rm -rf divx2pass.log
#rm -rf frameno.avi

# First Pass, Audio
# If we had encoded audio in an earlier try, we won't do it again
# (then we must provide a vbitrate on command line)
if [ ! -f frameno.avi ]
then
  command="mencoder -ovc frameno -oac lavc -lavcopts acodec=mp2:abitrate=128 -o frameno.avi $FILE | tee /tmp/encode.$$"
  echo "$command $NOTverbose"
  eval "$command $NOTverbose"
  # Set the bitrate from estimation, heuristic: use bitrate for 650MB CD even if we use 700MB
  # here is a place for experiments!
  VBITRATE=`tail -n 10 /tmp/encode.$$ | grep "for 650MB CD" | awk -F ":" '/^/{print $2}' | sed '/\ /s///g'`
  rm -f /tmp/encode.$$
else
  echo "existing frameno.avi found!"
fi

# Crop Detection
mencoder -vf cropdetect,scale=$WID:-3,expand=-1:$HEI:-1:-1:1 -oac copy  -ovc lavc  "$FILE" -frames 50 > /tmp/f
CROP=`cat /tmp/f |grep vf | tail -n 1 | cut -d "=" -f 2 | tr -d ')'`

for word in $PASS ; do
  VIDEO="video.mpg"
  [ "$word" == "single"  ] && pass=""
  [ "$word" == "1st"  ] && pass=":vpass=1"
  [ "$word" == "1st"  ] && VIDEO="/dev/null"
  [ "$word" == "2nd"  ] && pass=":vpass=2"

  if [ "$word" == "1st" ]
  then
    # vqscale=2 in first pass should give a better estimation for the second pass
    # which uses vbitrate
    command="mencoder -sws $SWS -vf ${VFILTER}crop=$CROP,scale=$WID:-3,expand=-1:$HEI:-1:-1:1  \
    -of mpeg -oac copy \
    -ovc lavc -lavcopts vcodec=$VCODEC:$MATRIX:vqscale=2:vrc_minrate=64:vrc_maxrate=2300:vrc_buf_size=320:keyint=25:${LAVCOPTS}$pass \
    $COMMAND_LINE_MENCODER $FILE -o $VIDEO"
  else
    command="mencoder -sws $SWS -vf ${VFILTER}crop=$CROP,scale=$WID:-3,expand=-1:$HEI:-1:-1:1  \
    -of mpeg -oac copy \
    -ovc lavc -lavcopts vcodec=$VCODEC:$MATRIX:vbitrate=$VBITRATE:vrc_minrate=64:\
vrc_maxrate=2300:vrc_buf_size=320:keyint=25:${LAVCOPTS}$pass \
    $COMMAND_LINE_MENCODER $FILE -o $VIDEO"
  fi
  echo "$command $NOTverbose"
  eval "$command $NOTverbose"
done

mv $VIDEO $NAME.mpg

for i in $NAME.mpg; do
  cue="`basename $i .mpg`.cue"
  bin="`basename $i .mpg`.bin"
  rm -f $cue $bin
  eval "vcdimager $IMAMODE -c $cue -b $bin $i"
done

echo -e "\n$HOWCALLED encoding is completed in $SECONDS seconds.\n"

for cue in $NAME.cue; do
  bin="`basename $cue .cue`.bin"
  echo "PLEASE INSERT BLANK CD IN CD-WRITER, after a keypress we start:"
  read -n 1 null
  eval "cdrdao write $CDOPT $CDDEV $cue"
  echo "CD WRITING IS COMPLETED."
done

exit 0
# last line of this script

This is not heavily tested, but should be used as a starting point for further tuning.

Have Fun with KVCD in Linux!

Greetings,

Neturmel

russiansexpat 12-10-2003 06:46 AM

Quote:

crop=$CROP,scale=$WID:-3,expand=-1:$HEI:-1:-1:1
are you sure about expand parameters? you did not center and also render osd.
cropdetect is nice to have, but you looking only into for first 50 frames.
For ppl who wants to automate something in this cript,
try use http://mpgtx.sourceforge.net and tcscan for transcode to get inormation about the source.

neturmel 12-10-2003 09:07 AM

Hi,


in my case, expand just adds enough black bands (below and above the movie) to keep the original aspect ratio of the movie without the need for the player to get its aspect correct by itself (infamous "feature" of the windows media player). But honestly, that was only added by trial and error and by verifying the result on different hard- and software players.

So it is possible that it is utterly useless for anyone else...

Cropdetect on only 50 frames is no problem if you only encode the main movie. If there are trailers or menus etc. , you certainly should use more frames. Otherwise, the bands really shouldn't change in the main movie.

But if you really want to be sure that your crop parameters are correct, just do it for 10min of movie ( would be at most 30*60*10= 18000 frames )

2) By coincidence, I just started to test mpgtx myself (for splitting movies longer than the size of the CD before burning). Works well for mpeg1, but not for mpeg2.

P.S.: Since I make KVCDs out of VDR-Recordings, I have found vdrsync.pl (http://vdrsync.vdr-portal.de) for remultiplexing and joining of cutted VDR material extremely useful (also uses parts of transcode)

Hope that others won't find this just boring...

neturmel

neturmel 12-10-2003 09:17 AM

Another hint:

it really seems that by using 2-pass encoding and vqscale=2 in the first pass,
you really hit your vbitrate value for the second pass pretty perfect, so it
should be possible to use the predicted bitrate for the planned CD size which
was printed in the first (audio encoding) pass, see above.

But have to test a little bit further...

Greetings,

neturmel

russiansexpat 12-10-2003 12:16 PM

"The audio stream must be MPEG-1 layer II, with a bit-rate ranging
from 32 to 384 kbits/sec bit-rate (i.e. the audio stream _is_ allowed
to be VBR!) with up to 2 stereo or 4 mono channels, or 1 extended
MPEG-1/2 multichannel (5+1) surround sound stream." --
http://www.vcdimager.org/pub/vcdimag.../vcdimager.txt

Thus the script now uses toolame for audio encoding,
http://mikecheng.d2.net.au/
also toolame can encode joint stereo and use diffrent acoustic models.
If you choose AUDIORATE in editable section equal "VAR"
the script will downsample frequency to 22050 Hz and encode with variable audio bitrate in 8 - 160 Kbps band.
Audio is still stereo! See results below in this thread.

mplex from http://mjpeg.sourceforge.net/ is used for multiplexing audio and video (tcmplex can't handle variable rate mp2) and it is not bad after all, you don't have to install heavyweight transcode package.

Code:

#!/bin/bash
#
# Copyright (C) 2003-2038 russiansexpat
#
# script:      mpeg(1,2,3,4) conversion to (S,X)VCD with quantisation matrix
#              and auto-splitting into multiple CDs and writing them.
#
# requires:    mencoder mplayer sox toolame(0.2k) mplex vcdimager cdrdao
#
# does not require: microsoft. This script has not been tested on animals.

for exe in mencoder mplayer sox toolame mplex vcdimager cdrdao; do
  if [ -z "`which $exe`" ]; then
      echo "ERROR: $exe must be in your path $PATH"
      exit 1
  fi
done

MATRIX="\
intra_matrix=\
8,9,12,22,26,27,29,34,\
9,10,14,26,27,29,34,37,\
12,14,18,27,29,34,37,38,\
22,26,27,31,36,37,38,40,\
26,27,29,36,39,38,40,48,\
27,29,34,37,38,40,48,58,\
29,34,37,38,40,48,58,69,\
34,37,38,40,48,58,69,79:\
inter_matrix=\
16,18,20,22,24,26,28,30,\
18,20,22,24,26,28,30,32,\
20,22,24,26,28,30,32,34,\
22,24,26,30,32,32,34,36,\
24,26,28,32,34,34,36,38,\
26,28,30,32,34,36,38,40,\
28,30,32,34,36,38,42,42,\
30,32,34,36,38,40,42,44\
"

Q="6" # constant video quality
      # best=2 excellent<=4 good<=7 even=11 for XVCD
      #        excellent<=6 good<=9 even=13 for SVCD

#---------- below you can edit parameters ----------

# audio bitrate
#AUDIORATE=128 # constant
AUDIORATE="VAR" # frequency 22.05kHz in 8-160kbs band

# scaling algorithm
#SWS=0 # fast bilinear
SWS=2 # bicubic (for upscaling)
#SWS=9 # lanczos (quality? slow)

# video filters
VFILTER="pp=de,denoise3d,"

# for frame rate conversions
#FPS=",telecine,lavcdeint -fps 29.97 -ofps 29.97" # to increase fps
#FPS=" -ofps 29.97"  # NTSC
#FPS=" -ofps 25"    # PAL
#FPS=" -ofps 23.976" # NTSC pulldowned
#FPS=",ivtc=1 -ofps 23.976" # to decrease fps

# aspect view of output;
# it should be the same as aspect view of the source mpeg(1,2)
# or equal to width/length if source aspect undefined (example: avi, capture)
# and your player has to be capable to process chosen aspect
#
#ASPECT="1" # 1:1 where have you seen square TV ?!
ASPECT="1.3333" # 4:3 standard TV or monitor
#ASPECT="1.7777" # 16:9 wide screen TV
#ASPECT="1.85" # film academy flat
#ASPECT="2.35" # cinema scope

# for xvcd
#XY="352:240"
#XY="352:288"
#VCODEC=mpeg1video
#MUXMODE="-f 2 -m 1 -V -b 46"
#IMAMODE="-t vcd2"

# for svcd
#XY="480:480"
XY="480:576"
VCODEC=mpeg2video
MUXMODE="-f 5 -m 2 -V -b 230"
IMAMODE="-t svcd"

# see 'man mencoder'
LAVCOPTS=":vlelim=-4:vcelim=7:lumi_mask=0.05:dark_mask=0.01:naq:dia=2:last_pred=2"
#

PASS="single"
#PASS="1st 2nd"

# mencoder verbosity
NOTverbose="2> /dev/null"
#NOTverbose="&> /dev/null"

#CDSIZE=735 # 74min CD
CDSIZE=795 # 80min CD
#CDSIZE=895 # 90min CD

# cdrdao parameters
CDOPT="--force --reload --eject"
CDDEV="--device 0,4,0" # SCSI id

#---------- above you can edit parameters ----------

function usage() {
  echo
  echo "Usage:  $HOWCALLED <shrunk name> <file or mplayer source> [quality [$Q]]"
  echo
  echo "qualilty: best=2 excellent<=4 good<=7 even=11 - XVCD"
  echo "                excellent<=6 good<=9 even=13 - SVCD"
  echo
  echo "result: (S,X)VCD and mpeg(1,2) encoded with $HOWCALLED."
  echo
exit 1
}

# command line parsing
HOWCALLED=`basename $0`
[ $# -lt 2 ] && usage

case $1 in
  -*)
      usage
  ;;
  *)
      NAME=$1
      shift 1
  ;;
esac

DIR="`pwd`"
FILE=$1
if [ "$1" == "`basename \"$1\"`" ]; then
  FILE="$DIR/$1"
fi
shift 1

if [ "$1"x != "x" ]; then
  Q=$1
  shift 1
fi
COMMAND_LINE_MENCODER=$*

# video encoding
rm -f divx2pass.log
rm -f frameno.avi

for word in $PASS ; do
  VIDEO="video.mpg"
  [ "$word" == "single"  ] && pass=""
  [ "$word" == "1st"  ] && pass=":vpass=1"
  [ "$word" == "1st"  ] && VIDEO="/dev/null"
  [ "$word" == "2nd"  ] && pass=":vpass=2"

  command="mencoder -sws $SWS -vf ${VFILTER}scale=$XY${FPS} \
  -forceidx -of mpeg -nosound \
  -ovc lavc -lavcopts aspect=$ASPECT:vcodec=$VCODEC:$MATRIX:mbd=2:vqscale=$Q:vqcomp=1:vrc_minrate=300:vrc_maxrate=2300:vrc_buf_size=320:keyint=25${LAVCOPTS}$pass \
  $COMMAND_LINE_MENCODER $FILE -o $VIDEO"

  echo "$command $NOTverbose"
  eval "$command $NOTverbose"
done

eval "mplayer -noframedrop -vc dummy -vo null -dumpvideo -dumpfile $NAME.mpv $VIDEO &> /dev/null &"

# audio encoding
AUDIO="audio.wav"
rm -f $AUDIO
mkfifo -m 660 $AUDIO
eval "mplayer -noframedrop -vc dummy -vo null -ao pcm -waveheader -aofile $AUDIO $FILE &> /dev/null &"

if [ "$AUDIORATE" == "VAR" ]; then
  command="cat $AUDIO | sox -V -t .wav - -r 22050 -t .wav - resample -q | toolame -s 22.05 -m s -v 1 - $NAME.mpa &"
else
  command="cat $AUDIO | toolame -s 44.1 -m s -b $AUDIORATE - $NAME.mpa &"
fi
echo "$command"
eval "$command"
#eval "lame -h --abr $AUDIORATE --resample 44.1 - $NAME.mpa < $AUDIO &"
#eval "ffmpeg -y -i $AUDIO -ab $AUDIORATE -ar 44100 -ac 2 -f mp2 $NAME.mpa &"

wait

rm -f $VIDEO
rm -f $AUDIO
# end of encoding

rm -f $NAME?.mpg
eval "mplex $MUXMODE -S $CDSIZE -o $NAME%d.mpg $NAME.mpv $NAME.mpa"

for i in $NAME?.mpg; do
  cue="`basename $i .mpg`.cue"
  bin="`basename $i .mpg`.bin"
  rm -f $cue $bin
  eval "vcdimager $IMAMODE -c $cue -b $bin $i"
done

echo -e "\n$HOWCALLED encoding is completed in $SECONDS seconds.\n"

for cue in $NAME?.cue; do
  bin="`basename $cue .cue`.bin"
  echo "PLEASE INSERT BLANK CD IN CD-WRITER, after a keypress we start:"
  read -n 1 null
  eval "cdrdao write $CDOPT $CDDEV $cue"
  echo "CD WRITING IS COMPLETED."
done

exit 0
# last line of this script


japie 12-10-2003 01:54 PM

I've been doing some testing and must say that 2-pass encoding doesn't change much... (in the mencoder a+v commandline), it only broke a/v_sync (as reposted on mailinglist)
vbr mp2 is actualy very interesting, anyone now how to handle it with mencoder?

russiansexpat 12-10-2003 02:08 PM

1) Just bumped into the ugly fact that tcmplex can't multiplex variable rate mp2 properly, so I'm switching to mplex usage.
Unfortunately, mplex rely on mpeg2enc to insert sequence break points.

mplex option:
-S
This option specifies the maximum size of output
files in MBytes (2^10). The default is 2000 Mbytes
(splitting output before 2G limits can hit). When
the limit is reached a new file is started.

Note: This option is _n_o_t suitable for splitting a
long video across multiple VCD's or SVCD's.

It simply splits a single long sequence into in a
way that prevents bits of a video GOP(group of pic*
tures) or audio frame being split between chunks.
frame reasonable. This is fine for formats like
that used for DVDs where all stream parameters
appear every GOP. However, for VCD / SVCD it won't
work as the players expect each file to start a new
MPEG sequence.

For VCD / SVCD a different technique is used. If
mplex encounters a sequence break (sequence end
followed by start) in the input video stream it
starts a new output stream and file at the sequence
start. Thus to split a long video across
VCD's/SVCD's you have to get the MPEG video encoder
to introduce sequence splits at the right points
(see mpeg2enc(1) for details of how to do this).

I just ignore suggested mpeg2enc and use -S option of mplex. It works.

2) Limitations of toolame encoding:
Bitrate Ranges
When making a VBR stream, the bitrate is only allowed to vary within set limits:
48kHz Stereo: 112-384kbps Mono: 56-192kbps
44.1kHz & 32kHz Stereo: 192-384kbps Mono: 96-192kbps
24kHz, 22.05kHz & 16kHz Stereo/Mono: 8-160kbps

It is expected in VCD and SVCD that sampling rate is 44.1 KHz; it is nice to have variable lower bitrates, so the question is: can we stretch VCD/SVCD standard by using 48kHz dvd standard?
Can standalone players handle that?

..Resampling from 44.1KHz to 48kHz is bad quality with standard tools, so I put resampling to 22kHz instead.

This is test on 1.5 hour film:
with stereo:
VBR stats:
8 16 24 32 40 48 56 64 80 96 112 128 144 160
186 0 16 31 138 494 1104 2025 8672 19671 38521 21557 2752 336
Avg slots/frame = 705.675; b/smp = 4.90; bitrate = 108.056 kbps

with joint stereo:
VBR stats:
8 16 24 32 40 48 56 64 80 96 112 128 144 160
186 0 16 40 153 544 1242 2260 9837 24930 42033 13886 376 0
Avg slots/frame = 681.046; b/smp = 4.73; bitrate = 104.285 kbps

The result is very good dispersion (not distortion) of audio bitrate.

russiansexpat 12-10-2003 03:42 PM

Quote:

Originally Posted by japie
I've been doing some testing and must say that 2-pass encoding doesn't change much... (in the mencoder a+v commandline), it only broke a/v_sync (as reposted on mailinglist)

I have the same experince when using two pass as it is.
However, if you do testing, maybe you can try
vrc_eq=
option mencoder, that is to specify rate control depends on the source.

Quote:

Originally Posted by japie
vbr mp2 is actualy very interesting, anyone now how to handle it with mencoder?

as I know, mencoder use libavcodec ffmpeg library for audio encoding; to use variable rate mp2, you have to use native mp2 encoder = toolame.

neturmel 12-11-2003 04:25 AM

Hi,

yes, acknowledged, 2-pass encoding doesn't change much, so one pass can be dumped.

I just did a one pass encoding (first one pass audio) of a 90min movie using the mencoder predicted bitrate for a 650MB CD and hit (or should I say missed) the target with a bin file of 742MB. It is more than 50MB short of the CD capacity, so next time, I'll try the 700MB value and keep you informed.

VBR Audio encoding directly with mencoder (with lavc=ffmpeg) is not possible at the moment :(

Is VBR Audio encoding valid for a DVD ?
To meet DVD recommendations, a sample rate of 48kHz is a must, but what about VBR ?

Most DVD-Players play (S)VCD with 48kHz audio without any problem and
as I sometimes burn those mpegs to DVD, I only encode with 48kHz
audio, so that I don't have to reencode audio.

BTW: My cheapo DVD-Player also plays (S)VCD and DVD with MP3 (also VBR) Audio, but since I like to encode to be compatible with more than my
player, I don't use that.

russiansexpat 12-11-2003 05:39 AM

"Is Variable Bit Rate allowed in MPEG-1 Audio?
For Layer III, the answer is simply 'yes'. The average bit rate is the one given in the header of a Layer III frame, but as the bits may be distributed over several frames, this effectively implies a variable bit rate.
For Layers I and II, according to the standard, it is not mandatory for decoders to support Variable Bit Rate (VBR). However, in practice the majority of the decoders do support Variable Bit Rate, and it is perfectly in line with the standard to specify for a certain application that decoders should support VBR. This is implemented by specifying for each audio frame separately the bit rate at which it is encoded. " -- http://www.chiariglione.org/mpeg/faq...mp1-aud.htm#15

As for DVD Book: http://www.mpeg.org/MPEG/DVD/Book_B/Audio.html
it does not say that audio should be constant rate.

SVCD specifications explicitely state that audio bitrate can be variable.

So, if you see SVCD sticker on a DVD player and it does not play variable rate audio, you can take seller/vendor for legal ride. Of course, before that you have to purchase copy of
ISO/IEC 13818-3 (MPEG-2 Audio)
ISO/IEC 11172-3 (MPEG-1 Audio) Dolby AC-3 standard
from ISO baggers, CHF44 each.
As for DVD, you know, you are only allowed to play your region DVDs and pre-approved by Bill Hates.

http://www.digitalfaq.com/archives/error.gif

neturmel 12-11-2003 09:24 AM

FYI:
Just terminated an encoding using mencoder predicted 700MB bitrate:
a perfect hit with 793MB .bin !

So if you are heading for 1CD-KVCDs perfectly filled, try it this way!

(only true for CBR audio...)

Greetings,

neturmel

russiansexpat 12-11-2003 10:43 AM

Quote:

Most DVD-Players play (S)VCD with 48kHz audio without any problem and
as I sometimes burn those mpegs to DVD, I only encode with 48kHz
audio, so that I don't have to reencode audio.
I am posting the script with audio 48 kHz frequency ("DVD type") in stereo 112-384kbps encoding. see 'man sox' for resample.
Most of audio bitrates will gather around 192 kbps, but depends on audio demand they can go up and down in a band 112-384kbs.

http://www.digitalfaq.com/archives/error.gif

russiansexpat 12-11-2003 10:56 AM

Code:

#!/bin/bash
#
# Copyright (C) 2003-2038 russiansexpat
#
# script:      mpeg(1,2,3,4) conversion to (S,X)VCD with quantisation matrix
#              and auto-splitting into multiple CDs and writing them.
#
# requires:    mencoder mplayer sox toolame(0.2k) mplex vcdimager cdrdao
#
# does not require: microsoft. This script has not been tested on animals.

for exe in mencoder mplayer sox toolame mplex vcdimager cdrdao; do
  if [ -z "`which $exe`" ]; then
      echo "ERROR: $exe must be in your path $PATH"
      exit 1
  fi
done

MATRIX="\
intra_matrix=\
8,9,12,22,26,27,29,34,\
9,10,14,26,27,29,34,37,\
12,14,18,27,29,34,37,38,\
22,26,27,31,36,37,38,40,\
26,27,29,36,39,38,40,48,\
27,29,34,37,38,40,48,58,\
29,34,37,38,40,48,58,69,\
34,37,38,40,48,58,69,79:\
inter_matrix=\
16,18,20,22,24,26,28,30,\
18,20,22,24,26,28,30,32,\
20,22,24,26,28,30,32,34,\
22,24,26,30,32,32,34,36,\
24,26,28,32,34,34,36,38,\
26,28,30,32,34,36,38,40,\
28,30,32,34,36,38,42,42,\
30,32,34,36,38,40,42,44\
"

Q="6" # constant video quality
      # best=2 excellent<=4 good<=7 even=11 for XVCD
      #        excellent<=6 good<=9 even=13 for SVCD

#---------- below you can edit parameters ----------

# audio bitrate
#AUDIORATE=128 # constant
AUDIORATE="VAR" # frequency 48kHz in 112-384kbps band

# scaling algorithm
#SWS=0 # fast bilinear
SWS=2 # bicubic (for upscaling)
#SWS=9 # lanczos (quality? slow)

# video filters
VFILTER="pp=de,denoise3d,"

# for frame rate conversions
#FPS=",telecine,lavcdeint -fps 29.97 -ofps 29.97" # to increase fps
#FPS=" -ofps 29.97"  # NTSC
#FPS=" -ofps 25"    # PAL
#FPS=" -ofps 23.976" # NTSC pulldowned
#FPS=",ivtc=1 -ofps 23.976" # to decrease fps

# aspect view of output;
# it should be the same as aspect view of the source mpeg(1,2)
# or equal to width/length if source aspect undefined (example: avi, capture)
# and your player has to be capable to process chosen aspect
#
#ASPECT="1" # 1:1 where have you seen square TV ?!
ASPECT="1.3333" # 4:3 standard TV or monitor
#ASPECT="1.7777" # 16:9 wide screen TV
#ASPECT="1.85" # film academy flat
#ASPECT="2.35" # cinema scope

# for xvcd
#XY="352:240"
#XY="352:288"
#VCODEC=mpeg1video
#MUXMODE="-f 2 -m 1 -V -b 46"
#IMAMODE="-t vcd2"

# for svcd
#XY="480:480"
XY="480:576"
VCODEC=mpeg2video
MUXMODE="-f 5 -m 2 -V -b 230"
IMAMODE="-t svcd"

# group of pictures length - the larger is better compression, but
# it relies on a player decoder and so resulting playback quality
GOP=50

# see 'man mencoder'
LAVCOPTS=":vlelim=-4:vcelim=7:lumi_mask=0.05:dark_mask=0.01:naq:dia=2:last_pred=2"
#

PASS="single"
#PASS="1st 2nd"

# mencoder verbosity
NOTverbose="2> /dev/null"
#NOTverbose="&> /dev/null"

#CDSIZE=735 # 74min CD
CDSIZE=795 # 80min CD
#CDSIZE=895 # 90min CD

# cdrdao parameters
CDOPT="--force --reload --eject"
CDDEV="--device 0,4,0" # SCSI id

#---------- above you can edit parameters ----------

function usage() {
  echo
  echo "Usage:  $HOWCALLED <shrunk name> <file or mplayer source> [quality [$Q]]"
  echo
  echo "qualilty: best=2 excellent<=4 good<=7 even=11 - XVCD"
  echo "                excellent<=6 good<=9 even=13 - SVCD"
  echo
  echo "result: (S,X)VCD and mpeg(1,2) encoded with $HOWCALLED."
  echo
exit 1
}

# command line parsing
HOWCALLED=`basename $0`
[ $# -lt 2 ] && usage

case $1 in
  -*)
      usage
  ;;
  *)
      NAME=$1
      shift 1
  ;;
esac

DIR="`pwd`"
FILE=$1
if [ "$1" == "`basename \"$1\"`" ]; then
  FILE="$DIR/$1"
fi
shift 1

if [ "$1"x != "x" ]; then
  Q=$1
  shift 1
fi
COMMAND_LINE_MENCODER=$*

# video encoding
rm -f divx2pass.log
rm -f frameno.avi

for word in $PASS ; do
  VIDEO="video.mpg"
  [ "$word" == "single"  ] && pass=""
  [ "$word" == "1st"  ] && pass=":vpass=1"
  [ "$word" == "1st"  ] && VIDEO="/dev/null"
  [ "$word" == "2nd"  ] && pass=":vpass=2"

  command="mencoder -sws $SWS -vf ${VFILTER}scale=$XY${FPS} \
  -forceidx -of mpeg -nosound \
  -ovc lavc -lavcopts aspect=$ASPECT:vcodec=$VCODEC:$MATRIX:mbd=2:vqscale=$Q:vqcomp=1:vrc_minrate=300:vrc_maxrate=2300:vrc_buf_size=320:keyint=$GOP${LAVCOPTS}$pass \
  $COMMAND_LINE_MENCODER $FILE -o $VIDEO"

  echo "$command $NOTverbose"
  eval "$command $NOTverbose"
done

eval "mplayer -noframedrop -vc dummy -vo null -dumpvideo -dumpfile $NAME.mpv $VIDEO &> /dev/null &"

# audio encoding
AUDIO="audio.wav"
rm -f $AUDIO
mkfifo -m 660 $AUDIO
eval "mplayer -noframedrop -vc dummy -vo null -ao pcm -waveheader -aofile $AUDIO $FILE &> /dev/null &"

if [ "$AUDIORATE" == "VAR" ]; then
  command="cat $AUDIO | sox -V -t .wav - -r 48000 -t .wav - resample -q vol 1.5 | toolame -s 48 -m s -v -1 - $NAME.mpa &"
else
  command="cat $AUDIO | toolame -s 44.1 -m s -b $AUDIORATE - $NAME.mpa &"
fi
echo "$command"
eval "$command"
#eval "lame -h --abr $AUDIORATE --resample 44.1 - $NAME.mpa < $AUDIO &"
#eval "ffmpeg -y -i $AUDIO -ab $AUDIORATE -ar 44100 -ac 2 -f mp2 $NAME.mpa &"

wait

rm -f $VIDEO
rm -f $AUDIO
# end of encoding

rm -f $NAME?.mpg
eval "mplex $MUXMODE -S $CDSIZE -o $NAME%d.mpg $NAME.mpv $NAME.mpa"

for i in $NAME?.mpg; do
  cue="`basename $i .mpg`.cue"
  bin="`basename $i .mpg`.bin"
  rm -f $cue $bin
  eval "vcdimager $IMAMODE -c $cue -b $bin $i"
done

echo -e "\n$HOWCALLED encoding is completed in $SECONDS seconds.\n"

for cue in $NAME?.cue; do
  bin="`basename $cue .cue`.bin"
  echo "PLEASE INSERT BLANK CD IN CD-WRITER, after a keypress we start:"
  read -n 1 null
  eval "cdrdao write $CDOPT $CDDEV $cue"
  echo "CD WRITING IS COMPLETED."
done

exit 0
# last line of this script


japie 12-11-2003 12:27 PM

Quote:

Originally Posted by russiansexpat
However, if you do testing, maybe you can try
vrc_eq=
option mencoder, that is to specify rate control depends on the source.

I know, but it doesn't change much, maybe 1% difference between factor 2 and 13 :O
Actualy I can't find ANY setting wich changes much to the libavcodec quality, even changing max and min bitrates doesn't change that much (unless using very weird values)

russiansexpat 12-14-2003 11:40 AM

This version of the script uses mencoder 1.0pre3, it is availabe now in source and rpm. Mencoder now is capable to encode mp2 audio.
The script contains part with encoding to variable mp2 with resampling to frequency 48kHz in 112-384kbs band; usually, audio encoded around 160kbs with good audio rate dispersion.
Other important changes: vrc_eq=tex:vrc_buf_size=$VBuffer (default parameters maybe not good for xvcd, svcd encoding).
mbd=1 (previously mbd=2 produced streams with bitrate spikes, not suitable for multiplexing).
You can experiment with vrc_eq, mbd, mbcmp parameters - maybe you can find better.
So far, I have achieved 1CD fit for 480*576 mpeg2 of 1h23m movie video quality 4, gop 15, audio 192.

Code:

#!/bin/bash
#
# Copyright (C) 2003-2038 russiansexpat
#
# script:      mpeg(1,2,3,4) conversion to (S,X)VCD with quantisation matrix
#              and auto-splitting into multiple CDs and writing them.
#
# requires:    mencoder(1.0pre3) mplayer mplex vcdimager cdrdao
# optional:    normalize sox toolame(0.2k)
#
# does not require: microsoft. This script has not been tested on animals.

for exe in mencoder mplayer mplex vcdimager cdrdao; do
  if [ -z "`which $exe`" ]; then
      echo "ERROR: $exe must be in your path $PATH"
      exit 1
  fi
done

MATRIX="\
intra_matrix=\
8,9,12,22,26,27,29,34,\
9,10,14,26,27,29,34,37,\
12,14,18,27,29,34,37,38,\
22,26,27,31,36,37,38,40,\
26,27,29,36,39,38,40,48,\
27,29,34,37,38,40,48,58,\
29,34,37,38,40,48,58,69,\
34,37,38,40,48,58,69,79:\
inter_matrix=\
16,18,20,22,24,26,28,30,\
18,20,22,24,26,28,30,32,\
20,22,24,26,28,30,32,34,\
22,24,26,30,32,32,34,36,\
24,26,28,32,34,34,36,38,\
26,28,30,32,34,36,38,40,\
28,30,32,34,36,38,42,42,\
30,32,34,36,38,40,42,44\
"

Q="6" # constant video quality
      # best=2 excellent<=4 good<=7 even=11 for XVCD
      #        excellent<=6 good<=9 even=13 for SVCD

#---------- below you can edit parameters ----------

# audio bitrate
#AUDIORATE=128 # constant
AUDIORATE=384 # variable with frequency 48kHz in 112-384kbs band

# scaling algorithm
#SWS=0 # fast bilinear
SWS=2 # bicubic (for upscaling)
#SWS=9 # lanczos (quality? slow)

# video filters
VFILTER="pp=de,denoise3d,"

# for frame rate conversions
#FPS=",telecine,lavcdeint -fps 29.97 -ofps 29.97" # to increase fps
#FPS=" -ofps 29.97"  # NTSC
#FPS=" -ofps 25"    # PAL
#FPS=" -ofps 23.976" # NTSC pulldowned
#FPS=",ivtc=1 -ofps 23.976" # to decrease fps

# aspect view of output;
# it should be the same as aspect view of the source mpeg(1,2)
# or equal to width/length if source aspect undefined (example: avi, capture)
# and your player has to be capable to process chosen aspect
#
#ASPECT="1" # 1:1 where have you seen square TV ?!
ASPECT="1.3333" # 4:3 standard TV or monitor
#ASPECT="1.7777" # 16:9 wide screen TV
#ASPECT="1.85" # film academy flat
#ASPECT="2.35" # cinema scope

# for xvcd
#XY="352:240"
#XY="352:288"
#VCODEC=mpeg1video
#VBuffer=376    # Kbits = 46*1024*8/1000
#MUXMODE="-f 2 -m 1 -V -b 46"
#IMAMODE="-t vcd2"

# for svcd
#XY="480:480"
XY="480:576"
VCODEC=mpeg2video
VBuffer=1884  # Kbits = 230*1024*8/1000
MUXMODE="-f 5 -m 2 -V -b 230"
IMAMODE="-t svcd"

# group of pictures length - the longer is better compression, but
# it relies on a player decoder and so resulting playback quality
GOP=15 # dvd pal gop <=15, ntsc <=18 but in practice gop can be longer

# see 'man mencoder'
ULAVCOPTS=":vlelim=-4:vcelim=7:lumi_mask=0.05:dark_mask=0.01:naq:dia=2:last_pred=2"
#

PASS="single"
#PASS="1st 2nd"

# mencoder verbosity
NOTverbose="2> /dev/null"
#NOTverbose="&> /dev/null"

#CDSIZE=735 # 74min CD
CDSIZE=795 # 80min CD
#CDSIZE=895 # 90min CD

# cdrdao parameters
CDOPT="--force --reload --eject"
CDDEV="--device 0,4,0" # SCSI id

#---------- above you can edit parameters ----------

function usage() {
  echo
  echo "Usage:  $HOWCALLED <shrunk name> <file or mplayer source> [quality [$Q]]"
  echo
  echo "qualilty: best=2 excellent<=4 good<=7 even=11 - XVCD"
  echo "                excellent<=6 good<=9 even=13 - SVCD"
  echo
  echo "result: (S,X)VCD and mpeg(1,2) encoded with $HOWCALLED."
  echo
exit 1
}

# command line parsing
HOWCALLED=`basename $0`
[ $# -lt 2 ] && usage

case $1 in
  -*)
      usage
  ;;
  *)
      NAME=$1
      shift 1
  ;;
esac

DIR="`pwd`"
FILE=$1
if [ "$1" == "`basename \"$1\"`" ]; then
  FILE="$DIR/$1"
fi
shift 1

if [ "$1"x != "x" ]; then
  Q=$1
  shift 1
fi
COMMAND_LINE_MENCODER=$*

# encoding
rm -f divx2pass.log
rm -f frameno.avi

for word in $PASS ; do
  MOVIE="movie.mpg"
  [ "$word" == "single" ] && pass=""
  [ "$word" == "1st"  ] && pass=":vpass=1"
  [ "$word" == "1st"  ] && MOVIE="/dev/null"
  [ "$word" == "2nd"  ] && pass=":vpass=2"

  command="mencoder -noskip -forceidx -of mpeg \
  -sws $SWS -vf ${VFILTER}scale=$XY${FPS} \
  -ovc lavc -oac lavc -lavcopts acodec=mp2:abitrate=$AUDIORATE:aspect=$ASPECT:vcodec=$VCODEC:$MATRIX:mbd=1:vqscale=$Q:vrc_minrate=300:vrc_maxrate=2300:vrc_eq=tex:vrc_buf_size=$VBuffer:keyint=$GOP${ULAVCOPTS}$pass \
  $COMMAND_LINE_MENCODER $FILE -o $MOVIE"

  echo "$command $NOTverbose"
  eval "$command $NOTverbose"
done

echo -e "\nyou will wait :p\n"
eval "mplayer -noframedrop -vc dummy -vo null -dumpvideo -dumpfile $NAME.mpv $MOVIE &> /dev/null &"

if [ $AUDIORATE != 384 ]; then
  eval "mplayer -noframedrop -ac dummy -ao null -dumpaudio -dumpfile $NAME.mpa $MOVIE &> /dev/null &"
else
  # re-encoding into variable audio rate
  AUDIO="audio.wav"
  #rm -f $AUDIO
  #mkfifo -m 660 $AUDIO
  eval "mplayer -noframedrop -vc dummy -vo null -ao pcm -waveheader -aofile $AUDIO $MOVIE &> /dev/null"
  eval "normalize -v --fractions $AUDIO" # normalize can't work from pipe
  command="cat $AUDIO | sox -V -t .wav - -r 48000 -t .wav - resample -q | toolame -s 48 -m s -v -1 - $NAME.mpa &"
  echo "$command"
  eval "$command"
fi

wait

rm -f $MOVIE
rm -f $AUDIO
# end of encoding

rm -f $NAME?.mpg
eval "mplex $MUXMODE -S $CDSIZE -o $NAME%d.mpg $NAME.mpv $NAME.mpa"

for i in $NAME?.mpg; do
  cue="`basename $i .mpg`.cue"
  bin="`basename $i .mpg`.bin"
  rm -f $cue $bin
  eval "vcdimager $IMAMODE -c $cue -b $bin $i"
done

echo -e "\n$HOWCALLED encoding is completed in $SECONDS seconds.\n"

for cue in $NAME?.cue; do
  bin="`basename $cue .cue`.bin"
  echo "PLEASE INSERT BLANK CD IN CD-WRITER, after a keypress we start:"
  read -n 1 null
  eval "cdrdao write $CDOPT $CDDEV $cue"
  echo "CD WRITING IS COMPLETED."
done

exit 0
# last line of this script


russiansexpat 12-17-2003 12:54 PM

:bugeyes:
Changes in -lavcopts string and minimum video quality.
Depends on video source, the script sometimes failed to produce valid stream,
becase of video bitrate control - bitrate going over the top and therefore video/audio failed to multiplex.

Code:

#!/bin/bash
#
# Copyright (C) 2003-2038 russiansexpat
#
# script:      mpeg(1,2,3,4) conversion to (S,X)VCD with quantisation matrix
#              and auto-splitting into multiple CDs and writing them.
#
# requires:    mencoder(1.0pre3) mplayer mplex vcdimager cdrdao
# optional:    normalize sox toolame(0.2k)
#
# does not require: microsoft. This script has not been tested on animals.

for exe in mencoder mplayer mplex vcdimager cdrdao; do
  if [ -z "`which $exe`" ]; then
      echo "ERROR: $exe must be in your path $PATH"
      exit 1
  fi
done

MATRIX="\
intra_matrix=\
8,9,12,22,26,27,29,34,\
9,10,14,26,27,29,34,37,\
12,14,18,27,29,34,37,38,\
22,26,27,31,36,37,38,40,\
26,27,29,36,39,38,40,48,\
27,29,34,37,38,40,48,58,\
29,34,37,38,40,48,58,69,\
34,37,38,40,48,58,69,79:\
inter_matrix=\
16,18,20,22,24,26,28,30,\
18,20,22,24,26,28,30,32,\
20,22,24,26,28,30,32,34,\
22,24,26,30,32,32,34,36,\
24,26,28,32,34,34,36,38,\
26,28,30,32,34,36,38,40,\
28,30,32,34,36,38,42,42,\
30,32,34,36,38,40,42,44\
"

Q="6" # constant video quality
      # best=3 excellent<=4 good<=7 even=11 for mpeg1  VCD resolution
      #        excellent<=6 good<=9 even=13 for mpeg2 SVCD resolution

#---------- below you can edit parameters ----------

# audio bitrate
#AUDIORATE=128 # constant
AUDIORATE=384 # variable with frequency 48kHz in 112-384kbs band

# scaling algorithm
#SWS=0 # fast bilinear
SWS=2 # bicubic (for upscaling)
#SWS=9 # lanczos (quality? slow)

# video filters
VFILTER="pp=de,denoise3d,"

# for frame rate conversions
#FPS=",telecine,lavcdeint -fps 29.97 -ofps 29.97" # to increase fps
#FPS=" -ofps 29.97"  # NTSC
#FPS=" -ofps 25"    # PAL
#FPS=" -ofps 23.976" # NTSC pulldowned
#FPS=",ivtc=1 -ofps 23.976" # to decrease fps

# aspect view of output;
# it should be the same as aspect view of the source mpeg(1,2)
# or equal to width/length if source aspect undefined (example: avi, capture)
# and your player has to be capable to process chosen aspect
#
#ASPECT="1" # 1:1 where have you seen square TV ?!
ASPECT="1.3333" # 4:3 standard TV or monitor
#ASPECT="1.7777" # 16:9 wide screen TV
#ASPECT="1.85" # film academy flat
#ASPECT="2.35" # cinema scope

# for xvcd
#XY="352:240"
#XY="352:288"
#VCODEC=mpeg1video
#VBuffer=376    # Kbits = 46*1024*8/1000
#MUXMODE="-f 2 -m 1 -V -b 46"
#IMAMODE="-t vcd2"

# for svcd
#XY="480:480"
XY="480:576"
VCODEC=mpeg2video
VBuffer=1884  # Kbits = 230*1024*8/1000
MUXMODE="-f 5 -m 2 -V -b 230"
IMAMODE="-t svcd"

# group of pictures length - the longer is better compression, but
# it relies on a player decoder and so resulting playback quality
GOP=15 # dvd pal gop <=15, ntsc <=18 but in practice gop can be longer

# see 'man mencoder'
ULAVCOPTS1=":naq:mbd=1:vqblur=1:vrc_eq=tex:vmax_b_frames=2:vb_strategy=1"
ULAVCOPTS2=":preme=1:predia=2:dia=2:vlelim=-4:vcelim=7:lumi_mask=0.05:dark_mask=0.01"
#

PASS="single"
#PASS="1st 2nd"

# mencoder verbosity
NOTverbose="2> /dev/null"
#NOTverbose="&> /dev/null"

#CDSIZE=735 # 74min CD
CDSIZE=795 # 80min CD
#CDSIZE=895 # 90min CD

# cdrdao parameters
CDOPT="--force --reload --eject"
CDDEV="--device 0,4,0" # SCSI id

#---------- above you can edit parameters ----------

function usage() {
  echo
  echo "Usage:  $HOWCALLED <shrunk name> <file or mplayer source> [quality [$Q]]"
  echo
  echo "qualilty: best=3 excellent<=4 good<=7 even=11 - XVCD"
  echo "                excellent<=6 good<=9 even=13 - SVCD"
  echo
  echo "result: (S,X)VCD and mpeg(1,2) encoded with $HOWCALLED."
  echo
exit 1
}

# command line parsing
HOWCALLED=`basename $0`
[ $# -lt 2 ] && usage

case $1 in
  -*)
      usage
  ;;
  *)
      NAME=$1
      shift 1
  ;;
esac

DIR="`pwd`"
FILE=$1
if [ "$1" == "`basename \"$1\"`" ]; then
  FILE="$DIR/$1"
fi
shift 1

if [ "$1"x != "x" ]; then
  Q=$1
  shift 1
fi
COMMAND_LINE_MENCODER=$*

# encoding
rm -f divx2pass.log
rm -f frameno.avi

for word in $PASS ; do
  MOVIE="movie.mpg"
  [ "$word" == "single" ] && pass=""
  [ "$word" == "1st"  ] && pass=":vpass=1"
  [ "$word" == "1st"  ] && MOVIE="/dev/null"
  [ "$word" == "2nd"  ] && pass=":vpass=2"

  command="mencoder \
  -forceidx -lavdopts ec=1:er=1 -noslices \
  -sws $SWS -vf ${VFILTER}scale=$XY${FPS} \
  -of mpeg -oac lavc -ovc lavc \
  -lavcopts acodec=mp2:abitrate=$AUDIORATE:aspect=$ASPECT:vcodec=$VCODEC:$MATRIX:vqscale=$Q:vqmin=3:mbqmin=3:vrc_minrate=300:vrc_maxrate=2300:vrc_buf_size=$VBuffer:keyint=$GOP${ULAVCOPTS1}${ULAVCOPTS2}$pass \
  $COMMAND_LINE_MENCODER $FILE -o $MOVIE"

  echo "$command $NOTverbose"
  eval "$command $NOTverbose"
done

echo -e "\nyou will wait :p\n"
eval "mplayer -noframedrop -vc dummy -vo null -dumpvideo -dumpfile $NAME.mpv $MOVIE &> /dev/null &"

if [ $AUDIORATE != 384 ]; then
  eval "mplayer -noframedrop -ac dummy -ao null -dumpaudio -dumpfile $NAME.mpa $MOVIE &> /dev/null &"
else
  # re-encoding into variable audio rate
  AUDIO="audio.wav"
  #rm -f $AUDIO
  #mkfifo -m 660 $AUDIO
  eval "mplayer -noframedrop -vc dummy -vo null -ao pcm -waveheader -aofile $AUDIO $MOVIE &> /dev/null"
  eval "normalize -v --fractions $AUDIO" # normalize can't work from pipe
  command="cat $AUDIO | sox -V -t .wav - -r 48000 -t .wav - resample -q | toolame -s 48 -m s -v -1 - $NAME.mpa &"
  echo "$command"
  eval "$command"
fi

wait

rm -f $MOVIE
rm -f $AUDIO
# end of encoding

rm -f $NAME?.mpg
eval "mplex $MUXMODE -S $CDSIZE -o $NAME%d.mpg $NAME.mpv $NAME.mpa"

for i in $NAME?.mpg; do
  cue="`basename $i .mpg`.cue"
  bin="`basename $i .mpg`.bin"
  rm -f $cue $bin
  eval "vcdimager $IMAMODE -c $cue -b $bin $i"
done

echo -e "\n$HOWCALLED encoding is completed in $SECONDS seconds.\n"

for cue in $NAME?.cue; do
  bin="`basename $cue .cue`.bin"
  echo "PLEASE INSERT BLANK CD IN CD-WRITER and press any key to begin writing:"
  read -n 1 null
  eval "cdrdao write $CDOPT $CDDEV $cue"
  echo "CD WRITING IS COMPLETED."
done

exit 0
# last line of this script


japie 12-17-2003 01:25 PM

Quote:

Originally Posted by russiansexpat
bitrate going over the top and therefore video/audio failed to multiplex.

Why do you de/re_multiplex the file? (the mpeg's produced by libavcodec mpeg1 + mp2 are perfectly muxed)

russiansexpat 12-18-2003 04:04 AM

I use mplex (or tcmplex) to split the result into multiple CDs
and for separate audio encoding with variable audiorate.
By the way, do you know any video bitrate viewer in unix?

russiansexpat 12-20-2003 08:10 PM

Apparently root of previous reported problems was broken audio-video sync in a source avi file.
In my case, the source has 24.999 frame rate instead of standard 25 fps PAL, it is enough to cause the problem of audio/video sync encoding.
It appears that use of the same algorithm for decoding and encoding can fix frame rate deviation from ugly encoded source (see idct=0 in -lavdopts and -lavcopts).
I still use mplex, because tcmplex produced muted audio with variable audio rate, however tcmplex is more tolerant to input video/audio files.
Also, I have restored vqmin=2, added :vmax_b_frames=1:vb_strategy=1 encoding with B frames
and :tcplx_mask=0.05:scplx_mask=0.05 quantisation adjustment to complexity (have to be used with :naq).
Video buffer is default size, but you can increase it.
Code:

#!/bin/bash
#
# Copyright (C) 2003-2038 russiansexpat
#
# script:      mpeg(1,2,3,4) conversion to (S,X)VCD with quantisation matrix
#              and auto-splitting into multiple CDs and writing them.
#
# requires:    mencoder(1.0pre3) mplayer mplex vcdimager cdrdao
# optional:    normalize sox toolame(0.2k)
#
# does not require: microsoft. This script has not been tested on animals.

for exe in mencoder mplayer mplex vcdimager cdrdao; do
  if [ -z "`which $exe`" ]; then
      echo "ERROR: $exe must be in your path $PATH"
      exit 1
  fi
done

MATRIX="\
intra_matrix=\
8,9,12,22,26,27,29,34,\
9,10,14,26,27,29,34,37,\
12,14,18,27,29,34,37,38,\
22,26,27,31,36,37,38,40,\
26,27,29,36,39,38,40,48,\
27,29,34,37,38,40,48,58,\
29,34,37,38,40,48,58,69,\
34,37,38,40,48,58,69,79:\
inter_matrix=\
16,18,20,22,24,26,28,30,\
18,20,22,24,26,28,30,32,\
20,22,24,26,28,30,32,34,\
22,24,26,30,32,32,34,36,\
24,26,28,32,34,34,36,38,\
26,28,30,32,34,36,38,40,\
28,30,32,34,36,38,42,42,\
30,32,34,36,38,40,42,44\
"

Q="6" # constant video quality
      # best=2 excellent<=4 good<=7 even=11 for mpeg1  VCD resolution
      #        excellent<=6 good<=9 even=13 for mpeg2 SVCD resolution

#---------- below you can edit parameters ----------

# audio bitrate
#AUDIORATE=128 # constant
AUDIORATE=384 # variable with frequency 48kHz in 112-384kbs band

# scaling algorithm
#SWS=0 # fast bilinear
SWS=2 # bicubic, for upscaling
#SWS=9 # lanczos, quality

# video filters
VFILTER="pp=de,denoise3d,"

# for frame rate conversions
#FPS=",telecine,lavcdeint -fps 29.97 -ofps 29.97" # example to increase fps
#FPS=" -fps 29.97 -ofps 29.97"                    # NTSC
FPS=" -fps 25 -ofps 25"                          # PAL
#FPS=" -fps 23.976 -ofps 23.976"                  # NTSC pulldowned
#FPS=",filmdint=fast=3 -fps 29.97 -ofps 23.976"  # example to decrease fps

# aspect view of output;
# it should be the same as aspect view of the source mpeg(1,2)
# or equal to width/length if source aspect undefined (example: avi, capture)
# and your player has to be capable to process chosen aspect
#
#ASPECT="1" # 1:1 where have you seen square TV ?!
ASPECT="1.3333" # 4:3 standard TV or monitor
#ASPECT="1.7777" # 16:9 wide screen TV
#ASPECT="1.85" # film academy flat
#ASPECT="2.35" # cinema scope

# for xvcd
#XY="352:240"
#XY="352:288"
#VCODEC=mpeg1video
#VBuffer=327    # Kbits = 40*1024*8/1000
#MUXMODE="-f 2 -m 1 -V -b 40"
#IMAMODE="-t vcd2"

# for svcd
#XY="480:480"
XY="480:576"
VCODEC=mpeg2video
VBuffer=917    # Kbits = 112*1024*8/1000
MUXMODE="-f 5 -m 2 -V -b 112"
IMAMODE="-t svcd"

# macroblock decision algorithm
#MBD=0 # compare blocks, fast
#MBD=1 # fewest bits
MBD=2 # rate distortion

# group of pictures length - the longer is better compression, but
# it relies on a player decoder and so resulting playback quality
GOP=25 # dvd pal gop <=15, ntsc <=18 but in practice gop can be longer

ULAVCOPTS1=":vlelim=-4:vcelim=7:vqblur=0.5:vrc_eq=tex:vmax_b_frames=2:vb_strategy=1"
ULAVCOPTS2=":naq:lumi_mask=0.05:dark_mask=0.01:tcplx_mask=0.05:scplx_mask=0.05:preme=1:predia=2:dia=2"

PASS="single"
#PASS="1st 2nd"

# mencoder verbosity
NOTverbose="2> /dev/null"
#NOTverbose="&> /dev/null"

#CDSIZE=735 # 74min CD
CDSIZE=795 # 80min CD
#CDSIZE=895 # 90min CD

# cdrdao parameters
CDOPT="--overburn --reload --eject"
CDDEV="--device 0,1,0" # SCSI id

#---------- above you can edit parameters ----------

function usage() {
  echo
  echo "Usage:  $HOWCALLED <shrunk name> <file or mplayer source> [quality [$Q]]"
  echo
  echo "qualilty: best=2 excellent<=4 good<=7 even=11 - XVCD"
  echo "                excellent<=6 good<=9 even=13 - SVCD"
  echo
  echo "result: (S,X)VCD and mpeg(1,2) encoded with $HOWCALLED."
  echo
exit 1
}

# command line parsing
HOWCALLED=`basename $0`
[ $# -lt 2 ] && usage

case $1 in
  -*)
      usage
  ;;
  *)
      NAME=$1
      shift 1
  ;;
esac

DIR="`pwd`"
FILE=$1
if [ "$1" == "`basename \"$1\"`" ]; then
  FILE="$DIR/$1"
fi
shift 1

if [ "$1"x != "x" ]; then
  Q=$1
  shift 1
fi
COMMAND_LINE_MENCODER=$*

# encoding
rm -f divx2pass.log
rm -f frameno.avi

for word in $PASS ; do
  MOVIE=$NAME.mpg
  [ "$word" == "single" ] && pass=""
  [ "$word" == "1st"  ] && pass=":vpass=1"
  [ "$word" == "1st"  ] && MOVIE="/dev/null"
  [ "$word" == "2nd"  ] && pass=":vpass=2"

  command="mencoder \
  -forceidx -lavdopts idct=0 \
  -sws $SWS -vf ${VFILTER}scale=$XY${FPS} \
  -of mpeg -oac lavc -ovc lavc \
  -lavcopts acodec=mp2:abitrate=$AUDIORATE:aspect=$ASPECT:vcodec=$VCODEC:$MATRIX:idct=0:mbd=$MBD:vqscale=$Q:vrc_minrate=300:vrc_maxrate=2300:vrc_buf_size=$VBuffer:keyint=$GOP${ULAVCOPTS1}${ULAVCOPTS2}$pass \
  $COMMAND_LINE_MENCODER $FILE -o $MOVIE"

  echo "$command $NOTverbose"
  eval "$command $NOTverbose"
done

echo -e "\nyou will wait :p\n"
eval "mplayer -noframedrop -vc dummy -vo null -dumpvideo -dumpfile $NAME.mpv $MOVIE &> /dev/null &"

if [ $AUDIORATE != 384 ]; then
  eval "mplayer -noframedrop -ac dummy -ao null -dumpaudio -dumpfile $NAME.mpa $MOVIE &> /dev/null &"
else
  # re-encoding into variable audio rate
  AUDIO=$NAME.wav
  ###rm -f $AUDIO
  ###mkfifo -m 660 $AUDIO
  eval "mplayer -noframedrop -vc dummy -vo null -ao pcm -waveheader -aofile $AUDIO $MOVIE &> /dev/null"
  eval "normalize -v --fractions $AUDIO" # normalize can't work from pipe
  command="cat $AUDIO | sox -V -t .wav - -r 48000 -t .wav - resample -q | toolame -s 48 -m s -v -5 - $NAME.mpa &"
  echo "$command"
  eval "$command"
fi

wait

#rm -f $MOVIE
#rm -f $AUDIO
# end of encoding

# multiplexing
rm -f $NAME?.mpg
eval "mplex $MUXMODE -S $CDSIZE -o $NAME%d.mpg $NAME.mpv $NAME.mpa"

# imaging
for i in $NAME?.mpg; do
  cue="`basename $i .mpg`.cue"
  bin="`basename $i .mpg`.bin"
  rm -f $cue $bin
  eval "vcdimager $IMAMODE -c $cue -b $bin $i"
done

#rm -f $NAME?.mpv $NAME?.mpa $NAME?.mpg
echo -e "\n$HOWCALLED encoding is completed in $SECONDS seconds.\n"

# CD writing
for cue in $NAME?.cue; do
  bin="`basename $cue .cue`.bin"
  echo "PLEASE INSERT BLANK CD IN CD-WRITER and press any key to begin writing:"
  read -n 1 null
  eval "cdrdao write $CDOPT $CDDEV $cue"
  echo "CD WRITING IS COMPLETED."
done

exit 0
# last line of this script


russiansexpat 12-24-2003 01:06 PM

Added expand to scaling, changed order in video processing chain, because frame rate conversion and video filters like denoise should be done before frame resolution scaling.
Video buffer size for encoding and multiplexing is 46Kbytes for XVCD and 112 Kbytes for SVCD
(46/112 is approximately 1152/2778 video+audio bitrates for XVCD/SVCD).
If you have buffer underruns warnings during multiplexing, you can try to increase video buffer size.
Usually you can encode 1h30min movie as SVCD mpeg2 480x576 resolution
with variable audio rate around 160kbps and video quality 5 or even 4 to fit single 80min CD.
Code:

#!/bin/bash
#
# Copyright (C) 2003-2038 russiansexpat
#
# script:      mpeg(1,2,3,4) conversion to (S,X)VCD with quantisation matrix
#              and auto-splitting into multiple CDs and writing them.
#
# requires:    mencoder(1.0pre3) mplayer mplex vcdimager cdrdao
# optional:    normalize sox toolame(0.2k)
#
# does not require: microsoft. This script has not been tested on animals.

for exe in mencoder mplayer mplex vcdimager cdrdao; do
  if [ -z "`which $exe`" ]; then
      echo "ERROR: $exe must be in your path $PATH"
      exit 1
  fi
done

MATRIX="\
intra_matrix=\
8,9,12,22,26,27,29,34,\
9,10,14,26,27,29,34,37,\
12,14,18,27,29,34,37,38,\
22,26,27,31,36,37,38,40,\
26,27,29,36,39,38,40,48,\
27,29,34,37,38,40,48,58,\
29,34,37,38,40,48,58,69,\
34,37,38,40,48,58,69,79:\
inter_matrix=\
16,18,20,22,24,26,28,30,\
18,20,22,24,26,28,30,32,\
20,22,24,26,28,30,32,34,\
22,24,26,30,32,32,34,36,\
24,26,28,32,34,34,36,38,\
26,28,30,32,34,36,38,40,\
28,30,32,34,36,38,42,42,\
30,32,34,36,38,40,42,44\
"

Q="6" # constant video quality
      # best=2 excellent<=4 good<=7 even=11 for mpeg1  VCD resolution
      #        excellent<=6 good<=9 even=13 for mpeg2 SVCD resolution

#---------- below you can edit parameters ----------

# audio bitrate
#AUDIORATE=128 # constant
AUDIORATE=384 # variable with frequency 48kHz in 112-384kbs band

# frame rate conversion (has to be first in processing chain)
#FRC="-fps 29.97 -ofps 29.97 -vf telecine,lavcdeint," # example to increase fps
#FRC="-fps 29.97 -ofps 29.97 -vf "                    # NTSC
FRC="-fps 25 -ofps 25 -vf "                          # PAL
#FRC="-fps 23.976 -ofps 23.976 -vf "                  # NTSC pulldowned
#FRC="-fps 29.97 -ofps 23.976 -vf filmdint=fast=3,"  # example to decrease fps
#FRC="-vf " # fps not changed

# video filters
VFILTER="pp=de,denoise3d,"

# aspect view of output;
# it should be the same as aspect view of the source mpeg(1,2)
# or equal to width/length if source aspect undefined (example: avi, capture)
# and your player has to be capable to process chosen aspect
#
#ASPECT="1" # 1:1 where have you seen square TV ?!
ASPECT="1.3333" # 4:3 standard TV or monitor
#ASPECT="1.7777" # 16:9 wide screen TV
#ASPECT="1.85" # film academy flat
#ASPECT="2.35" # cinema scope

AB="480:360" # expand to match aspect view, black bands added

# for xvcd
#XY="352:240"
#XY="352:288"
#VCODEC=mpeg1video
#VBuffer=376    # Kbits = 46*1024*8/1000
#MUXMODE="-f 2 -m 1 -V -b 46"
#IMAMODE="-t vcd2"

# for svcd
#XY="480:480"
XY="480:576"
VCODEC=mpeg2video
VBuffer=917    # Kbits = 112*1024*8/1000
MUXMODE="-f 5 -m 2 -V -b 112"
IMAMODE="-t svcd"

# scaling algorithm
#SWS=0 # fast bilinear
SWS=2 # bicubic, for upscaling
#SWS=9 # lanczos, quality

# macroblock decision algorithm
#MBD=0 # compare blocks, fast
#MBD=1 # fewest bits
MBD=2 # rate distortion

# group of pictures length - the longer is better compression, but
# it relies on a player decoder and so resulting playback quality
GOP=25 # dvd pal gop <=15, ntsc <=18 but in practice gop can be longer

# various mencoder -lavcopts parameters
ULAVCOPTS1=":vlelim=-4:vcelim=7:vqblur=0.5:vrc_eq=tex:vmax_b_frames=2:vb_strategy=1"
ULAVCOPTS2=":naq:lumi_mask=0.05:dark_mask=0.01:tcplx_mask=0.05:scplx_mask=0.05:preme=1:predia=2:dia=2"

PASS="single"
#PASS="1st 2nd"

# mencoder verbosity
NOTverbose="2> /dev/null"
#NOTverbose="&> /dev/null"

#CDSIZE=735 # 74min CD
CDSIZE=795 # 80min CD
#CDSIZE=895 # 90min CD

# cdrdao parameters
CDOPT="--overburn --reload --eject"
CDDEV="--device 0,1,0" # SCSI id

#---------- above you can edit parameters ----------

function usage() {
  echo
  echo "Usage:  $HOWCALLED <shrunk name> <file or mplayer source> [quality [$Q]]"
  echo
  echo "qualilty: best=2 excellent<=4 good<=7 even=11 - XVCD"
  echo "                excellent<=6 good<=9 even=13 - SVCD"
  echo
  echo "result: (S,X)VCD and mpeg(1,2) encoded with $HOWCALLED."
  echo
exit 1
}

# command line parsing
HOWCALLED=`basename $0`
[ $# -lt 2 ] && usage

case $1 in
  -*)
      usage
  ;;
  *)
      NAME=$1
      shift 1
  ;;
esac

DIR="`pwd`"
FILE=$1
if [ "$1" == "`basename \"$1\"`" ]; then
  FILE="$DIR/$1"
fi
shift 1

if [ "$1"x != "x" ]; then
  Q=$1
  shift 1
fi
COMMAND_LINE_MENCODER=$*

# encoding
rm -f divx2pass.log
rm -f frameno.avi

for word in $PASS ; do
  MOVIE=$NAME.mpg
  [ "$word" == "single" ] && pass=""
  [ "$word" == "1st"  ] && pass=":vpass=1"
  [ "$word" == "1st"  ] && MOVIE="/dev/null"
  [ "$word" == "2nd"  ] && pass=":vpass=2"

  command="mencoder \
  -forceidx -lavdopts idct=0 \
  $FRC${VFILTER}expand=$AB,scale=$XY -sws $SWS \
  -of mpeg -oac lavc -ovc lavc \
  -lavcopts acodec=mp2:abitrate=$AUDIORATE:aspect=$ASPECT:vcodec=$VCODEC:$MATRIX:idct=0:mbd=$MBD:vqscale=$Q:vrc_minrate=300:vrc_maxrate=2300:vrc_buf_size=$VBuffer:keyint=$GOP${ULAVCOPTS1}${ULAVCOPTS2}$pass \
  $COMMAND_LINE_MENCODER $FILE -o $MOVIE"

  echo "$command $NOTverbose"
  eval "$command $NOTverbose"
done

echo -e "\nyou will wait :p\n"
eval "mplayer -noframedrop -vc dummy -vo null -dumpvideo -dumpfile $NAME.mpv $MOVIE &> /dev/null &"

if [ $AUDIORATE != 384 ]; then
  eval "mplayer -noframedrop -ac dummy -ao null -dumpaudio -dumpfile $NAME.mpa $MOVIE &> /dev/null &"
else
  # re-encoding into variable audio rate
  AUDIO=$NAME.wav
  ###rm -f $AUDIO
  ###mkfifo -m 660 $AUDIO
  eval "mplayer -noframedrop -vc dummy -vo null -ao pcm -waveheader -aofile $AUDIO $MOVIE &> /dev/null"
  eval "normalize -v --fractions $AUDIO" # normalize can't work from pipe
  command="cat $AUDIO | sox -V -t .wav - -r 48000 -t .wav - resample -q | toolame -s 48 -m s -v -1 - $NAME.mpa &"
  echo "$command"
  eval "$command"
fi

wait

#rm -f $MOVIE
#rm -f $AUDIO
# end of encoding

# multiplexing
rm -f $NAME?.mpg
eval "mplex $MUXMODE -S $CDSIZE -o $NAME%d.mpg $NAME.mpv $NAME.mpa"

# imaging
for i in $NAME?.mpg; do
  cue="`basename $i .mpg`.cue"
  bin="`basename $i .mpg`.bin"
  rm -f $cue $bin
  eval "vcdimager $IMAMODE -c $cue -b $bin $i"
done

#rm -f $NAME?.mpv $NAME?.mpa $NAME?.mpg
echo -e "\n$HOWCALLED encoding is completed in $SECONDS seconds.\n"

# CD writing
for cue in $NAME?.cue; do
  bin="`basename $cue .cue`.bin"
  echo "PLEASE INSERT BLANK CD IN CD-WRITER and press any key to begin writing:"
  read -n 1 null
  eval "cdrdao write $CDOPT $CDDEV $cue"
  echo "CD WRITING IS COMPLETED."
done

exit 0
# last line of this script


russiansexpat 12-29-2003 10:17 AM

I have added audio filter to the script, it is requred if source have audio sample rate different from 44.1kHz.
I use variable audio rate encoding, but keep the section with standard frequency 44.1kHz for purists. To say again, variable audio is completely according to SVCD standard
(the only deviation from the standard that I use frequency 48kHz like dvd) and it is playable on every standalone I tried.
I have added crop option for sources with ugly black bands; use extend option according to aspect view you choose, for example use 480:360 if aspect ratio is 4/3.
Template script below is mpeg1 encoding; with celeron 933mHz and RAM 512MB the speed of encoding is 1x movie time.
Code:

#!/bin/bash
#
# Copyright (C) 2003-2038 russiansexpat
#
# script:      mpeg(1,2,3,4) conversion to (S,X)VCD with quantisation matrix
#              and auto-splitting into multiple CDs and writing them.
#
# requires:    mencoder(1.0pre3) mplayer mplex vcdimager cdrdao
# optional:    normalize toolame(0.2k)
#
# does not require: microsoft. This script has not been tested on animals.

for exe in mencoder mplayer mplex vcdimager cdrdao; do
  if [ -z "`which $exe`" ]; then
      echo "ERROR: $exe must be in your path $PATH"
      exit 1
  fi
done

MATRIX="\
intra_matrix=\
8,9,12,22,26,27,29,34,\
9,10,14,26,27,29,34,37,\
12,14,18,27,29,34,37,38,\
22,26,27,31,36,37,38,40,\
26,27,29,36,39,38,40,48,\
27,29,34,37,38,40,48,58,\
29,34,37,38,40,48,58,69,\
34,37,38,40,48,58,69,79:\
inter_matrix=\
16,18,20,22,24,26,28,30,\
18,20,22,24,26,28,30,32,\
20,22,24,26,28,30,32,34,\
22,24,26,30,32,32,34,36,\
24,26,28,32,34,34,36,38,\
26,28,30,32,34,36,38,40,\
28,30,32,34,36,38,42,42,\
30,32,34,36,38,40,42,44\
"

Q="6" # constant video quality
      # best=2 excellent<=4 good<=7 even=11 for mpeg1  VCD resolution
      #        excellent<=6 good<=9 even=13 for mpeg2 SVCD resolution

#---------- below you can edit parameters ----------

# audio bitrate
#AUDIORATE=128 # constant
AUDIORATE=384 # variable with frequency 48kHz in 112-384kbs band

# frame rate conversion (has to be first in processing chain)
#FRC="-fps 29.97 -ofps 29.97 -vf telecine,lavcdeint," # example to increase fps
#FRC="-fps 29.97 -ofps 29.97 -vf "                    # NTSC
FRC="-fps 25 -ofps 25 -vf "                          # PAL
#FRC="-fps 23.976 -ofps 23.976 -vf "                  # NTSC pulldowned
#FRC="-fps 29.97 -ofps 23.976 -vf filmdint=fast=3,"  # example to decrease fps
#FRC="-vf " # fps not changed

# video filters
VFILTER="pp=de,denoise3d,"

# aspect view of output;
# it should be the same as aspect view of the source mpeg(1,2)
# or equal to width/length if source aspect undefined (example: avi, capture)
# and your player has to be capable to process chosen aspect
#
#ASPECT="1" # 1:1 where have you seen square TV ?!
ASPECT="1.3333" # 4:3 standard TV or monitor
#ASPECT="1.7777" # 16:9 wide screen TV
#ASPECT="1.85" # film academy flat
#ASPECT="2.35" # cinema scope

XcYc="346:282" # crop, cut out black bands
XeYe="376:282" # expand to match aspect view, black bands added

# for xvcd
#XY="352:240"
XY="352:288"
VCODEC=mpeg1video
VBuffer=376    # Kbits = 46*1024*8/1000
MUXMODE="-f 2 -m 1 -V -b 46"
IMAMODE="-t vcd2"

# for svcd
#XY="480:480"
#XY="480:576"
#VCODEC=mpeg2video
#VBuffer=917    # Kbits = 112*1024*8/1000
#MUXMODE="-f 5 -m 2 -V -b 112"
#IMAMODE="-t svcd"

# scaling algorithm
#SWS=0 # fast bilinear
SWS=2 # bicubic, for upscaling
#SWS=9 # lanczos, quality

# macroblock decision algorithm
#MBD=0 # compare blocks, fast
#MBD=1 # fewest bits
MBD=2 # rate distortion

# group of pictures length - the longer is better compression, but
# it relies on a player decoder and so resulting playback quality
GOP=25 # dvd pal gop <=15, ntsc <=18 but in practice gop can be longer

# various mencoder -lavcopts parameters
ULAVCOPTS1=":vlelim=-4:vcelim=7:vqblur=0.5:vrc_eq=tex:vmax_b_frames=2:vb_strategy=1"
ULAVCOPTS2=":naq:lumi_mask=0.05:dark_mask=0.01:tcplx_mask=0.05:scplx_mask=0.05:preme=1:predia=2:dia=2"

PASS="single"
#PASS="1st 2nd"

# mencoder verbosity
NOTverbose="2> /dev/null"
#NOTverbose="&> /dev/null"

#CDSIZE=735 # 74min CD
CDSIZE=795 # 80min CD
#CDSIZE=895 # 90min CD

# cdrdao parameters
CDOPT="--overburn --reload --eject"
CDDEV="--device 0,1,0" # SCSI id

#---------- above you can edit parameters ----------

function usage() {
  echo
  echo "Usage:  $HOWCALLED <shrunk name> <file or mplayer source> [quality [$Q]]"
  echo
  echo "qualilty: best=2 excellent<=4 good<=7 even=11 - XVCD"
  echo "                excellent<=6 good<=9 even=13 - SVCD"
  echo
  echo "result: (S,X)VCD and mpeg(1,2) encoded with $HOWCALLED."
  echo
exit 1
}

# command line parsing
HOWCALLED=`basename $0`
[ $# -lt 2 ] && usage

case $1 in
  -*)
      usage
  ;;
  *)
      NAME=$1
      shift 1
  ;;
esac

DIR="`pwd`"
FILE=$1
if [ "$1" == "`basename \"$1\"`" ]; then
  FILE="$DIR/$1"
fi
shift 1

if [ "$1"x != "x" ]; then
  Q=$1
  shift 1
fi
COMMAND_LINE_MENCODER=$*

# encoding
rm -f divx2pass.log
rm -f frameno.avi

for word in $PASS ; do
  MOVIE=$NAME.mpg
  [ "$word" == "single" ] && pass=""
  [ "$word" == "1st"  ] && pass=":vpass=1"
  [ "$word" == "1st"  ] && MOVIE="/dev/null"
  [ "$word" == "2nd"  ] && pass=":vpass=2"

  command="mencoder \
  -forceidx -srate 44100 -lavdopts idct=0 \
  -af resample=44100 $FRC${VFILTER}crop=$XcYc,expand=$XeYe,scale=$XY -sws $SWS \
  -of mpeg -oac lavc -ovc lavc \
  -lavcopts acodec=mp2:abitrate=$AUDIORATE:aspect=$ASPECT:vcodec=$VCODEC:$MATRIX:idct=0:mbd=$MBD:vqscale=$Q:vrc_minrate=300:vrc_maxrate=2300:vrc_buf_size=$VBuffer:keyint=$GOP${ULAVCOPTS1}${ULAVCOPTS2}$pass \
  $COMMAND_LINE_MENCODER $FILE -o $MOVIE"

  echo "$command $NOTverbose"
  eval "$command $NOTverbose"
done

echo -e "\nyou will wait :p\n"

if [ $AUDIORATE != 384 ]; then
  # fixed audio rate
  eval "mplayer -noframedrop -dumpvideo -dumpfile $NAME.mpv $MOVIE &> /dev/null &"
  eval "mplayer -noframedrop -dumpaudio -dumpfile $NAME.mpa $MOVIE &> /dev/null &"
else
  # re-encoding into variable audio rate
  eval "mplayer -noframedrop -srate 48000 -dumpvideo -dumpfile $NAME.mpv $MOVIE &> /dev/null &"
  AUDIO=$NAME.wav
  ###rm -f $AUDIO
  ###mkfifo -m 660 $AUDIO
  eval "mplayer -noframedrop -vo null -vc dummy -ao pcm -waveheader -af resample=48000 -aofile $AUDIO $MOVIE &> /dev/null"
  eval "normalize -v --fractions $AUDIO" # normalize can't work from pipe
  command="cat $AUDIO | toolame -s 48 -m s -v -1 - $NAME.mpa &"
  echo "$command"
  eval "$command"
fi

wait

#rm -f $MOVIE
#rm -f $AUDIO
# end of encoding

# multiplexing
rm -f $NAME?.mpg
eval "mplex $MUXMODE -S $CDSIZE -o $NAME%d.mpg $NAME.mpa $NAME.mpv"

# imaging
for i in $NAME?.mpg; do
  cue="`basename $i .mpg`.cue"
  bin="`basename $i .mpg`.bin"
  rm -f $cue $bin
  eval "vcdimager $IMAMODE -c $cue -b $bin $i"
done

#rm -f $NAME?.mpv $NAME?.mpa $NAME?.mpg
echo -e "\n$HOWCALLED encoding is completed in $SECONDS seconds.\n"

# CD writing
for cue in $NAME?.cue; do
  bin="`basename $cue .cue`.bin"
  echo "PLEASE INSERT BLANK CD IN CD-WRITER and press any key to begin writing:"
  read -n 1 null
  eval "cdrdao write $CDOPT $CDDEV $cue"
  echo "CD WRITING IS COMPLETED."
done

exit 0
# last line of this script


notmyidea 01-01-2004 11:19 PM

First off, thanks for these excellent scripts.
I have tried out your latest version (posted Dec.29) w/o any success in multiplexing.
I get:
++ WARN: [mplex] Stream e0: data will arrive too late sent(SCR)=41652225 required(DTS)=41609503
++ WARN: [mplex] Audio c0: buf= 4096 frame=017695 sector=00002742
++ WARN: [mplex] Video e0: buf= 45075 frame=011555 sector=00025060
**ERROR: [mplex] Too many frame drops -exiting

Any ideas as to what causes this or what parameter I can change?
I am doing VCD mpeg1 encoding w/ CBR audio of 96

otzi 01-03-2004 10:37 AM

I using that script but audio have delay ....

U no have these problem ?

russiansexpat 01-05-2004 07:16 AM

Yes, I have had a problem with video and audio out of sync (slightly), but since the last verson of the script with "-srate 44100" and "-af resample=44100" the problem is gone.
If you read mencoder manpage, it is saying the -srate option adjusts video frame rates according to audio frequency.
In all my cases video and audio out of sync was caused the the source (avi file) had a frame rate slightly diffrent from the standard, for example 24.999 fps instead of 25 fps.
As result, I think, video got out of sync after splitting mpg file into video and audio and then re-multiplexing.
If you do only constant audio bitrate it is not necessary to split video and audio, resample audio into 48kHz and encode into variable audio bitrate; just take .mpg file produced by mencoder and create .bin and .cue with vcdimager.
I think that DTS and SCR delayes gettig out of hand because video buffer (see corresponding varibale in the script) become too small for incoming video packets.
There is no standard specs for the size of video buffer, so it can be changed and 46KB and 112KB buffer sizes is far too low then all moder standalones buffer memory.
I'll try to keep you posted and if you can run some tests, the help is appreciated.
Because current results are promising; I just encoded 2h07m movie into standard SVCD quality 5 with resolution 480x576 and gop 25. and i use varibale audio bitrate with toolame encoder, so audio quality is excellent and if you use mctoolame audio encoder you can put 5.1 surround audio (unfortunately i don't have this audio at home, only left-right and subwoofer).

otzi 01-05-2004 10:32 AM

russiansexpat, thanks ... can u copy the last script here ?

I am using script mkxvcd.sh you know this ? in your opinion its good ?

Thanks again :D

russiansexpat 01-06-2004 09:41 AM

mkxvcd.sh script is interactive script, and of course it is good - a few people worked it out in kvcd4nix project. It is based on mjpegtools (and optionally transcode). encoder mpeg2enc in fact is origin of tmpgenc (another name tsunami) for windose folks and currently have K-matrix option.
Still it is at least twice slower than mencoder or ffmpeg.
I was trying to create a script that it is using just one mencoder/ffmpeg library because the number of option in mencoder is many and allow to tune the result (see ulavcopts options in my script).
If you are not interested in VBR audio, you don't have to re-multiplex video/audio and also you can use tcmplex instead of mplex or original mplex from http://www.linuxtv.org/download/dvb/
it multiplexes prefectly, but can't handle vbr audio, only constant bitrate audio.
Current verson of my script is below:
Code:

#!/bin/bash
#
# Copyright (C) 2003-2038 russiansexpat
#
# script:      mpeg(1,2,3,4) conversion to (S,X)VCD with quantisation matrix
#              and auto-splitting into multiple CDs and writing them.
#
# requires:    mencoder(1.0pre3) mplayer mplex vcdimager cdrdao
# optional:    normalize toolame(0.2k)
#
# does not require: microsoft. This script has not been tested on animals.

for exe in mencoder mplayer mplex vcdimager cdrdao; do
  if [ -z "`which $exe`" ]; then
      echo "ERROR: $exe must be in your path $PATH"
      exit 1
  fi
done

MATRIX="\
intra_matrix=\
8,9,12,22,26,27,29,34,\
9,10,14,26,27,29,34,37,\
12,14,18,27,29,34,37,38,\
22,26,27,31,36,37,38,40,\
26,27,29,36,39,38,40,48,\
27,29,34,37,38,40,48,58,\
29,34,37,38,40,48,58,69,\
34,37,38,40,48,58,69,79:\
inter_matrix=\
16,18,20,22,24,26,28,30,\
18,20,22,24,26,28,30,32,\
20,22,24,26,28,30,32,34,\
22,24,26,30,32,32,34,36,\
24,26,28,32,34,34,36,38,\
26,28,30,32,34,36,38,40,\
28,30,32,34,36,38,42,42,\
30,32,34,36,38,40,42,44\
"

Q="6" # constant video quality
      # best=2 excellent<=4 good<=7 even=11 for mpeg1  VCD resolution
      #        excellent<=6 good<=9 even=13 for mpeg2 SVCD resolution

#---------- below you can edit parameters ----------

# audio bitrate
#AUDIORATE=128 # constant
AUDIORATE=384 # variable with frequency 48kHz in 112-384kbs band

# frame rate conversion (has to be first in processing chain)
#FRC="-fps 29.97 -ofps 29.97 -vf telecine,lavcdeint," # example to increase fps
#FRC="-fps 29.97 -ofps 29.97 -vf "                    # NTSC
FRC="-fps 25 -ofps 25 -vf "                          # PAL
#FRC="-fps 23.976 -ofps 23.976 -vf "                  # NTSC pulldowned
#FRC="-fps 29.97 -ofps 23.976 -vf filmdint=fast=3,"  # example to decrease fps
#FRC="-vf " # fps not changed

# video filters
VFILTER="pp=de,denoise3d,"

# aspect view of output;
# it should be the same as aspect view of the source mpeg(1,2)
# or equal to width/length if source aspect undefined (example: avi, capture)
# and your player has to be capable to process chosen aspect
#
#ASPECT="1" # 1:1 where have you seen square TV ?!
ASPECT="1.3333" # 4:3 standard TV or monitor
#ASPECT="1.7777" # 16:9 wide screen TV
#ASPECT="1.85" # film academy flat
#ASPECT="2.35" # cinema scope

XcYc="346:282" # crop, cut out black bands
XeYe="376:282" # expand to match aspect view, black bands added

# for xvcd
#XY="352:240"
#XY="352:288"
#VCODEC=mpeg1video
#VBuffer=376    # Kbits = 46*1024*8/1000
#MUXMODE="-f 2 -m 1 -V -b 46"
#IMAMODE="-t vcd2"

# for svcd
#XY="480:480"
XY="480:576"
VCODEC=mpeg2video
VBuffer=917    # Kbits = 112*1024*8/1000
MUXMODE="-f 5 -m 2 -V -b 112"
IMAMODE="-t svcd"

# scaling algorithm
#SWS=0 # fast bilinear
SWS=2 # bicubic, for upscaling
#SWS=9 # lanczos, quality

# macroblock decision algorithm
#MBD=0 # compare blocks, fast
#MBD=1 # fewest bits
MBD=2 # rate distortion

# group of pictures length - the longer is better compression, but
# it relies on a player decoder and so resulting playback quality
GOP=25 # dvd pal gop <=15, ntsc <=18 but in practice gop can be longer

# various mencoder -lavcopts parameters
ULAVCOPTS1=":vlelim=-4:vcelim=7:vqblur=0.5:vrc_eq=tex:vmax_b_frames=2:vb_strategy=1"
ULAVCOPTS2=":naq:lumi_mask=0.05:dark_mask=0.01:tcplx_mask=0.05:scplx_mask=0.05:preme=1:predia=2:dia=2"

PASS="single"
#PASS="1st 2nd"

# mencoder verbosity
NOTverbose="2> /dev/null"
#NOTverbose="&> /dev/null"

#CDSIZE=735 # 74min CD
CDSIZE=795 # 80min CD
#CDSIZE=895 # 90min CD

# cdrdao parameters
CDOPT="--overburn --reload --eject"
CDDEV="--device 0,1,0" # SCSI id

#---------- above you can edit parameters ----------

function usage() {
  echo
  echo "Usage:  $HOWCALLED <shrunk name> <file or mplayer source> [quality [$Q]]"
  echo
  echo "qualilty: best=2 excellent<=4 good<=7 even=11 - XVCD"
  echo "                excellent<=6 good<=9 even=13 - SVCD"
  echo
  echo "result: (S,X)VCD and mpeg(1,2) encoded with $HOWCALLED."
  echo
exit 1
}

# command line parsing
HOWCALLED=`basename $0`
[ $# -lt 2 ] && usage

case $1 in
  -*)
      usage
  ;;
  *)
      NAME=$1
      shift 1
  ;;
esac

DIR="`pwd`"
FILE=$1
if [ "$1" == "`basename \"$1\"`" ]; then
  FILE="$DIR/$1"
fi
shift 1

if [ "$1"x != "x" ]; then
  Q=$1
  shift 1
fi
COMMAND_LINE_MENCODER=$*

# encoding
rm -f divx2pass.log
rm -f frameno.avi

for word in $PASS ; do
  MOVIE=$NAME.mpg
  [ "$word" == "single" ] && pass=""
  [ "$word" == "1st"  ] && pass=":vpass=1"
  [ "$word" == "1st"  ] && MOVIE="/dev/null"
  [ "$word" == "2nd"  ] && pass=":vpass=2"

  command="mencoder \
  -forceidx -srate 44100 -lavdopts idct=0 \
  -af resample=44100 $FRC${VFILTER}crop=$XcYc,expand=$XeYe,scale=$XY -sws $SWS \
  -of mpeg -oac lavc -ovc lavc \
  -lavcopts acodec=mp2:abitrate=$AUDIORATE:aspect=$ASPECT:vcodec=$VCODEC:$MATRIX:idct=0:mbd=$MBD:vqscale=$Q:vrc_minrate=300:vrc_maxrate=2300:vrc_buf_size=$VBuffer:keyint=$GOP${ULAVCOPTS1}${ULAVCOPTS2}$pass \
  $COMMAND_LINE_MENCODER $FILE -o $MOVIE"

  echo "$command $NOTverbose"
  eval "$command $NOTverbose"
done

echo -e "\nyou will wait :p\n"

if [ $AUDIORATE != 384 ]; then
  # fixed audio rate
  eval "mplayer -noframedrop -dumpvideo -dumpfile $NAME.mpv $MOVIE &> /dev/null &"
  eval "mplayer -noframedrop -dumpaudio -dumpfile $NAME.mpa $MOVIE &> /dev/null &"
else
  # re-encoding into variable audio rate
  eval "mplayer -noframedrop -srate 48000 -dumpvideo -dumpfile $NAME.mpv $MOVIE &> /dev/null &"
  AUDIO=$NAME.wav
  ###rm -f $AUDIO
  ###mkfifo -m 660 $AUDIO
  eval "mplayer -noframedrop -vo null -vc dummy -ao pcm -waveheader -af resample=48000 -aofile $AUDIO $MOVIE &> /dev/null"
  eval "normalize -v --fractions $AUDIO" # normalize can't work from pipe
  command="cat $AUDIO | toolame -s 48 -m s -v -1 - $NAME.mpa &"
  echo "$command"
  eval "$command"
fi

wait

#rm -f $MOVIE
#rm -f $AUDIO
# end of encoding

# multiplexing
rm -f $NAME?.mpg
eval "mplex $MUXMODE -S $CDSIZE -o $NAME%d.mpg $NAME.mpa $NAME.mpv"

# imaging
for i in $NAME?.mpg; do
  cue="`basename $i .mpg`.cue"
  bin="`basename $i .mpg`.bin"
  rm -f $cue $bin
  eval "vcdimager $IMAMODE -c $cue -b $bin $i"
done

#rm -f $NAME?.mpv $NAME?.mpa $NAME?.mpg
echo -e "\n$HOWCALLED encoding is completed in $SECONDS seconds.\n"

# CD writing
for cue in $NAME?.cue; do
  bin="`basename $cue .cue`.bin"
  echo "PLEASE INSERT BLANK CD IN CD-WRITER and press any key to begin writing:"
  read -n 1 null
  eval "cdrdao write $CDOPT $CDDEV $cue"
  echo "CD WRITING IS COMPLETED."
done

exit 0
# last line of this script


notmyidea 01-06-2004 02:03 PM

Correct me if I am wrong, but tcmplex can't split the mpg for multiplexing over several CDs, only mplex can do that?

russiansexpat 01-07-2004 05:30 AM

Of course, tcmplex also can split mpeg files into multiple CDs.
Look at my modifications of these 2 scripts (please pass respects to original authors):
http://dvdripping-guid.berlios.de/fo...?t=157&start=1
they entirely based on mjpegtools and use tcmplex for multiplexing. I fully tested them but then start using K-matrix and mencoder.

otzi 01-08-2004 02:18 AM

Note, in new version of mplex (1.6.1.92)need remove "-m" in that lines :

SVCD
MUXMODE="-f 5 -m 2 -V -b 112"
VCD
MUXMODE="-f 2 -m 1 -V -b 46"

russiansexpat 01-11-2004 06:20 AM

This is a release of the script, version 0.2.
I have tested it on many avi files and tv captures.
For example, in a last test on tv capture 320*240 wmv
the script fitted single 80 min CD with 150 minutes quality=4 of standard vcd mpeg1 at 1.4x speed on celeron 933MHz.
It is working with both cbr and vbr mp2 audio; you can take out normalize out of the script and feed toolame from fifo pipe, but I found normalize is significantly improving soundtrack hearing.
Compared to the previous version vlelim and vcelim quantisation thresholds have been taken out, and trell quantisation has been added.
I put compulsary parameters in capital caps and optional parameters in small cups in editable section; however optional parameters worked well on all sources.
Code:

#!/bin/bash
#
# Copyright (C) 2003-2038 russiansexpat
#
# script:      mpeg(1,2,3,4) conversion to (S,X)VCD with quantisation matrix
#              and auto-splitting into multiple CDs and writing them.
#
# requires:    mencoder(1.0pre3) mplayer mplex vcdimager cdrdao
# optional:    normalize toolame(0.2k)
#
# does not require: microsoft. This script has not been tested on animals.
#
# version 0.2

for exe in mencoder mplayer mplex vcdimager cdrdao; do
  if [ -z "`which $exe`" ]; then
      echo "ERROR: $exe must be in your path $PATH"
      exit 1
  fi
done

MATRIX="\
intra_matrix=\
8,9,12,22,26,27,29,34,\
9,10,14,26,27,29,34,37,\
12,14,18,27,29,34,37,38,\
22,26,27,31,36,37,38,40,\
26,27,29,36,39,38,40,48,\
27,29,34,37,38,40,48,58,\
29,34,37,38,40,48,58,69,\
34,37,38,40,48,58,69,79:\
inter_matrix=\
16,18,20,22,24,26,28,30,\
18,20,22,24,26,28,30,32,\
20,22,24,26,28,30,32,34,\
22,24,26,30,32,32,34,36,\
24,26,28,32,34,34,36,38,\
26,28,30,32,34,36,38,40,\
28,30,32,34,36,38,42,42,\
30,32,34,36,38,40,42,44\
"

Q="6" # constant video quality
      # best=2 excellent<=4 good<=7 even=11 for mpeg1  VCD resolution
      #        excellent<=6 good<=9 even=13 for mpeg2 SVCD resolution

#---------- below you can edit parameters ----------

# audio bitrate
#AUDIORATE=128 # constant
AUDIORATE=384 # variable with frequency 48kHz in 112-384kbs band

# frame rate conversion (has to be first in processing chain)
#FRC="-fps 29.97 -ofps 29.97 -vf telecine,lavcdeint," # example to increase fps
#FRC="-fps 29.97 -ofps 29.97 -vf "                    # NTSC
FRC="-fps 25 -ofps 25 -vf "                          # PAL
#FRC="-fps 23.976 -ofps 23.976 -vf "                  # NTSC pulldowned
#FRC="-fps 29.97 -ofps 23.976 -vf filmdint=fast=3,"  # example to decrease fps
#FRC="-vf " # fps not changed

# video filters
vfilter="pp=de,denoise3d,eq,"

# aspect view of output;
# it should be the same as aspect view of the source mpeg(1,2)
# or equal to width/length if source aspect undefined (example: avi, capture)
# and your player has to be capable to process chosen aspect
#
#ASPECT="1" # 1:1 where have you seen square TV ?!
ASPECT="1.3333" # 4:3 standard TV or monitor
#ASPECT="1.7777" # 16:9 wide screen TV
#ASPECT="1.85" # film academy flat
#ASPECT="2.35" # cinema scope

#crop="crop=320:240,"    # crop, cut out black bands
#expand="expand=320:240," # expand to match aspect view, black bands added

# for xvcd
#XY="352:240"
XY="352:288"
VCODEC=mpeg1video
VBuffer=376 # Kbits = 46*1024*8/1000
MUXMODE="-f 2 -V -b 46"
IMAMODE="-t vcd2"

# for svcd
#XY="480:480"
#XY="480:576"
#VCODEC=mpeg2video
#VBuffer=917 # Kbits = 112*1024*8/1000
#MUXMODE="-f 5 -V -b 112"
#IMAMODE="-t svcd"

# scaling algorithm
#SWS=0 # fast bilinear
SWS=2 # bicubic, for upscaling
#SWS=9 # lanczos, quality

# macroblock decision algorithm
#MBD=0 # compare blocks, fast
#MBD=1 # fewest bits
MBD=2 # best rate distortion

# group of pictures length - the longer is better compression, but
# it relies on a player decoder and so resulting playback quality
GOP=25 # dvd pal gop <=15, ntsc <=18 but in practice gop can be longer

# various mencoder -lavcopts parameters
ulavcopts1=":vmax_b_frames=2:vb_strategy=1:vqblur=0.3:vqcomp=0.7:vrc_eq=tex"
ulavcopts2=":naq:lumi_mask=0.05:dark_mask=0.01:tcplx_mask=0.1:scplx_mask=0.1"
ulavcopts3=":preme=1:precmp=2:cmp=2:subcmp=2:mbcmp=2:predia=2:dia=2:trell:cbp"

PASS="single"
#PASS="1st 2nd"

# mencoder verbosity
NOTverbose="2> /dev/null"
#NOTverbose="&> /dev/null"

#CDSIZE=735 # 74min CD
#CDSIZE=795 # 80min CD
CDSIZE=895 # 90min CD

# cdrdao parameters
CDOPT="--overburn --reload --eject"
CDDEV="--device 0,1,0" # SCSI id

#---------- above you can edit parameters ----------

function usage() {
  echo
  echo "Usage:  $HOWCALLED <shrunk name> <file or mplayer source> [quality [$Q]]"
  echo
  echo "qualilty: best=2 excellent<=4 good<=7 even=11 - XVCD"
  echo "                excellent<=6 good<=9 even=13 - SVCD"
  echo
  echo "result: (S,X)VCD and mpeg(1,2) encoded with $HOWCALLED."
  echo
exit 1
}

# command line parsing
HOWCALLED=`basename $0`
[ $# -lt 2 ] && usage

case $1 in
  -*)
      usage
  ;;
  *)
      NAME=$1
      shift 1
  ;;
esac

DIR="`pwd`"
FILE=$1
if [ "$1" == "`basename \"$1\"`" ]; then
  FILE="$DIR/$1"
fi
shift 1

if [ "$1"x != "x" ]; then
  Q=$1
  shift 1
fi
COMMAND_LINE_MENCODER=$*

# encoding
rm -f divx2pass.log
rm -f frameno.avi

for word in $PASS ; do
  MOVIE=$NAME.mpg
  [ "$word" == "single" ] && pass=""
  [ "$word" == "1st"  ] && pass=":vpass=1"
  [ "$word" == "1st"  ] && MOVIE="/dev/null"
  [ "$word" == "2nd"  ] && pass=":vpass=2"

  command="mencoder \
  -forceidx -srate 44100 -af resample=44100 \
  -lavdopts er=1:idct=0 $FRC${vfilter}${crop}${expand}scale=$XY -sws $SWS \
  -of mpeg -oac lavc -ovc lavc \
  -lavcopts acodec=mp2:abitrate=$AUDIORATE:aspect=$ASPECT:vcodec=$VCODEC:$MATRIX:idct=0:mbd=$MBD:vqscale=$Q:vrc_minrate=300:vrc_maxrate=2300:vrc_buf_size=$VBuffer:keyint=$GOP${ulavcopts1}${ulavcopts2}${ulavcopts3}$pass \
  $COMMAND_LINE_MENCODER $FILE -o $MOVIE"

  echo "$command $NOTverbose"
  eval "$command $NOTverbose"
done

echo -e "\nyou will wait :p\n"

if [ $AUDIORATE != 384 ]; then
  # fixed audio rate
  eval "mplayer -noframedrop -dumpvideo -dumpfile $NAME.mpv $MOVIE &> /dev/null &"
  eval "mplayer -noframedrop -dumpaudio -dumpfile $NAME.mpa $MOVIE &> /dev/null &"
else
  # re-encoding into variable audio rate
  eval "mplayer -noframedrop -srate 48000 -dumpvideo -dumpfile $NAME.mpv $MOVIE &> /dev/null &"
  AUDIO=$NAME.wav
  ###rm -f $AUDIO
  ###mkfifo -m 660 $AUDIO
  eval "mplayer -noframedrop -vc dummy -vo null -ao pcm -waveheader -af resample=48000 -aofile $AUDIO $MOVIE &> /dev/null"
  eval "normalize -v --fractions $AUDIO" # normalize can't work from pipe
  command="cat $AUDIO | toolame -s 48 -m s -v -1 - $NAME.mpa &"
  echo "$command"
  eval "$command"
fi

wait

rm -f $MOVIE
rm -f $AUDIO
# end of encoding

# multiplexing
rm -f $NAME?.mpg
eval "mplex $MUXMODE -S $CDSIZE -o $NAME%d.mpg $NAME.mpv $NAME.mpa"
#rm -f $NAME.mpv $NAME.mpa

# imaging
for i in $NAME?.mpg; do
  cue="`basename $i .mpg`.cue"
  bin="`basename $i .mpg`.bin"
  rm -f $cue $bin
  eval "vcdimager $IMAMODE -c $cue -b $bin $i"
done
#rm -f $NAME?.mpg

echo -e "\n$HOWCALLED encoding is completed in $SECONDS seconds.\n"

# CD writing
for cue in $NAME?.cue; do
  bin="`basename $cue .cue`.bin"
  echo "PLEASE INSERT BLANK CD IN CD-WRITER and press any key to begin writing:"
  read -n 1 null
  eval "cdrdao write $CDOPT $CDDEV $cue"
  echo "CD WRITING IS COMPLETED."
done

exit 0
# last line of this script



All times are GMT -5. The time now is 09:30 AM  —  vBulletin © Jelsoft Enterprises Ltd

Site design, images and content © 2002-2024 The Digital FAQ, www.digitalFAQ.com
Forum Software by vBulletin · Copyright © 2024 Jelsoft Enterprises Ltd.