Hello,
Here's a script I've been developing while converting VHS onto DVD-Rs.
The primarily goal of the script is to handle the repeating flags. It
has saved me a lot of cutting and pasting. It has also reduced the
number of off-air recordings that are lost due to typos.
It handles videos in three stages. Stage 1, recording, is done with
lavrec & quicktime, with an an oversized window to be trimmed later.
Stage 2, editing, is still done manually if it is needed. The script
can be set to use chapters (local files ch01.eli, ch02.eli,..), a single
editlist (sometitle.eli), or just to transcode the whole recording.
Stage 3, post-processing, includes croping, kinecoing, filtering, and
encoding.
Any suggestions for making this script more usefull will be apprecieted,
as suggestions for new features.
-James
#!/bin/sh
#------------------------------------------------------------------------------
#
# rec_movie rev 3.4
#
# By James M. Ogg
#
#------------------------------------------------------------------------------
#
# This script uses sox and the excellent Mjpeg Square LAV tools. It's
# primary role is to handle the repeating flags, saving a lot of cutting
# and pasting.
#
# It handles movies in up to three stages. Stage 1, recording, is done with
# an oversized window to be trimmed later. Stage 2, editing, is still done
# manually. Glav is used to create either one or more editlists. Stage 3,
# post-processing, includes croping, kinecoing, filtering, and encoding.
#
# You will also need v4lctl, which usually comes with xawtv.
# Stage: Uncomment one REC...
REC="TRUE";TC=0 # Stage 1: just record
#REC="TRUE";TC=1 # Stage 1 & 3: recored and transcode the whole thing
#REC="FALSE";TC=2 # Stage 3: just transcode based on chapters,
#defined by editlists ch01.eli,...
# ch01.eli will go to ch01.mpg, etc.
#REC="FALSE";TC=3 # Stage 3: just transcode by a specified edit list
# usefull for archiving short subjects.
#-------------------------------------------------------------------------------
# SHOW SETTINGS
#-------------------------------------------------------------------------------
# Recording source: Uncomment one RECSRC...
#set for your card's tuner. Mine gets it's TV tuner through what should be the composite input.
#RECSRC="-i n -C us-cable:9"
#set for your card's composite in. Mine gets it's composite in through what should be the S-Video in.
RECSRC="-i N"
DUR=16000
QTFILE="/Video/Current/drama1.qt"
#paste your channels in here for easy reference
#9=kqed, 10=kteh, 32=arts, 36=fx, 37=tnt, 41=tbs, 42=usa, 43=mtv
#44=vh1 45=tnn, 46=life, 49=amc, 52=abcfam,53=nic
#54=toon, 55=dis, 63=com, 66=Halmark
# Durration is in seconds: 90min= 5400 2 hrs=7200 3 hrs = 10800 4 hrs = 14400 5 hrs = 18000
#-------------------------------------------------------------------------------
# VIDEO RESOLUTION
#-------------------------------------------------------------------------------
# RES is the recording resolution
# SCALE_HOR sets video size and clears most of the noise
# SCALE_VER blackens small patches of noise and filters random noise
# You will need to modify SCALE_HOR if you record and transcode
# with different resolution modes, and can use SCALE_VER to get
# rid of remaining noise around the borders
#
# Uncomment one RES...
# SVCD-ish modes. 480x480 output compatible with a software decoder such as xine.
# The quicktime file will be about 20 Gig per hour, and transcode down so that 4 or 6 hours
# will fit on a DVD-R. Transcoding takes about 6 hours per hour on a 1.5 GHz Athalon.
# very clean 4:3/normal, for software player
#RES="-g 512x480 -q 100"; SCALE_HOR="yuvscaler -I USE_480x480+16+0 -O SVCD -n n -v 0"; SCALE_VER="yuvdenoise"; MPEGENC="mpeg2enc -v 0 -f 8 -d -q 8 -b 2400 -V 526 -4 2 -2 1 -r 24 -g 6 -G 32 -a 2 -I 0"; MPLEX="mplex -f 8 -b 300 -r 2750"
# mildly noisy 4:3/normal, for software player
RES="-g 512x480 -q 98"; SCALE_HOR="yuvscaler -I USE_480x480+16+0 -O SVCD -n n -v 0"; SCALE_VER="yuvdenoise -b 0,0,480,472"; MPEGENC="mpeg2enc -v 0 -f 8 -d -q 10 -b 2400 -V 526 -4 2 -2 1 -r 24 -g 6 -G 32 -a 2 -I 0"; MPLEX="mplex -f 8 -b 300 -r 2750"
# mildly noisy 4:3/normal with extra side margins, may be needed for VHS tapes, for software player
#RES="-g 544x480 -q 98"; SCALE_HOR="yuvscaler -I USE_480x480+32+0 -O SVCD -n n -v 0"; SCALE_VER="yuvdenoise -b 0,0,480,472"; MPEGENC="mpeg2enc -v 0 -f 8 -d -q 10 -b 2400 -V 526 -4 2 -2 1 -r 24 -g 6 -G 32 -a 2 -I 0"
#Letterbox modes...
# mildly noisy 16:9/letterbox, quasi-DVD, note that this gives about the same final size, but
# should take advantage of a 16:9 display.
#RES="-g 544x480 -q 98"; SCALE_HOR="yuvscaler -I USE_512x288+16+96 -O SIZE_512x288 -n n -v 0"; SCALE_VER="yuvdenoise"; MPEGENC="mpeg2enc -v 0 -f 8 -d -q 8 -b 2400 -V 526 -4 2 -2 1 -r 24 -g 6 -G 32 -a 3 -I 0"; MPLEX="mplex -f 8 -b 300 -r 2750"
# in case you didn't know a movie was letterbox when you recorded it, transcode it with this setting.
# 16+488+8 wide
#RES="-g 512x480 -q 98"; SCALE_HOR="yuvscaler -I USE_512x288+0+96 -O SIZE_512x288 -n n -v 0"; SCALE_VER="yuvdenoise -b 16,0,488,288"; MPEGENC="mpeg2enc -v 0 -f 8 -d -q 8 -b 2400 -V 526 -4 2 -2 1 -r 24 -g 6 -G 32 -a 3 -I 0"; MPLEX="mplex -f 8 -b 300 -r 2750"
# D2/VCD-ish modes. 320x240 output compatible with a software decoder such as xine.
# The quicktime file will be about 10 Gig per hour, and transcode down so that 6 or 8 hours
# will fit on a DVD-R. Transcoding takes about 3 hours per hour on a 1.5 GHz Athalon.
# 4:3/normal, 336x240 is trimmed to 320x240, 8-320-8, VBR MPEG1. Resolution is comparable
# to VCD. Maybe up to 8 hrs per DVD-R
#RES="-g 336x240 -q 100"; SCALE_HOR="yuvscaler -I USE_320x240+8+0 -O SIZE_320x240 -n n -v 0"; SCALE_VER="yuvdenoise"; MPEGENC="mpeg2enc -v 0 -f 0 -q 8 -b 2000 -V 526 -4 2 -2 1 -r 24 -g 6 -G 32 -I 0 -a 2"; MPLEX="mplex -f 0 -V -b 220 -r 2500"
#-------------------------------------------------------------------------------
# SOUND RESOLUTION & FILTERS
#-------------------------------------------------------------------------------
# Uncomment one SOUND...
#SOUND="-l -1 -a 16 -s"; MP2ENC="mp2enc -s -b 192 -o" # stereo form tv, need to manually set line 1 - recsource, line 1, unmute input gain
#SOUND="-l -1 -a 16 -m";MP2ENC="mp2enc -m -b 128 -o" #mono form tv, need to manually set line 1 - recsource, line 1, unmute input gain
SOUND="-R l -l 85 -a 16 -m"; MP2ENC="mp2enc -m -b 128 -o" # mono from vcr, need to manually unmute input gain
#To strip off either high or low fequency noise, Uncomment one SOXFILTER
SOXFILTER="cat";OFFSET=0 # leave as is
#SOXFILTER="sox -t wav - -t wav - highpass 250";OFFSET=-250 # trim low frequencies
#SOXFILTER="sox -t wav - -t wav - lowpass 1800";OFFSET=-250 # trim high frequencies
#SOXFILTER="sox -t wav - -t wav - lowpass 2200";OFFSET=-250 # leave mostly as-is, trimming very high frequencies
#-------------------------------------------------------------------------------
# OTHER SETTINGS
#-------------------------------------------------------------------------------
# change max-file-size to slightly under the space you have, in Meg.
#BUFFS="--file-flush 0 -n 32 -b 1024 --max-file-size 85000 " # To monitor counters in real time
BUFFS="--file-flush 0 -n 32 -b 1024 --max-file-size 85000 -B" # to just see the summary
#BUFFS=" -n 32 -b 1024 --max-file-size 85000 -B" #more forgiving if resources are shared and resolution is low
#KINECO to convert movies from 30 fps to 24 fps
KINECO="yuvkineco -F 1" #for movies
#KINECO="cat" #for TV shows
#------------------------------------------------------------------
# RECORDING
#------------------------------------------------------------------
if [ $REC = TRUE ]
then
echo "starting to record"
# set & reset bttv as needed here. lavrec may mute
# one or both audio channels when it is done. When in
# doubt, comment out.
/usr/local/bin/v4lctl volume 85% # may be in /usr/bin/v4lctl
/sbin/rmmod bttv
# kill some programs that might interefer with recording...
killall -9 artsd
killall -9 top
# My twin Seagates take two minutes to get up to
# speed, this helps. Your disks may differ.
#umount /Video
#mount -t ext2 -o check=sync,check=none /dev/md0 /Video
#/sbin/hdparm -Z /dev/hda
#/sbin/hdparm -Z /dev/hdb
# the actual recording... lavrec may be in /usr/bin/v4lctl
/usr/bin/nice -18 /usr/local/bin/lavrec $RECSRC --software-encoding $RES -t $DUR $SOUND $BUFFS $QTFILE
# try to unmute again afterwards...
/usr/local/bin/v4lctl volume 85%
fi
#-------------------------------------------------------------------------------
# TRANSCODING
#-------------------------------------------------------------------------------
#to simply encode the whole movie...
if [ $TC = 1 ]
then
echo "encoding whole file"
lav2yuv $QTFILE | $KINECO | $SCALE_HOR | $SCALE_VER | $MPEGENC -o video.m2v
lav2wav $QTFILE | $SOXFILTER | $MP2ENC sound.mp2
$MPLEX -O $OFFSET sound.mp2 video.m2v -o $QTFILE.mpg
fi
#to simply encode the movie by edit lists...
if [ $TC = 2 ]
then
echo "encoding movie by chapters"
#comment out extra chapters if the error messages bother you
lav2yuv ch01.eli | $KINECO | $SCALE_HOR | $SCALE_VER | $MPEGENC -o video1.m2v
lav2wav ch01.eli | $SOXFILTER | $MP2ENC sound1.mp2
$MPLEX -O $OFFSET sound1.mp2 video1.m2v -o ch01.mpg
lav2yuv ch02.eli | $KINECO | $SCALE_HOR | $SCALE_VER | $MPEGENC -o video2.m2v
lav2wav ch02.eli | $SOXFILTER |$MP2ENC sound2.mp2
$MPLEX -O $OFFSET sound2.mp2 video2.m2v -o ch02.mpg
lav2yuv ch03.eli | $KINECO | $SCALE_HOR | $SCALE_VER | $MPEGENC -o video3.m2v
lav2wav ch03.eli | $SOXFILTER |$MP2ENC sound3.mp2
$MPLEX -O $OFFSET sound3.mp2 video3.m2v -o ch03.mpg
lav2yuv ch04.eli | $KINECO | $SCALE_HOR | $SCALE_VER | $MPEGENC -o video4.m2v
lav2wav ch04.eli | $SOXFILTER |$MP2ENC sound4.mp2
$MPLEX -O $OFFSET sound4.mp2 video4.m2v -o ch04.mpg
#lav2yuv ch05.eli | $KINECO | $SCALE_HOR | $SCALE_VER | $MPEGENC -o video5.m2v
#lav2wav ch05.eli | $SOXFILTER |$MP2ENC sound5.mp2
#$MPLEX -O $OFFSET sound5.mp2 video5.m2v -o ch05.mpg
#lav2yuv sample.eli | $KINECO | $SCALE_HOR | $SCALE_VER | $MPEGENC -o video4.m2v
#lav2wav sample.eli | $SOXFILTER |$MP2ENC sound4.mp2
$MPLEX -O $OFFSET sound4.mp2 video4.m2v -o sample.mpg
fi
if [ $TC = 3 ]
then
echo "encoding to single edited files"
ELI1="sagwa_colors" #the name of an existing local editlist, without the suffix
lav2yuv $ELI1.eli | $KINECO | $SCALE_HOR | $SCALE_VER | $MPEGENC -o video1.m2v
lav2wav $ELI1.eli | $SOXFILTER |$MP2ENC sound1.mp2
$MPLEX -O $OFFSET sound1.mp2 video1.m2v -o $ELI1.mpg
fi