digitalFAQ.com Forums [Archives]

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

russiansexpat 01-23-2004 01: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 04: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 05: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 05: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 06:04 AM

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

russiansexpat 01-23-2004 06: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 03: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 04: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 05: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 09: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 05: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 05: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 05: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 05: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 09: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 10: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 02: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 04: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 04:37 AM

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

istevens 02-05-2004 12:48 PM

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 04:34 AM  —  vBulletin © Jelsoft Enterprises Ltd

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