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)

dafart 01-12-2004 11:26 AM

Very nice sripty, well done!
Can I put subtitles in the same directory as the .avi to make mencode add these subtitles to the kvcd/skvcd (hardsubbed)
If not is there another way to add subs ?
Thanx in advance

russiansexpat 01-12-2004 01:00 PM

I was not doing subtitles or used this script for dvd authoring.
(Look into 'man mplayer' in OSD/SUB OPTIONS section and vobsubout options of mencoder)?
The only thing I remember that video buffer size should be 224Kb (twice the the size of svcd video buffer) and gop should be less or equal 15 for pal and 18 for ntsc.
Another way to add subtitles and menu, I guess, can be done by vcdimager .xml descriptors.
If you know how to add dvd authoring to the script - do it and let us know.
My priority now is to find some gui wrapper for the script, so that you don't have to edit the scrupt everytime before use.
Also, it would be helpful to add features like source analysis before encoding; it can be done by mplayer -v -identify options and -cropdetect.

dafart 01-14-2004 05:22 AM

Sorry but I lack the coding skills to help you out with a GUI wrapper or vcdimager implementation for authoring (haven't used xml yet)
But it would be great to see this script with a usefull GUI to avoid changing settings all the time indeed.
One short question: is it possible to use this script for encoding to 2 CD's as well?
Imho movies >120 minutes look a lot better when you make it a 2 CD skvcd rip.
I hope that's not that hard to ask,
And thanx again..

russiansexpat 01-14-2004 07:50 AM

The script splits the resulting .mpg .bin .cue files automatically according CDSIZE variable.
That's why mpeg file produced by mencoder has to be de-multiplexed into video and audio and then multiplexed again by external multiplexer (mplex or tcmplex) with usage of CDSIZE break point.
(Maybe this can be done by mplayer itself, by counting frames and determing the stream size.)
If mpeg produced by mencoder is fit for single CD, you can just pass it to vcdimager to produce .bin and .cue files.
(Meanwhile I use separate audio encoding by toolame with variable audio bitrate and normalize sound level, but it is not necessary; i just found that the quality of soundtrack is better with this separate audio encoding).

dafart 01-14-2004 08:06 AM

What I actually mean is: can I set cdsize to something like CDSIZE=1600 #(2x 795MB to fit on 2 700 MB cdr's) so that it encodes to an mpeg with increased bitrate & quality to fit on 2 cd's.
Or is this script/mencoder limited to these 3 settings only?
Code:

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

I know the best way to find out is to try myself but since it takes quite some time for a decode to finish I was hoping to get some answers here.

Would it also be possible to use this script in order to try using kdvd templates to create Res : 720x480 rips ?
Or doesn't it make sense using this script for this purpose.
eg:
Code:

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

Or will I need to use another input in IMAMODE="-t svcd"] ? Like kdvd? --probably not supported?



/me hopes no to bother too much with asking all these questions ;)

russiansexpat 01-14-2004 08:49 AM

The script does not calculate quality (or video bitrate in earlier versions) for CD size and their numbers, because it is simply not possible to predict the size of resulting mpeg file accurately.
However, it is not a big drama: chose AUDIORATE constant
and any constant quality, start the script and watch mencoder output bottom line - it displays estimated completion time, estimated final size and current birates.
I recommend to run it at least for 10% of encoding, it displayes in brackets after current fame number.
Then you choose quality in command line according desired final size.
(For variable audio rate initial encoding is 384Kbs, but resulting variable audio is usually can be around 160Kbs, so you need to do simple math :D)

dr_fawlty 01-17-2004 08:20 PM

can't execute script - russiansexpat
 
I am visitor from the "linux media" forum and thought I'd get a few ideas from here.

I tried your script but can't get it to work. I left it pretty much alone and only commented and uncommented a few lines. When I do "./[name of script] [file.avi], I get the following message:

Usage: $HOWCALLED <shrunk name> <file or mplayer source> [variable video bitrate kbs [$VBITRATE]]"

"result: (S,X)VCD and mpeg(1,2) encoded with $HOWCALLED."

or something close...I copied this message from the script as it is the closest. I'm away from my linux box now.

Here is a copy of the script if you care to look. As I said, I only changed a few "#" to make it work for the file.
-------------------------------------------------------------------------------------
#!/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=130 # 80min CD
#CDSIZE=895 # 90min CD

CDOPT="--force --reload --eject"
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

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:vr c_minrate=300:vrc_maxrate=2300:vrc_buf_size=320:ke yint=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
:idea: :idea: :arrow: :idea:

