LinuxAnswers DiscussionThis forum is to discuss articles posted to LinuxAnswers.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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!
Distribution: SuSE Pro Releases 7.3, 9.0, CentOS 4.0, Kubuntu 6.0x
Posts: 103
Rep:
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: MyDivXFilm.srt
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?
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:
Code:
# rm "$OUTPREFIX.$SUF"
# 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.
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.
Todo:
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!
Code:
#!/bin/bash
# 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
DVD_BITRATE="7500"
# 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.
HALF_D1_BITRATE="3600"
QUARTER_D1_BITRATE=$(($HALF_D1_BITRATE / 2))
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
TGTWIDTH="352"
TGTHEIGHT="240"
PALHEIGHT="288"
# For VCD, use VCD sound profile of mp2enc
if [[ $1 == "vcd" ]]; then
FORMAT="VCD"
VIDFMT="-f 1"
SNDOPTS="-V"
MUXOPTS="-m v"
SUF="m1v"
# For VCD-on-DVD, use DVD-format audio
else
FORMAT="SIZE_352x240"
VIDFMT="-f 8 -b $QUARTER_D1_BITRATE"
SNDOPTS="-r 48000 -s"
MUXOPTS="-m d"
SUF="m2v"
fi
elif [[ $1 == "svcd" ]]; then
TGTWIDTH="480"
TGTHEIGHT="480"
PALHEIGHT="576"
FORMAT="SVCD"
# -d for dummy SVCD scan offsets
VIDFMT="-f 4 -d"
SNDOPTS="-V"
MUXOPTS="-m s"
SUF="m2v"
elif [[ $1 == "dvd" ]]; then
TGTWIDTH="720"
TGTHEIGHT="480"
PALHEIGHT="576"
FORMAT="DVD"
VIDFMT="-f 8 -b $DVD_BITRATE"
SNDOPTS="-r 48000 -s"
MUXOPTS="-m d"
SUF="m2v"
elif [[ $1 == "half-dvd" ]]; then
TGTWIDTH="352"
TGTHEIGHT="480"
PALHEIGHT="576"
FORMAT="SIZE_352x480"
VIDFMT="-f 8 -b $HALF_D1_BITRATE"
SNDOPTS="-r 48000 -s"
MUXOPTS="-m d"
SUF="m2v"
else
echo $USAGE
exit 1
fi
if [[ $2 == "wide" ]]; then
ASPECT="WIDE"
elif [[ $2 == "full" ]]; then
ASPECT="FULL"
elif [[ $2 == "panavision" ]]; then
ASPECT="PANA"
else
echo "$USAGE"
exit 1
fi
INFILE=$3
OUTPREFIX=$4
# 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" ]];
then
echo "Source is 29.970 fps (NTSC). Encoding as NTSC video at 29.97 FPS."
ADJUSTFPS=""
VIDFPS="-F 4"
elif [[ $CURFPS == "23.976" ]];
then
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"
else
echo "Source is not at an NTSC frame rate. Adjusting FPS to 29.97."
ADJUSTFPS="yuvfps -r 30000:1001 -v 0 |"
VIDFPS="-F 4"
fi
# 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!)
ESTASPECT=$(($CURWIDTH * 100 / $CURHEIGHT))
# Tolerances for wide/full aspect ratio (+/- 10% of target)
if [[ $ASPECT == "WIDE" ]];
then
MINASPECT=160
MAXASPECT=195
else
MINASPECT=120
MAXASPECT=147
fi
# Determine whether any rescaling needs to be done
# If resolution is already the same as the target, do not rescale.
if [[ $CURWIDTH == $TGTWIDTH && $CURHEIGHT == $TGTHEIGHT ]];
then
echo "Source is already at target resolution ($TGTWIDTH x $TGTHEIGHT)."
echo "No rescaling will be applied."
ADJSIZE=""
# See if source is target resolution in PAL
# If so, just rescale; aspect ratio should be fine
elif [[ $CURWIDTH == $TGTWIDTH && $CURHEIGHT == $PALHEIGHT ]];
then
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 |"
elif [[ $ESTASPECT -ge $MINASPECT && $ESTASPECT -le $MAXASPECT ]];
then
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
else
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`
fi
fi
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.$SUF"
rm "$OUTPREFIX.mpa"
rm fileinfo
echo "Done"
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!
Distribution: SuSE Pro Releases 7.3, 9.0, CentOS 4.0, Kubuntu 6.0x
Posts: 103
Rep:
Quote:
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!
Great!
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?
Distribution: SuSE Pro Releases 7.3, 9.0, CentOS 4.0, Kubuntu 6.0x
Posts: 103
Rep:
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...
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:
Code:
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.
Distribution: SuSE Pro Releases 7.3, 9.0, CentOS 4.0, Kubuntu 6.0x
Posts: 103
Rep:
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...
(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:
Code:
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:
Code:
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):
Code:
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
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.
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?
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.
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.
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 :
*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
*Maybe an integrated bitrate caclulator, would be a bit fiddly to make I guess..
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.