-   LinuxAnswers Discussion (
-   -   DISCUSSION: Converting video to VCD, SVCD, or DVD (

wapcaplet 06-21-2004 10:33 PM

tovid discussion forum
This thread began life as a forum for discussing the article: Converting video to VCD, SVCD, or DVD. It was, for a good length of time, the official discussion and support forum for the tovid suite, which grew from the above script.

Now, this thread is mostly historical, because tovid has its own forum site. Please direct inquiries there!

sbogus 06-22-2004 06:00 AM

Hi wapcaplet,
Thanks for the great article. I'd like to ask one small question.

I've used the SVCD version of the script (divx2svcd) to convert one DivX 5.1 file to the corresponding SVCD image, but got very irritating results.

First of all, the AVI length is something about 87000 frames (52 min.) and is 704 MB big. I got a dozen of files with sizes from 200 bytes to 900 MB big.
This is what I found in the folder containing the AVI file and the subtitle one.

The original files
the AVI file itself: MyDivXFilm.avi
the SUB file:

The transcoded files
some file named MyDivXFilm.m2v and 720MB big
some file named MyDivXFilm.mpa and 67 MB big
some file named Pelicula.mpg and 900MB big
some file named Pelicula00.mpg and 712MB big
some file named Pelicula00.mpg.bin and 711MB big
some file named Pelicula00.mpg.cue and 178 Bytes big
some file named Pelicula01.mpg and 89MB big
some file named Pelicula01.mpg.bin and 87MB big
some file named Pelicula01.mpg.cue and 178 Bytes big

So, what is supposed to be done with these bunch of big&mighty files? And how comes it that I got the Film split in two parts?

One furter question: May I use a DVD media to write a (S)VCD where all parts of the film are in one place?

Many thanks in advance.

Kind regards,

wapcaplet 06-26-2004 11:13 PM

It looks like you are using divx2svcd. I cannot answer for that script, since I did not write it :) In fact, I've never been able to get anything useful out of it myself; I just borrowed some segments of it for mine.

Though, I did realize after posting my script that there is one small mistake: there are two lines towards the end, under "Cleaning up..." that read:


# rm "$OUTPREFIX.mpa"

Uncomment them by removing the leading hash mark. Those are the reason you are left with an extra 'mpa' and 'm2v' file after encoding. With my script, you should end up with is a new file with an .mpg extension, and nothing else. The size is somewhat out of your control, with the current version, however. I'll see about introducing a bit-rate option for SVCD. 704MB sounds reasonable for 52 minutes of video.

I've made a lot of changes to my script since I posted this... I'll have to see about revising the posted version.

wapcaplet 06-26-2004 11:26 PM

Here is a revised version of my script. Additions and alterations include:
  • New 'panavision' aspect ratio option. Some movies are in an aspect ratio of about 2.35:1 (which is quite a bit wider than the 16:9 ratio). If you have such a video, use the 'panavision' command-line option, rather than 'widescreen'. Easy way to find out: divide the width by the height (in pixels). If it's close to 2.35, you have 'panavision'. If it's closer to 1.85, you have 'widescreen'. If you use the wrong one for your video, the picture may look squished/stretched.
  • New 'half-dvd' output format. DVD supports a 'half' resolution of 352x480, which is suitable for TV shows or other stuff you may have that 720x480 would be overkill for.
  • Bitrate options. You can hard-code bitrates into the lines at the beginning for both DVD and half-DVD. I've found the given values to be fairly good.
  • Removed dependencies on transcode and perl. Good because I found some source video that transcode's 'tcprobe' choked on. mencoder used for all video identification now.

  • Bitrate option for SVCD
  • Better aspect ratio guessing (works for some, but not others, e.g. panavision)
  • Better system for audio normalization. Works for some, distorts others. (normalization is still commented out, but uncomment the 'normalize...' line if you need it)

Here it is. Enjoy!



# Convert any video/audio stream that mplayer can play
# into VCD, SVCD, or DVD-compatible Mpeg output file.
# Arguments: $1 - format: Video CD, Super Video CD, DVD, or VCD-on-DVD [vcd|svcd|dvd]
#            $2 - aspect: Widescreen or full-frame [wide|full]
#            $3 - name of input file
#            $4 - name of output prefix

# Some constants to use:
# Maximum bitrates (for video):
#  kbps    guaranteed    possible    notes
# ----------------------------------------------------
#  7500    81 min.      270 min.    Good for full DVD
#  3000    194 min.      400 min.    Good for half-D1
# Bitrate to use for Half-D1-encoded DVD format. Since resolution of Half-D1 is
# a little less than half that of full DVD, bitrate can be half as much here with
# quality (per pixel) comparable to full DVD.

USAGE="Usage: tovid [vcd|svcd|dvd|half-dvd|dvd-vcd] [wide|full|panavision] <input file> <output prefix>"

if [ $# -ne 4 ]; then
  echo $USAGE
  exit 1
elif [[ $1 == "vcd" || $1 == "dvd-vcd" ]]; then
  # For VCD, use VCD sound profile of mp2enc
  if [[ $1 == "vcd" ]]; then
    VIDFMT="-f 1"
    MUXOPTS="-m v"
  # For VCD-on-DVD, use DVD-format audio
    SNDOPTS="-r 48000 -s"
    MUXOPTS="-m d"
elif [[ $1 == "svcd" ]]; then
  # -d for dummy SVCD scan offsets
  VIDFMT="-f 4 -d"
  MUXOPTS="-m s"
elif [[ $1 == "dvd" ]]; then
  SNDOPTS="-r 48000 -s"
  MUXOPTS="-m d"
elif [[ $1 == "half-dvd" ]]; then
  SNDOPTS="-r 48000 -s"
  MUXOPTS="-m d"
  echo $USAGE
  exit 1

if [[ $2 == "wide" ]]; then
elif [[ $2 == "full" ]]; then
elif [[ $2 == "panavision" ]]; then
  echo "$USAGE"
  exit 1


# Filtering options to use with mplayer
# pp=hb/vb/dr gives horizontal and vertical deblocking, plus deringing
# hqdn3d gives high quality denoising
VIDFILTER="-vf pp=hb/vb/dr,hqdn3d"
# VIDFILTER="-vf hqdn3d"

# Probe for width, height, and frame rate
mplayer -vo null -ao null -frames 0 -identify "$INFILE" 2>/dev/null | \
  grep "^ID_" > fileinfo
CURWIDTH=`grep 'ID_VIDEO_WIDTH' fileinfo | \
  sed -e 's/ID_VIDEO_WIDTH=//g'`
CURHEIGHT=`grep 'ID_VIDEO_HEIGHT' fileinfo | \
  sed -e 's/ID_VIDEO_HEIGHT=//g'`
CURFPS=`grep 'ID_VIDEO_FPS' fileinfo | \
  sed -e 's/ID_VIDEO_FPS=//g'`

echo "Input file is $CURWIDTH x $CURHEIGHT at $CURFPS fps."

# If FPS is already 29.97 (NTSC) or 23.976 (NTSC film), leave it alone
if [[ $CURFPS == "29.970" ]];
  echo "Source is 29.970 fps (NTSC). Encoding as NTSC video at 29.97 FPS."
  VIDFPS="-F 4"
elif [[ $CURFPS == "23.976" ]];
  echo "Source is 23.976 fps (NTSC film). Adjusting FPS to 29.97."
  ADJUSTFPS="yuvfps -s 24000:1001 -r 30000:1001 -v 0 |"
  VIDFPS="-F 4"
  echo "Source is not at an NTSC frame rate. Adjusting FPS to 29.97."
  ADJUSTFPS="yuvfps -r 30000:1001 -v 0 |"
  VIDFPS="-F 4"

# Set appropriate aspect ratio for output format
# Widescreen on DVD should be 16:9
[ $ASPECT == "WIDE" ] && [ $FORMAT == "DVD" ] && ASPECTFMT="-a 3"
# Panavision on DVD is encoded at 16:9 with letterboxing added
[ $ASPECT == "PANA" ] && [ $FORMAT == "DVD" ] && ASPECTFMT="-a 3"
# Widescreen on VCD/SVCD needs to be padded out to 4:3
[ $ASPECT == "WIDE" ] && [ $FORMAT != "DVD" ] && ASPECTFMT="-a 2"
# Standard (fullscreen) is always 4:3
[ $ASPECT == "FULL" ] && ASPECTFMT="-a 2"

# Estimate existing aspect ratio (integer math!)
# Tolerances for wide/full aspect ratio (+/- 10% of target)
if [[ $ASPECT == "WIDE" ]];

# Determine whether any rescaling needs to be done
# If resolution is already the same as the target, do not rescale.
  echo "Source is already at target resolution ($TGTWIDTH x $TGTHEIGHT)."
  echo "No rescaling will be applied."
# See if source is target resolution in PAL
# If so, just rescale; aspect ratio should be fine
  echo "Source appears to be PAL of target resolution ($TGTWIDTH x $PALHEIGHT)."
  echo "Assuming correct aspect ratio and rescaling."
  ADJSIZE="yuvscaler -O $FORMAT -v 0 -n n |"
  echo "Source is within 10% of target aspect ratio."
  echo "Assuming correct aspect ratio and rescaling."
  ADJSIZE="yuvscaler -O $FORMAT -v 0 -n n |"
# Otherwise, scale and/or pad with black bars
  echo "Scaling and/or padding with letterbox bars"
  # For non-DVD formats, widescreen needs to be padded to make
  # it fullscreen.
  if [ $FORMAT != "DVD" ] && [ $ASPECT == "WIDE" ]; then
    echo "Letterboxing widescreen aspect to fit in 4:3 aspect"
    ADJSIZE="yuvscaler -O $FORMAT -v 0 -n n -M WIDE2STD |"
  # Non-DVD standard sizes can be scaled directly
  elif [ $FORMAT != "DVD" ] && [ $ASPECT == "FULL" ]; then
    echo "Scaling full-screen aspect"
    ADJSIZE="yuvscaler -O $FORMAT -v 0 -n n |"
  # Non-panavision DVD can be scaled directly
  elif [ $ASPECT != "PANA" ] && [ $FORMAT == "DVD" ]; then
    "Scaling directly to DVD resolution"
    ADJSIZE="yuvscaler -O $FORMAT -v 0 -n n |"
  # Panavision (2.35:1) DVD must be padded within the 16:9 frame
  elif [ $ASPECT == "PANA" ] && [ $FORMAT == "DVD" ]; then
    echo "Letterboxing Panavision (2.35:1) aspect to fit DVD widescreen aspect"
    ADJSIZE="yuvscaler -O DVD -v 0 -n n |"
    VIDFILTER=`echo $VIDFILTER,scale=720:363,expand=720:480`

echo "Creating and encoding video stream..."
mkfifo stream.yuv
mplayer -nosound -noframedrop -vo yuv4mpeg $VIDFILTER "$INFILE" &
eval `echo "cat stream.yuv | $ADJUSTFPS $ADJSIZE nice -n 16 mpeg2enc $ASPECTFMT $VIDFMT $VIDFPS -v 0 -n n -H -o $OUTPREFIX.$SUF"`

echo "Creating WAV of audio stream..."
mplayer -vc dummy -vo null -ao pcm -aofile stream.wav "$INFILE"
# echo "Normalizing WAV audio..."
# normalize --amplitude=-14dBFS stream.wav
echo "Encoding WAV..."
cat stream.wav | mp2enc $SNDOPTS -o "$OUTPREFIX.mpa"

echo "Multiplexing audio and video together..."
tcmplex -i "$OUTPREFIX.$SUF" -p "$OUTPREFIX.mpa" -o "$OUTPREFIX.mpg" $MUXOPTS

echo "Cleaning up..."
rm stream.yuv
rm stream.wav
rm "$OUTPREFIX.mpa"
rm fileinfo

echo "Done"

wapcaplet 07-06-2004 02:28 PM

Rather than continue to clutter the forum with updates to this script, I thought I'd just direct your attention to the tovid homepage and tovid project summary page on Sourceforge. Patches and updates are welcome!

sbogus 07-08-2004 02:13 AM


Originally posted by wapcaplet
Rather than continue to clutter the forum with updates to this script, I thought I'd just direct your attention to the tovid homepage and tovid project summary page on Sourceforge. Patches and updates are welcome!
But the homesite and the download section does not work - I can't download the 0.1 version of the script&GUI. Am I doing smoething wrong or because the project is very new to SF, there's not yet mirrored files to download?

Kind regards,

wapcaplet 07-08-2004 04:56 AM


Originally posted by sbogus
But the homesite and the download section does not work - I can't download the 0.1 version of the script&GUI.
Dunno. Works OK for me! Could be a mirror problem, I suppose. Try again in a couple days.

sbogus 07-08-2004 05:57 AM

Okay, thanks wapcaplet,
now it worked with the download.

What version of mplayer do you use with the script? Because mine is 1.0.pre4[whatever] and keeps instantly crashing when the script tries to extract the audio from the AVI file. The file itself plays perfect in the player but extracting the audio does not work.
I've also played with the options, but could not manage to tell mplayer to extract the audio only using other options than the ones you've used in the script. But then again, it crashes with these options...

Thanks in advance.

Kind regards,

wapcaplet 07-08-2004 03:51 PM

My mplayer version is 1.0pre4-3.3.2. What error message do you get when it crashes? If it's just a segfault, I wouldn't know where to begin fixing it :) Does it crash with all video files, or just a specific format? AVI video can have a variety of different audio codecs along with it. If it's just a specific format, or a specific video file, you can find out the audio format by running:


mplayer -identify YourVideoFile
Look for the line that says "ID_AUDIO_CODEC" and also the line "ID_AUDIO_FORMAT". Let me know what they are.

sbogus 07-09-2004 04:32 AM

Thanks wapcaplet,
it segfaults (crashed with signal 11).

It crashes on each AVI file that has MP3 audio therein (XViD, DivX 5.x)) and unfortunately all my films&videos are either in XViD or in DivX 5.x format.