russiansexpat 01-18-2004 06:31 AM

Simply your usage was wrong.
Example:
./name_of_the_script result_base file.avi 5
will produce the resulting files with result_base names from source file.avi and quality=5.

russiansexpat 01-18-2004 06:32 AM

Simply your usage was wrong.
Example:
./name_of_the_script result_base file.avi 5
will produce the resulting files with result_base names from source file.avi and quality=5.

dafart 01-19-2004 08:53 PM

I think you didn't use the latest version of mencoder and all other required software.
At least I didn't check my version of mplayer before running the script and I got the same output.
maybe this'll help.

russiansexpat; what will be the difference fo your script when it's build in a programm like avidemux as gui, compared with the kvcd conversion that is already available?
is there a difference or is it the same?

russiansexpat 01-19-2004 11:33 PM

#(rpm -qa | grep mplayer | sort ; rpm -qa | grep mencoder)
mozilla-plugin-mplayer-1.0pre2-2
mplayer-1.0pre3-1
mplayer-codecs-extralite-1.0-1
mplayer-codecs-linux-real-9.0-2
mplayer-codecs-linux-xanim-1.1-1
mplayer-codecs-linux-xanim-3ivx-1.1-1
mplayer-codecs-win32-1.1-1
mplayer-codecs-win32-dmo-9.0-2
mplayer-codecs-win32-indeo-1.1-1
mplayer-codecs-win32-mjpeg2k-1.0-2
mplayer-codecs-win32-qt-6.0-2
mplayer-codecs-win32-qt-extras-1.1-1
mplayer-common-1.0pre3-1
mplayer-font-cp1250-1.1-1
mplayer-font-iso1-1.1-1
mplayer-font-iso2-1.1-1
mplayer-font-iso7-1.1-1
mplayer-font-iso9-1.1-1
mplayer-font-koi8r-1.1-1
mplayer-gui-1.0pre3-1
mplayer-skin-default-1.0-2
mplayer-skin-slim-1.0-2
mplayer-tools-1.0pre3-1
mplayer-vidix-1.0pre3-1
mplayer-vidix-nvidia-1.0pre3-1
mencoder-1.0pre3-1
#

I use both mplayer and mencoder version -1.0pre3-1 from rpm binaries for RedHat Linux.
It could be a problem with parsing command line if you use other compiled versions, but it is not difficult to figure it out at your end.
Check what shell do you use to run the script; it is bash script and also it can be run from shell (bourne shell) but not ksh or csh.
Try to run "sh -x scriptname resultname sourcename 6"

There is a topic
http://www.kvcd.net/forum/viewtopic.php?t=8017
where I am asking for volunteers to develop simple gui
for example in tcl/tk for the script. At this moment I don't have enough resources (brains and time) to do it myself.

zomo 01-21-2004 06:23 AM

**ERROR: [mplex] Too many frame drops -exiting
 
I'm trying to make a SVCD with the menkoder script posted here, but when mplex runs I get a lot of warnings like this:

++ WARN: [mplex] Stream e0: data will arrive too late sent(SCR)=25198602 required(DTS)=7261342
++ WARN: [mplex] Video e0: buf= 112397 frame=001925 sector=00002237

and finally :

**ERROR: [mplex] Too many frame drops -exiting

and the mpg doesn't get builded.

I'm using mplayer and mencoder 1.0pre3 and mplex 1.6.1.92,
the version of menkoder is 0.2.

Somebody also gets this problem ?

russiansexpat 01-21-2004 06:59 AM

I have had a long struggle with these errors.
Usually they appear when the source has problems with a frame rate.
Try to specify explicitly FRC parameter with -fps and -ofps
(you have to know frame rate of your source); if it does not help, then try FRC with filmdint (aka reverse telecine) parameter.
Alternatively, chose a constant audio rate and use tcmplex instead of mplex; tcmplex does not produce these kind of errors, but check audio/video sync of the result.

otzi 01-21-2004 08:06 AM

W/ version 0.2 I have same problem ...

My audio not sync w/ video ..in constant bit rate ..

in variable bit rate i have error in mplex ...

dpkg -l|egrep mjpe\|toolame\|normali\|mencoder\|mplayer\|ffmp\|v cd |awk '{print $2,"\t"$3}'

