Quantcast KVCD Using Menkoder? - Page 2 - digitalFAQ.com Forums [Archives]
  #21  
12-11-2003, 09:24 AM
neturmel neturmel is offline
Free Member
 
Join Date: Dec 2003
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
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
Reply With Quote
Someday, 12:01 PM
admin's Avatar
Site Staff / Ad Manager
 
Join Date: Dec 2002
Posts: 42
Thanks: ∞
Thanked 42 Times in 42 Posts
  #22  
12-11-2003, 10:43 AM
russiansexpat russiansexpat is offline
Free Member
 
Join Date: Nov 2003
Posts: 123
Thanks: 0
Thanked 0 Times in 0 Posts
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.

__________________
are you ready for year 2038?
x+2038-1970 > (2^31+1)/(365.25*24*3600)
/dev/mem < /dev/null
Reply With Quote
  #23  
12-11-2003, 10:56 AM
russiansexpat russiansexpat is offline
Free Member
 
Join Date: Nov 2003
Posts: 123
Thanks: 0
Thanked 0 Times in 0 Posts
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
__________________
are you ready for year 2038?
x+2038-1970 > (2^31+1)/(365.25*24*3600)
/dev/mem < /dev/null
Reply With Quote
  #24  
12-11-2003, 12:27 PM
japie japie is offline
Free Member
 
Join Date: Jul 2003
Posts: 106
Thanks: 0
Thanked 0 Times in 0 Posts
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)
__________________
Groetjes Japie
Reply With Quote
  #25  
12-14-2003, 11:40 AM
russiansexpat russiansexpat is offline
Free Member
 
Join Date: Nov 2003
Posts: 123
Thanks: 0
Thanked 0 Times in 0 Posts
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
__________________
are you ready for year 2038?
x+2038-1970 > (2^31+1)/(365.25*24*3600)
/dev/mem < /dev/null
Reply With Quote
  #26  
12-17-2003, 12:54 PM
russiansexpat russiansexpat is offline
Free Member
 
Join Date: Nov 2003
Posts: 123
Thanks: 0
Thanked 0 Times in 0 Posts

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
__________________
are you ready for year 2038?
x+2038-1970 > (2^31+1)/(365.25*24*3600)
/dev/mem < /dev/null
Reply With Quote
  #27  
12-17-2003, 01:25 PM
japie japie is offline
Free Member
 
Join Date: Jul 2003
Posts: 106
Thanks: 0
Thanked 0 Times in 0 Posts
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)
__________________
Groetjes Japie
Reply With Quote
  #28  
12-18-2003, 04:04 AM
russiansexpat russiansexpat is offline
Free Member
 
Join Date: Nov 2003
Posts: 123
Thanks: 0
Thanked 0 Times in 0 Posts
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?
__________________
are you ready for year 2038?
x+2038-1970 > (2^31+1)/(365.25*24*3600)
/dev/mem < /dev/null
Reply With Quote
  #29  
12-20-2003, 08:10 PM
russiansexpat russiansexpat is offline
Free Member
 
Join Date: Nov 2003
Posts: 123
Thanks: 0
Thanked 0 Times in 0 Posts
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
__________________
are you ready for year 2038?
x+2038-1970 > (2^31+1)/(365.25*24*3600)
/dev/mem < /dev/null
Reply With Quote
  #30  
12-24-2003, 01:06 PM
russiansexpat russiansexpat is offline
Free Member
 
Join Date: Nov 2003
Posts: 123
Thanks: 0
Thanked 0 Times in 0 Posts
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
__________________
are you ready for year 2038?
x+2038-1970 > (2^31+1)/(365.25*24*3600)
/dev/mem < /dev/null
Reply With Quote
  #31  
12-29-2003, 10:17 AM
russiansexpat russiansexpat is offline
Free Member
 
Join Date: Nov 2003
Posts: 123
Thanks: 0
Thanked 0 Times in 0 Posts
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
__________________
are you ready for year 2038?
x+2038-1970 > (2^31+1)/(365.25*24*3600)
/dev/mem < /dev/null
Reply With Quote
  #32  
01-01-2004, 11:19 PM
notmyidea notmyidea is offline
Free Member
 
Join Date: Jan 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
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
Reply With Quote
  #33  
01-03-2004, 10:37 AM
otzi otzi is offline
Free Member
 
Join Date: Nov 2003
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
I using that script but audio have delay ....

U no have these problem ?
Reply With Quote
  #34  
01-05-2004, 07:16 AM
russiansexpat russiansexpat is offline
Free Member
 
Join Date: Nov 2003
Posts: 123
Thanks: 0
Thanked 0 Times in 0 Posts
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).
__________________
are you ready for year 2038?
x+2038-1970 > (2^31+1)/(365.25*24*3600)
/dev/mem < /dev/null
Reply With Quote
  #35  
01-05-2004, 10:32 AM
otzi otzi is offline
Free Member
 
Join Date: Nov 2003
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
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
Reply With Quote
  #36  
01-06-2004, 09:41 AM
russiansexpat russiansexpat is offline
Free Member
 
Join Date: Nov 2003
Posts: 123
Thanks: 0
Thanked 0 Times in 0 Posts
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
__________________
are you ready for year 2038?
x+2038-1970 > (2^31+1)/(365.25*24*3600)
/dev/mem < /dev/null
Reply With Quote
  #37  
01-06-2004, 02:03 PM
notmyidea notmyidea is offline
Free Member
 
Join Date: Jan 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Correct me if I am wrong, but tcmplex can't split the mpg for multiplexing over several CDs, only mplex can do that?
Reply With Quote
  #38  
01-07-2004, 05:30 AM
russiansexpat russiansexpat is offline
Free Member
 
Join Date: Nov 2003
Posts: 123
Thanks: 0
Thanked 0 Times in 0 Posts
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.
__________________
are you ready for year 2038?
x+2038-1970 > (2^31+1)/(365.25*24*3600)
/dev/mem < /dev/null
Reply With Quote
  #39  
01-08-2004, 02:18 AM
otzi otzi is offline
Free Member
 
Join Date: Nov 2003
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
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"
Reply With Quote
  #40  
01-11-2004, 06:20 AM
russiansexpat russiansexpat is offline
Free Member
 
Join Date: Nov 2003
Posts: 123
Thanks: 0
Thanked 0 Times in 0 Posts
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
__________________
are you ready for year 2038?
x+2038-1970 > (2^31+1)/(365.25*24*3600)
/dev/mem < /dev/null
Reply With Quote
Reply




Thread Tools



 
All times are GMT -5. The time now is 10:08 PM  —  vBulletin Jelsoft Enterprises Ltd