The MP3 audio stream is always in 44100 Hz frequency, the codec that is used to play the stream is "lame", but sometimes it uses also "MAD" for the playing. I don't know why...

Thanks for helping me continuously.

Kind regards,

wapcaplet 07-09-2004 08:05 PM

OK, until I figure out a different way to extract .wav from mplayer, try changing the line in the script:


mplayer -vc dummy -vo null -ao pcm -aofile stream.wav "$INFILE"
to this:


mplayer -vo null -ao pcm -aofile stream.wav "$INFILE"
(just remove the -vc dummy part - I'm not too sure about it anyway). If you want to just test it out without modifying the script, just run the above command manually, replacing $INFILE with the name of your AVI (you can leave out the quotes). Let me know if that works.

Since I am unable to get any of my AVIs to cause crashing, I'd like to use you as a guinea-pig for another little experiment, if you don't mind. Try this command:


mplayer -dumpaudio -dumpfile stream YourAVIFile
From what I can determine, this will just bulk-copy the audio portion to a separate file (called 'stream'). That file should be whatever format the audio itself was in (an mp3, in your case). To find out for sure, run this command:


file stream
If that works, then I am hoping you have sox installed, because it can convert a bunch of different formats. If you do, try this command (assuming it's mp3):


sox -t mp3 stream stream.wav
It might complain about not supporting 16-bit data, but it ought to do the conversion. If all of that works for you, then it may give me another option to work with for extracting the .wav output. (You can play the wav with 'play stream.wav', to make sure it sounds like your video.) Too bad sox can't convert directly to mp2 audio, since that's what it eventually needs to be! If any of the above doesn't work, let me know what part and what errors you get.

Another thing to try, if you haven't already, is upgrading mplayer and/or lame. Could just be a bug with one of those.

Thanks for all your feedback so far! You're my first beta-tester :)

sbogus 07-19-2004 03:23 AM

Hi wapcaplet,
sorry for the big delay - I've had many things to do so I didn't manage to take care about the AVI conversion until now.

Brief review of what I've done and what I got:


mplayer -vo null -ao pcm -aofile stream.wav "$INFILE"
works very well (although somehow strange as it *dumps* the audio, but with empty video frames - i.e. this is not only audio, but also contains empty video frames). For AVI file size of 700 MB it produces about 850MB WAV file.


mplayer -dumpaudio -dumpfile stream YourAVIFile
file stream
sox -t mp3 stream stream.wav

works also well, the resulting WAV file has about 500 MB file size. I'd say, the sound quality using the first *mplayer*-statement is much more better than the one from the latter conversion way, so I modified your tovid script in order to incorporate the statement that works for me.
Now the script does not break, nor it segfaults anymore and it produces realy good high quality MPEG-video. I still have some problems with the conversion types and the most important thing is what to do with the resulting MPEG file?!?

What I mean is following:
My AVI file has the panavision aspect (2.35 : 1) and your script does the conversion wery well if I specify mode dvd with panavision screen format only. Other combinations result in 4:3 sqeezed picture, wish looks very bad.

Can you tell me how can I *melt* together several AVIs to burn them on one DVD-R disk? From the several AVIs I get exact the same number MPGs, but my K3b application does not create automaticaly the needed DVD structure from them, so what is supposed to be done for these MPGs prior to put them in a K3b burn project?

Many thanks in advance.

Kind regards,

wapcaplet 07-19-2004 01:31 PM

Unfortunately, k3b does not seem to support DVD video authoring at this time; that is, it can't create the file structure needed for the DVD to play in a regular DVD player. For that you'll need dvdauthor, which I'm afraid is not the easiest thing in the world to use. I've found a few good tutorials that should get you through some of it:

If you end up with several mpeg video files that are supposed to be part of a single video (like a movie in three pieces), you can re-assemble them when you author the DVD, and insert chapter breaks in between them. dvdauthor is quite powerful, but it involves a lot of editing of XML files to lay out the DVD how you want it. I don't know of anything else that works in Linux at this time; I haven't even been able to find decent (free) Windows software to do this! Someday I may write a small utility for that, too, but at this time I'm afraid you're on your own.

Thanks for your feedback and testing! I'm glad you got the script to work to your liking. If you don't mind, email me a copy of the changes you made (use the 'email' link at the bottom of my post) so I can improve the script.

sbogus 07-21-2004 02:53 AM

Hi wapcaplet,
I'm sorry - I do not see any e-mail address in your post.

Since the change in the script is in one single place only, I guess it's enough if I post here the modified line in your script.

mplayer -vo null -ao pcm -aofile stream.wav "$INFILE"
You should just remove the -vc dummy part of the call to mplayer when dumping the audio.
When I do have enough time to play with the script I'll do some additional testing using different input parameters and I let you know what the results are.

Many thanks for your help.

Kind regards,

koy 07-29-2004 11:07 AM

Nice script u made there, simple but effective :D

I tested it and it took bout 5 hours for a 700mb xvid file @23fps to DVD. Which is bout the same time it took me on windows with a professional program ;) And it was actually in sync and quality wasn't too bad either :)

Here's something that would be a nice addition though:

*You mentioned that it will only encode to NTSC, a PAL option would be nice though; especially with my TV only supporting PAL ;p

Here some useless suggestions :p :

*dvdauthor support, so that it authors the mpeg2 file after it's finished for you :) Not necessary but a nice lil addon :)

*and while ur at it, add mkisofs so that it creates an .iso file ready to be burned :p

*Maybe an integrated bitrate caclulator, would be a bit fiddly to make I guess..

All times are GMT -5. The time now is 05:13 AM.