LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-30-2004, 07:29 AM   #1
Maverick1182
Member
 
Registered: Aug 2004
Location: London
Distribution: Gentoo
Posts: 277

Rep: Reputation: 30
Divx to VCD script


I've searched on LW for a good howto encode a divx file to VCD to then burn onto CD. I have come across several solutions , mainly making a script file consisting of the following:

!/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

USAGE="Usage: tovid [vcd|svcd|dvd|dvd-vcd] [wide|full] <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"
FORMAT="VCD"
VIDFMT="-f 1"
# For VCD, use VCD sound profile of mp2enc
if [[ $1 == "vcd" ]]; then
SNDOPTS="-V"
# For VCD-on-DVD, use DVD-format audio
else
SNDOPTS="-r 48000 -s"
fi
MUXOPTS="-m v"
SUF="m1v"
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"
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"
else
echo "$USAGE"
exit 1
fi

INFILE=$3
OUTPREFIX=$4

# Probe for width, height, and frame rate
tcprobe -i "$INFILE" > fileinfo
CURWIDTH=`grep 'import frame size' fileinfo | \
perl -e ' $line=<STDIN> ; $line =~ /import frame size: -g (\d+?)x\d+ / ; print $1' `
CURHEIGHT=`grep 'import frame size' fileinfo | \
perl -e ' $line=<STDIN> ; $line =~ /import frame size: -g \d+?x(\d+) / ; print $1' `
CURFPS=`grep 'frame rate' fileinfo | \
perl -e ' $line=<STDIN> ; $line =~ /frame rate: -f (.+?) \[/ ; print $1' `

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."
ADJUSTFPS=""
VIDFPS="-F 4"
elif [[ $CURFPS == "23.976" ]];
then
echo "Source is 23.976 fps (NTSC film). Encoding as NTSC film."
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."
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"
# 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.
[ $FORMAT != "DVD" ] && [ $ASPECT == "WIDE" ] && \
ADJSIZE="yuvscaler -O $FORMAT -v 0 -n n -M WIDE2STD |"
# Non-DVD standard sizes can be scaled directly
[ $FORMAT != "DVD" ] && [ $ASPECT == "FULL" ] && \
ADJSIZE="yuvscaler -O $FORMAT -v 0 -n n |"
# DVD can be scaled directly
[ $FORMAT == "DVD" ] && \
ADJSIZE="yuvscaler -O $FORMAT -v 0 -n n |"
fi

echo "Creating and encoding video stream..."
mkfifo stream.yuv
mplayer -nosound -noframedrop -vo yuv4mpeg -vf pp=hb/vb/dr,hqdn3d "$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"




Problem is that i've doen this and changed it to a shell script, but i cant run it...... it keeps saying command not found!

Can anyone help me by either suggesting what i need to do to get this script to work or suggesting an alternative on how to convert Divx to VCD?
 
Old 08-30-2004, 07:33 AM   #2
Baldrick65
Member
 
Registered: Aug 2003
Location: Dunedin NZ
Distribution: Mint 13 Cinnamon
Posts: 653

Rep: Reputation: 31
Quote:
!/bin/bash
Should be
Code:
#!/bin/bash
Baldrick
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
xine: vcd eject button pressed BUT still VCD does not goes out.. ic_torres Linux - Hardware 2 12-02-2005 02:03 AM
Vcd cholombeh Slackware 3 08-14-2004 06:48 AM
Whats a good mpeg, vcd, divX player lhiggins Linux - Newbie 13 06-26-2003 08:37 AM
Encoding divx to vcd using mencvcd or transcode or divx2vcd... GnomeKing Linux - Software 5 06-23-2003 01:44 PM
Any distro:DiVX Linux version:DivX codec compatible player? sewer_monkey Linux - Software 16 05-19-2002 07:03 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:23 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration