Mailing List archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[vdr] Re: script to convert multiple *vdr to cd-sized *avi



ok, here we go again...

i've manipulatet the skript something, so you can define, how many cd's the movie will need.
all your preferred setting are made in header of skript, but for myself I like these settings ;o)

i've you like restrict the movie-size to one only cd, you can uncomment the lines at the end of file --then you only have to write the moviename on cd manually ;o)
in the evening i will put this skript at my homepage, so posting on mailing-lists is obsolete.

best regards,
Andreas Reichel



#!/bin/bash
#-------------------------------------------------------------------------------------------------------------
# command:	"/usr/local/bin/vdr2avi.sh 16:9" OR "/usr/local/bin/vdr2avi.sh 4:3" in 
#		path of movie files (something like /video/${MOVIENAME}/${TIMECODE}/)
# author:	Andreas Reichel 
# email: 	andreas.reichel@i-kit.de
# url:		http://www.i-kit.de
#-------------------------------------------------------------------------------------------------------------
#
# simple bash-script to transcode multiple *.vdr files to cd-sized avi-files in mpeg4-format
# use it, to convert videos recorded from dvb-cards
# use it for free, but please send me copies of modifications 
#-------------------------------------------------------------------------------------------------------------
# simple howto:
#
# 1) record the movie using vdr [1] and the linux-dvb-drivers [2]
# 2) cut the movie using vdr [1]
# 3) run this skript to convert the pva-pes formatted movie-files to ps-formated mpegII-files using 
#    pvastrumento [3] and wine [4]
# 4) run this skript in directory of movie-files to transcode [5]  
# 5) optional: burn the avi-files to cdrom
#-------------------------------------------------------------------------------------------------------------
# sources and references:
# [1] http://www.cadsoft.de/people/kls/vdr/download.htm
# [2] http://www.linuxdvb.tv/download/
# [3] http://www.offeryn.de/dv.htm
# [4] http://www.winehq.org/download.shtml
# [5] http://www.theorie.physik.uni-goettingen.de/~ostreich/transcode/#download
#-------------------------------------------------------------------------------------------------------------

EXT="vdr"				
NICELEVEL=10				# run it in background
RM_TMP_FILES=1				# set it "1" if instant removing of obsolete temporary files wanted
					# to save disk space
					# set it "0" to safe transcoding without deleting temporary files

AF=""					# initialise empty, will hold concanated filesnames later
FULLFRAMES=0

CODEC="mpeg2"				# input-codec
OUT_MCODEC="xvid"			# xvid|divx|opendivx
MBITRATE="1400,1000,100" 		# bitrate, key-frames, crispness
RES169="640x360"
RES43="640x480"

ABITRATE="128"				# vbr using lame seems to bee broken
CDSIZE="700"				# use 700mb splitting
CDCOUNT="2"				# use 1 cdroms, set 0 to disable this feature

WINE=`which wine`			# path to wine
TRANSCODE=`which transcode`		# path to transcode
CPVAS='/usr/local/bin/cPVAS.exe'	# path to cPVAS.exe

case "${1}" in
	"16:9")	Y=80
		RES=${RES169}
		;;
	"4:3")	Y=0
		RES=${RES43}
		;;
	"42:19")
		Y=80
		RES=${RES169}
		;;
	"1:1")
		Y=0
		RES=${RES169}
		;;
	*)	echo "Usage: /usr/local/bin/mpeg2avi.sh 16:9|4:3|2.21:1|1:1"
		exit 1
		;;
esac

# test, if all needed programs are found
if test -z ${WINE}
then
	echo "Error: Wine not found in PATH"
	exit 1
fi
if test -z ${TRANSCODE}
then 
	echo "Error: Wine not found in PATH"
	exit 1
fi
if test ! -s ${CPVAS}
then
	echo "Error: cPVAS.exe not found" 
	exit 1	
fi