ffmpeg 0.4.8-sarge0.0
libmjpegtools0 1.6.1.92-0.1
mencoder-k7 1.0-pre3-0.0
mjpegtools 1.6.1.92-0.1
mplayer-fonts 3.3-0.1
mplayer-k7 1.0-pre3-0.0
normalize 0.7.6-3
toolame 02i-2
vcdimager 0.7.14-1
vcdtools 0.4-2


anybody can help-me ?

russiansexpat 01-21-2004 10:14 PM

I don't have these errors to fatal extent, so I've been able to multiplex video and audio by mplex.
De-multiplexing part of the code is here:
Code:

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"

If you use only fixed audiorate, then .mpg file $MOVIE produced by mencoder can be passed straight to vcdimager,
without de-mux and re-mux.
(Unfortunately, then you don't have ability to split the result into multiple CDs, so $MOVIE should be less $CDSIZE to fit single CD).
I appreciate your feedback. Thanks

otzi 01-22-2004 05:58 AM

I have solved my problem :D

problem is FPS ....


#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

only, work w/ this FRC ....

russiansexpat

Koenie 01-22-2004 06:36 AM

Quote:

Originally Posted by russiansexpat
I have had a long struggle with these errors.
Usually they appear when the source has problems with a frame rate.
Try to specify explicitly FRC parameter with -fps and -ofps
(you have to know frame rate of your source); if it does not help, then try FRC with filmdint (aka reverse telecine) parameter.
Alternatively, chose a constant audio rate and use tcmplex instead of mplex; tcmplex does not produce these kind of errors, but check audio/video sync of the result.

I'm also experiencing these problems. I did specify the FRC parameters (I thought that was required anyway), they are set to the PAL values. I'm not aware of my source having any problems, and, being new to all this, I don't know how to check this. When playing in mplayer, it tells me the sources is indeed 25 fps, so that should be ok.

I'm also having difficulties trying to understand why the sound is resampled to 48 kHz. I thought VCD/SVCD is 44.1 kHz, or is the 48 kHz also related to KSVCD?

Last one: I just tried to make a very simple GUI, which isn't that hard (glade/python), but I can hardly test it if I can't even encode video myself :-(

zomo 01-22-2004 08:07 AM

Quote:

Originally Posted by russiansexpat
I have had a long struggle with these errors.
Usually they appear when the source has problems with a frame rate.
Try to specify explicitly FRC parameter with -fps and -ofps
(you have to know frame rate of your source); if it does not help, then try FRC with filmdint (aka reverse telecine) parameter.
Alternatively, chose a constant audio rate and use tcmplex instead of mplex; tcmplex does not produce these kind of errors, but check audio/video sync of the result.

I've already used FRC="-fps 25 -ofps 25", my source and destination are PAL, so I dont think filmdint will be usefull.
Finally, I've used tcmplex with constant audio rate, and it worked ok, with audio/video synced all the movie.

Another thing I dont understand of the menkoder script, is why first encode the audio with mencoder, then generate a .wav, and then again encode it with toolame ? Is for something related to the frame rate ?
Why not dump the original audio to .wav and then encode with toolame ? Each encode looses quality.

Regards

russiansexpat 01-22-2004 08:17 AM

If your source is avi file, then it has header and this header can be wrong
(and real frame rate = number_of_frames/movie_time can be different) because it was encoded with corrupted encoder.
avi files are not original sources - original sources are mpeg or analog video.
transcode has tools to analyze source and fix avi header:
tcprobe, tcscan and avifix, but transcode itself is very-very slow encoder.
Try
FRC="-fps 25 -ofps 25 -vf filmdint=fast=3,"
it will de-interlace the source and do frame rate conversion regardless.

48 KHz frequency aduio was discussed earlier - it is a limitation of mp2 variable rate encoding, see
http://mikecheng.d2.net.au/layer2/vbr.html
You can have variable audiorate encoding
in 44.1KHz and stereo 192-384kbps bitrate range.
Standalone DVD players accept 48KHz and all standalones I've tried play variable mp2 also, so I chose
48KHz because of wider bitrate band 112-384kbps.

Quote:

Another thing I dont understand of the menkoder script, is why first encode the audio with mencoder, then generate a .wav, and then again encode it with toolame ? Is for something related to the frame rate ?
Why not dump the original audio to .wav and then encode with toolame ? Each encode looses quality.
I dump video and audio from the _same_ $MOVIE mpeg file, trying to have audio/video in sync.
If you dump .wav from the source, and encode video separately, it is another risk of adio/video being not in sync.

Maybe it is a time to sipmplify the script (as mentioned already) - not de-mux and then re-mux audio and video, but instead just pass $MOVIE result file from mencoder straight to vcdimager and use only fixed audiorate.
Mpeg files can be splitted by mpgtx tool according to $CDSIZE, see
http://mpgtx.sourceforge.net/

Koenie 01-22-2004 09:24 AM

Quote:

Originally Posted by russiansexpat
Try
FRC="-fps 25 -ofps 25 -vf filmdint=fast=3,"
it will de-interlace the source and do frame rate conversion regardless.

I just tried that; unfortunately, mplex still gives me a bunch of 'stream e0: data will arrive too late sent(SCR)=xxx required(DTS)=yyy' and then just quits with 'too many frame drops'. :-(

Quote:

Originally Posted by russiansexpat
Standalone DVD players accept 48KHz and all standalones I've tried play variable mp2 also, so I chose
48KHz because of wider bitrate band 112-384kbps.

OK. But in that case, why is it resampled to 44.1kHz first (by mencoder)? And, another audio-thing: Is there any way I can get 5+1 audio that may be present in the AVI into an MPEG-2 stream in the SVCD? And yet another one: Why encoding mp2 in the mencoder-step, when you're decoding it to wav later on?

As I sidenote, I like VBR, so I'd opt to leave it in the script. Not because it sounds better (haven't done any comparison), but because I think the technique is nice...

russiansexpat 01-23-2004 12:20 AM

I have put
-srate 44100 -af resample=44100
to ensure encoding audio into (S)VCD compliant format,
and because source can have audio with any frequency sample rate.
My problems with frame rate and audio/video sync resolved
after introduction of -srate (it adjusts video frame rate according to audio while encoding, see man mplayer) and -lavdopts idct=0 option.

Try to avoid frame rate conversion if possible, with
FRC="-vf " # fps not changed
(even it is a contradiction with my prevous postings), because
for me frame rate in sources was the root of audio/video sync problems.

For multichannel audio (5.1) you can use
http://mctoolame.sourceforge.net/
or use mecoder audio options for multichannel audio.
It uses ffmpeg audio codec for mp2.

Again, ensure that you have mplayer and mencoder 1.0pre3
- it was audio/video sync bug in previous versions, reported in a mailing list.

Koenie 01-23-2004 03:23 AM

Quote:

Originally Posted by russiansexpat
I have put -srate 44100 -af resample=44100 to ensure encoding audio into (S)VCD compliant format, and because source can have audio with any frequency sample rate.

I understand that you use -srate, but I don't really understand why you would first resample it to 44.1kHz (mencoder), and then resample it to 48kHz again (for variable audio rate).
Quote:

Originally Posted by russiansexpat
Try to avoid frame rate conversion if possible, with FRC="-vf " # fps not changed

I'm trying it right now. Didn't work... However, I'll try with the RTC enabled now.
Quote:

Originally Posted by russiansexpat
For multichannel audio (5.1) you can use http://mctoolame.sourceforge.net/ or use mecoder audio options for multichannel audio. It uses ffmpeg audio codec for mp2.

Thanks for the link. I'm not quite sure how to incorporate this, though, since, as I understand it, in the mencoder step, the 5.1 audio is already lost. I'm about to give up on this, because it seems that I'm never able to find the information I need when it comes to mplayer/transcode/other video/audio codec/fileformat stuff :-(
Quote:

Originally Posted by russiansexpat
Again, ensure that you have mplayer and mencoder 1.0pre3
- it was audio/video sync bug in previous versions, reported in a mailing list.

MEncoder 1.0pre3-3.3.3 should be alright then.

PS: Even though it seems that every answer you give results in two more questions from me, I appreciate your script, time and answers!

russiansexpat 01-23-2004 04:45 AM

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

Enable Real Time Clock (RTC) for mplayer.
It is the first thing I did before start developing the script, and
this affects the whole syncing in mplayer/mencoder.

The description is here:
http://www.mplayerhq.hu/DOCS/HTML/en/rtc.html

russiansexpat 01-23-2004 04:56 AM

Quote:

I understand that you use -srate, but I don't really understand why you would first resample it to 44.1kHz (mencoder), and then resample it to 48kHz again (for variable audio rate).
This is a shortcoming of the script in case of variable audio, I agree. It can be fixed by chosing different -srate parameter
in mencoder line, according to the case fixed or variable audiorate. Somehere in the coder before mencoder line
should be 'case' or 'if' statement to set $SRATE variable and in menoder line it should be:
-srate $SRATE -af resample=$SRATE
I just was trying to keep the script as simple as possible, and double resampling did not reduce sound quality in my results.

otzi 01-23-2004 05:04 AM

russiansexpat , can I modify u script to suport subtitles and post here ?

russiansexpat 01-23-2004 05:32 AM

Quote:

russiansexpat , can I modify u script to suport subtitles and post here ?
sure. very much welcome.
Who is interested in developing GUI for the script, join the topic:
http://www.kvcd.net/forum/viewtopic.php?t=8017

otzi 01-23-2004 02:41 PM

russiansexpat, if I set audio bitrate in 128 I need use mplex ?

script with subtitle suport is done I need more test to post .

russiansexpat 01-24-2004 03:59 AM

If you chose to use fixed audiorate only,
you can use tcmplex from transcode or dvb-mplex from libdvb
http://www.metzlerbros.org/dvb/libdvb-0.5.3.tar.gz
they are less sensitive to sync errors,
but they are unable to multiplex with variable audiorate
(I've tested them both).
Alternatively (as mentioned before) don't de-multiplex and re-multiplex at all,
just pass $MOVIE mpeg file from mencoder line to vcdimager
(I've not tested it myself, but developers say it suppose to be working).

otzi 01-25-2004 04:59 PM

That work 100% for my ....

I use file generated by mencoder to vcdimager and this work ...

god bye mplex errors :D :wink:

zomo 01-26-2004 08:03 AM

I'm using constant audio rate and tcmplex, or directly the output from mencoder and it works ok to create VCDs.

Now my problem is that I cant fit more than 150 minutes of video at VCD resolution (352x288 at 25 fps) at quality 4 or 5.

All kind of video compress the same ?

I'm using a 640x480 high bitrate tv capture from satellite, no transmision noise, and its a mix of animation and real footage.

russiansexpat 01-27-2004 04:07 AM

So, if you use fixed audio rate only, there is no need for (de)multiplexing at all.
You can use http://mpgtx.sourceforge.net/
for splitting $MOVIE mpeg file before vcdimger according to desired size or time.
In case of SVCD it is required, because vcdimger has a limit of 100min for one SVCD track, but you can have multiple tracks (mpeg files) on a single CD.
Thanks everybody for feedbacks and continue publish your results and modified scripts, especially if you added interactive or simplified feautures to the script.

otzi 01-27-2004 04:10 AM

Quote:

Originally Posted by zomo
I'm using constant audio rate and tcmplex, or directly the output from mencoder and it works ok to create VCDs.

Now my problem is that I cant fit more than 150 minutes of video at VCD resolution (352x288 at 25 fps) at quality 4 or 5.

All kind of video compress the same ?

I'm using a 640x480 high bitrate tv capture from satellite, no transmision noise, and its a mix of animation and real footage.

Its no easy :D try increase size of GOP ...

otzi 01-27-2004 04:19 AM

This version of menkoder suport subtiles you need have video and subtitle with a same name.
This suport only .sub and .srt

I copy tetra script subtitle parts and add suport to more video types (ogm wma) and make changes

example :
myvideo.avi - myvideo.srt

Code:

./menkoder myvcd myvideo.avi 4
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.3
#
# Changeslog
#
# - Added subtitle suport (Alexandre Possebom(otzi))
#

for exe in mencoder mplayer mplex vcdim
ager 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=192 # 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

# Subtitle settings
blur=4
subpos=75
textscale=4
outline=4
autoscale=2

#---------- above you can edit parameters ----------
FILE=$2
tmp=`echo $FILE | sed s/\....$//`
SUB=""
[ -f "${tmp}".sub ] && SUB="-sub ${tmp}.sub -subpos ${subpos} -subfont-autoscale ${autoscale} -subfont-outline ${outline} -subfont-text-scale
${textscale}"
[ -f "${tmp}".srt ] && SUB="-sub ${tmp}.srt -subpos ${subpos} -subfont-autoscale ${autoscale} -subfont-outline ${outline} -subfont-text-scale ${textscale}"
tmp=""



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 $SUB \
  -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 $NOTverbose "
  eval "mplayer -noframedrop -dumpaudio -dumpfile $NAME.mpa $MOVIE $NOTverbose "
else
  # re-encoding into variable audio rate
  eval "mplayer -noframedrop -srate 48000 -dumpvideo -dumpfile $NAME.mpv $MOVIE $NOTverbose"
  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 $NOTverbose"
  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

[/code]

istevens 02-02-2004 04:57 PM

Lots of skipped frames while encoding
 
Thanks for posting this wonderful script. I have converted an AVI to MPEG1 but when I did so there were a lot of skipped frames when encoding:

Code:

...
Skipping frame!
Pos:1137.9s  30312f (22%)  20fps Trem:  83min 331mb  A-V:0.070 [359:191]
Skipping frame!
Pos:1138.3s  30322f (20%)  20fps Trem:  96min 372mb  A-V:0.070 [358:191]
Skipping frame!
Pos:1138.7s  30332f (20%)  20fps Trem:  96min 372mb  A-V:0.070 [358:191]
Skipping frame!
Pos:1139.0s  30342f (20%)  20fps Trem:  96min 372mb  A-V:0.070 [358:191]
Skipping frame!
Pos:1139.4s  30352f (22%)  20fps Trem:  83min 331mb  A-V:0.070 [358:191]
Skipping frame!
Pos:1139.8s  30362f (20%)  20fps Trem:  96min 372mb  A-V:0.070 [358:192]
Skipping frame!
...

When I play the resulting MPEG, the audio drifts, although that might have been more because the audio was separated and then multiplexed. Surely dropping so many frames (2-4 per second) will result in some loss of quality. The video looks OK but, as I said, the audio drifts considerably.

Is there any way to overcome the skipping? I have seen this for every AVI I have thus far encoded, except for one which had the occasional (two or three times per minute) duplicate frame.

FYI, I am using the defaults and have encoded with quality betweeo 4 and 8.

thanks in advance,

otzi 02-02-2004 08:14 PM

I have same problem ... i solved it changing FRC ... try all parameters ...


frame skip is nota problem is a frame rate .. example have films with 29 fps .. u convert to 25 fps ... 4 frames per seconds is been skipped :D

I think it russianexplat can solve that question :D

istevens 02-02-2004 09:10 PM

Thanks otzi. I switched from the default first options (-fps 29.97 -ofps 29.97 -vf telecine,lavcdeint,) to the second set (-fps 29.97 -ofps 29.97 -vf) and now only see a few skipped frames per AVI.

russiansexpat 02-03-2004 01:01 AM

Some mpeg4 encoders produce broken or duplicated frames in AVI source, so if a few frames are skipped - it is normal.
If frames skipping is consistent, it means that you need to choose FRC (frame rate conversion) appropriate to your source.
For example, if you have NTSC source and try to encode it to PAL with -fps 25 -ofps 25 without filmdeint or telecine, frames will be skipped.
Another example is wmv microsoft source with variable (1000fps) frame rate; in this case you have to use FRC -fps and -ofps to specify resulting frame rate.

istevens 02-03-2004 03:28 PM

Now I'm having problems creating a VCD image using vcdimager. Note that I am not demuxing then muxing the stream, so that may be a problem:

Code:

  INFO: scanning mpeg sequence item #0 for scanpoints...
++ WARN: mpeg stream will be padded on the fly -- hope that's ok for you!
++ WARN: APS' pts seems out of order (actual pts 270.270667, last seen pts 270.304033) -- ignoring this aps
++ WARN: APS' pts seems out of order (actual pts 1452.289956, last seen pts 1452.323322) -- ignoring this aps
++ WARN: APS' pts seems out of order (actual pts 3171.881944, last seen pts 3171.915311) -- ignoring this aps
++ WARN: autopadding requires to insert additional 37921296 zero bytes into MPEG stream (due to 137396 unaligned packets of 137397 total)
++ WARN: audio stream #0 has bitrate 196608 kbps (should be 224 kbps for this vcd type)

Should I be worried that 99.99% of the packets are unaligned? Is this because I haven't mplexed the audio and video? What about the other warnings?

I haven't tried to burn the resulting image as I am SSHing from home.

russiansexpat 02-04-2004 03:37 AM

These are not errors, only warnings.
Image should be ok; let us know otherwise.

istevens 02-05-2004 11:48 AM

I have menkoded a couple AVIs using my new FRC settings. Both AVIs gave me many "Duplicate frame" errors when mencoding. The resulting video still looks good, but the audio drifts significantly behind the video. Towards the beginning the audio is a few seconds behind, which quickly turns into minutes.

Is this a case of mencoder dropping video frames but not adjusting the audio to compensate?

I am going to play a little with the FRC settings to see if that will change anything.


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

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