# demux the pva-pes files and save information in log-files
for F in `ls *.${EXT}`
do
	FN=`basename ${F} .${EXT}`
	
	if `test $[${FN}] -gt 0`
	then
		
		#demux video, first create job-file
		echo -e "offeryn pvas job v002016 # DO NOT DELETE THIS LINE\n\044JOB\ndemux ${FN}.${EXT} ${FN}.mpv ${FN}.mpa\naudio 1\nvideo 1\n\044PARMS\nloglevel 2\nfixstart 1\nsync 1\ndropgop 1\ndropwronggop 1\nstrongaudio 1\nshortscan 0\nscanseq 200\nsetbr 1\nsetvbr 1\nsetavg 1\nadjusttc 1\npacksize 0\nsplitsize 0\noverlap 1\nspliteven 0\nsplitaudioFMT 1\ngoppts 1" > ${FN}.ajb
		chmod 0644 ${FN}.ajb
		nice -n ${NICELEVEL} ${WINE} -- ${CPVAS} ${FN}.ajb > ${FN}.log
		test $? -ne 0 && (echo "ERROR: ${F}, demuxing"; exit 1)
		test ${RM_TMP_FILES} -gt 0 && rm -f ${FN}.${EXT}
		#get video-frames in movie
		FRAMES=`awk '/^Video:[ 0123456789.]+/ {match($0,/[0123456789.]+/); print substr($0,RSTART,RLENGTH)}' ${FN}.log`
		FULLFRAMES=$((${FULLFRAMES}+${FRAMES}))
	fi
done

#overwrite bitrate if number of cdroms defined
if `test $[${CDSIZE}] -gt 0`
then
	BITRATE=$(( ${CDSIZE} * ${CDCOUNT} * 204800 / ${FULLFRAMES} ))
	MBITRATE=$(( ${BITRATE} - ${ABITRATE} ))
	echo "calculated bitrate:" ${MBITRATE} "kbit/sec"
fi
	
for F in `ls *.mpv`
do
	FN=`basename ${F} .mpv`
	
	if `test $[${FN}] -gt 0`
	then
		
		#get video-frames in movie
		FRAMES=`awk '/^Video:[ 0123456789.]+/ {match($0,/[0123456789.]+/); print substr($0,RSTART,RLENGTH)}' ${FN}.log`
		test ${RM_TMP_FILES} -gt 0 && rm -f ${FN}.ajb
	
		#first loop, get vbr-settings and the -s option from astat-plugin
		NORMALIZE=`nice -n ${NICELEVEL} transcode -x ${CODEC} -y ${OUT_MCODEC} -i ${FN}.mpv -p ${FN}.mpa  -R 1 -O -V -M 2 -c 0-${FRAMES} -w ${MBITRATE} -j ${Y},0,${Y},0 -Z ${RES} -J astat -b ${ABITRATE} | awk '/-s[ 0123456789.]/ {match($0,/-s [0123456789.]+/); print substr($0,RSTART,RLENGTH)}'`
		test $? -ne 0 && (echo "ERROR: ${F}, first loop"; exit 1)
	
		#second loop, make the movie using the calculated settings
		nice -n ${NICELEVEL} transcode -x ${CODEC} -y ${OUT_MCODEC} -i ${FN}.mpv -p ${FN}.mpa  -o ${FN}.avi -R 2 -O -V -M 2 -c 0-${FRAMES} -w ${MBITRATE} -j ${Y},0,${Y},0 -Z ${RES} -b ${ABITRATE} ${NORMALIZE}
		test $? -ne 0 && (echo "ERROR: ${F}, second loop"; exit 1)
		
		test ${RM_TMP_FILES} -gt 0 && rm -f ${FN}.mpv ${FN}.mpa		# remove temp-files
		AF="${AF} ${FN}.avi"						# concanate filenames	
	fi
done

#get name of parent-dir as moviename
DIRNAME=`(cd ..; pwd)`
TOP_DIRNAME=`(cd ../.. ; pwd)`
MOVIENAME=`basename ${DIRNAME} ${TOP_DIRNAME}`

# merge avifiles and remove them
avimerge -i ${AF} -o ${MOVIENAME}.avi
#test $? -eq 0 && exit 1
test ${RM_TMP_FILES} -gt 0 && rm -f ${AF}

#split in cd-sized chunks and clean up
avisplit -i ${MOVIENAME}.avi -o ${MOVIENAME} -s ${CDSIZE}
test ${RM_TMP_FILES} -gt 0 && rm -f ${MOVIENAME}.avi *.log

#burn the movie on cd, please manipulate the device-settings
#if $[${CDCOUNT}] -eq 1
#then
#	mkisofs -R *.avi | cdrecord -v fs=6m -eject speed=4 dev=0,0,0 -	
#fi

exit 0		


-- 
 _________________________________________________________________________

 Andreas Reichel                                 +49 0174-3262-499  :Phone
 Hasenweg 2c                              andreas.reichel@i-kit.de  :Email
 D-04463 Grosspoesna, Germany                         www.i-kit.de  :HTTP
 _________________________________________________________________________


-- No attachments (even text) are allowed --
-- Type: application/pgp-signature




Home | Main Index | Thread Index