mpgs via mkdvd komprimieren

Digital Recording
sir-zock-a-lot
Einsteiger
Einsteiger
Beiträge: 131
Registriert: Mittwoch 15. Oktober 2003, 16:33

mpgs via mkdvd komprimieren

Beitrag von sir-zock-a-lot »

Hallo,

ich fand diesen link recht spannend und habe mich gefragt, ob man das irgendwie mit "mkdvd" verheiraten kann :

http://www.heise.de/newsticker/data/vza-25.09.03-000/

"requant" ist also durch erweiterte Magie in der Lage in hoher Geschwindigkeit ein mpg zu komprimieren. Um das mit mkdvd zu kombinieren tue ich folgendes :

Voraussetzung sind mplayer, tcmplex und requant.

- man kompiliert requant (#undef DEMO nicht vergessen;)

- das von mkdvd erzeugte vob wird anhand "mplayer" in video- und audio geteilt:

Code: Alles auswählen

mplayer -vo null -dumpaudio -dumpfile aufnahme.mp2 VTS_01_1.VOB

Code: Alles auswählen

mplayer -vo null -dumpvideo -dumpfile aufnahme.m2v VTS_01_1.VOB
- dann wird die video-datei komprimiert :

Code: Alles auswählen

cat aufnahme.m2v | requant 1.25 > aufnahme_req.m2v
- anschliessend wird die Aufnahme wieder gemuxt :

Code: Alles auswählen

tcmplex -m 2 -i aufnahme_req.m2v -p aufnahme.mp2 -o aufnahme.mpg
Um das nicht jedes mal von Hand machen zu muessen, habe ich mir ein Skript geschrieben. Das heisst bei mir "custom_udrec.sh" und wird indirekt via "sserver" und "script.udrec" aufgerufen. "script.udrec" tut eigentlich nur das hier :

Code: Alles auswählen

#!/bin/bash
./custom_udrec.sh $1 &
exit 0
custom_udrec.sh:

Code: Alles auswählen

#!/bin/bash
#
# my sserver-options:
#
# the binary: 
#	./sserver \
#
# path where "sserver" stores "stream".v0, "stream".a0, "stream".a1 usw.
# 	-o /free/media/movies/dbox/mkdvd_tmp/ \
#
# your dbox-ip
# 	-host 192.168.0.5 \
#
# your linux-box
# 	-ip 192.168.0.100 \
# 
# executing <this> script when finished, "./script" expands to "./script.udrec"
# 	-script ./script \
#
# using engine:
# 	-udrec
#
#################################################################
# 
# my ./script.udrec:
# #!/bin/bash
# ./custom_udrec.sh $1 &
#
##################################################################
# <config> 

# modes : avi,mpg,vob,img
MODE=mpg

# installation-path of "mkdvd"
MKDVD_BASE_DIR="/opt/mkdvd-0.06"

# change this to your prefered movie-dir. target-file is stored here.
MOVIE_DIR="/free/media/movies/dbox"

# where "sserver" stores "stream".v0, "stream".a0, "stream".a1 usw.
# (check ./sserver -o <path> <options>)
MKDVD_TMP_DIR="/free/media/movies/dbox/mkdvd_tmp"

### mpg-options ###
# 0: no compression
# 1: compress mpg (requant is needed)
# more information :
# http://www.heise.de/newsticker/data/vza-25.09.03-000/
MPG_COMPRESSION="0"
REQUANT="${MKDVD_BASE_DIR}/requant"
REQUANT_OPTS="1.25" # 1.5

TCMPLEX="nice -+19 /usr/bin/tcmplex"

### divx-options ###
# mencoder-options (using 2pass-encoding) / leave this, if unsure !
MENCODER="nice -+19 /usr/bin/mencoder"
MPLAYER="/usr/bin/mplayer"
#
# first pass
AUDIO_OPTS="-oac copy"
VIDEO_OPTS="-ovc lavc -lavcopts vcodec=mpeg4:vbitrate=1000:vhq:vpass=1:vqmax=31 -vop scale=640:480"
#
# second pass
AUDIO_OPTS_2="-oac copy"
VIDEO_OPTS_2="-ovc lavc -lavcopts vcodec=mpeg4:vbitrate=1000:vhq:vpass=2:vqmax=31 -vop scale=640:480"

# </config>
###################################################################

# store "stream"-name passed by sserver
REC_FILE_BASE=`echo $1 | sed -e 's/\(.*\)\(\/\)\(.*\)/\3/g'`

# avoids more than one encoding processes
LOCK_FILE="/tmp/mkdvd.lock"

# some directory-definitions
# should be fine for everyone
MKDVD_BIN="/opt/mkdvd-0.06/mkdvd"
MKDVD_TARGET_DIR="${MKDVD_BASE_DIR}/dvd/001/VIDEO_TS"
MKISOFS_DIR="${MKDVD_BASE_DIR}/dvd/001/"
MKDVD_TARGET_FILE="${MKDVD_TARGET_DIR}/VTS_01_1.VOB"
TARGET="${MOVIE_DIR}/${REC_FILE_BASE}.${MODE}"

# usage
if [ $# -lt 1 ]
then
        echo "Usage: ./custom_script.udrec /<path>/<stream-basename> !"
	echo "  This script should be called by sserver."
	echo "  Otherwise do it like this:"
	echo "  e.g.: ./custom_script.udrec /<path>/RTL_Television_Formel_I__Das_Rennen_20031012_073001"
	echo " -> exiting..."
        exit 1
fi

# just to be sure  ...
sleep 3

# start the show
if [ -e "${MKDVD_TMP_DIR}/${REC_FILE_BASE}.v0" ]
then
	echo " -> recording of ${REC_FILE_BASE} finished ... !"
	echo " ->"
	echo " -> processing ${REC_FILE_BASE} ..."
	echo " ->"

	# checking already running encoding-process
	if [ -e ${LOCK_FILE} ]
	then
		while [ -e ${LOCK_FILE} ]
		do
	       		PID=`cat ${LOCK_FILE}`
	        	echo " -> waiting for PID:$PID to terminate ..."
			sleep 60
		done
	else
		echo $$ > ${LOCK_FILE}
	fi

	# catching mkdvd-bug(?) with corrupt a1-audiostream
	if [ -e "${MKDVD_TMP_DIR}/${REC_FILE_BASE}.a1" ]
	then
		echo " -> a1-audio-stream detected ..."
		echo " -> moving ${MKDVD_TMP_DIR}/${REC_FILE_BASE}.a1 ..."	
		echp " ->"
		mv ${MKDVD_TMP_DIR}/${REC_FILE_BASE}.a1 ${MKDVD_TMP_DIR}/${REC_FILE_BASE}.ac3
	fi

	# muxing v0 and a0
	echo " -> trying to \"mkdvd\" ${REC_FILE_BASE} (may take a while) ..."
	./mkdvd -onevob -f ${MKDVD_TMP_DIR}/${REC_FILE_BASE}

	# mkdvd successful ?
	if [ -e ${MKDVD_TARGET_FILE} ]
	then
		echo " -> \"mkdvd\" successful ..."
		echo " ->"
		echo " -> creating ${TARGET} ... (may take a looong time ...)"
		
		case "${MODE}" in
			mpg) 	
				echo " -> dumping audio"
				${MPLAYER} -vo null -dumpaudio -dumpfile \
					${MKDVD_TMP_DIR}/${REC_FILE_BASE}.mp2 \
					${MKDVD_TARGET_FILE} \
					${DEBUG}

				echo " -> dumping video"
				${MPLAYER} -vo null -dumpvideo -dumpfile \
					${MKDVD_TMP_DIR}/${REC_FILE_BASE}.m2v \
					${MKDVD_TARGET_FILE} \
					${DEBUG}
				
				# compression of m2v-file via requant
				if [ ${MPG_COMPRESSION} == "1" ]
				then
				echo " -> compressing video"
				cat ${MKDVD_TMP_DIR}/${REC_FILE_BASE}.m2v | ${REQUANT} ${REQUANT_OPTS} \
					> ${MKDVD_TMP_DIR}/${REC_FILE_BASE}_requant.m2v
				mv -f ${MKDVD_TMP_DIR}/${REC_FILE_BASE}_requant.m2v ${MKDVD_TMP_DIR}/${REC_FILE_BASE}.m2v
				fi				
		
				echo " -> muxing audio and video"
				${TCMPLEX} -m 2	-i ${MKDVD_TMP_DIR}/${REC_FILE_BASE}.m2v \
						-p ${MKDVD_TMP_DIR}/${REC_FILE_BASE}.mp2 \
						-o ${TARGET} \
						${DEBUG}
					
				rm -f ${MKDVD_TMP_DIR}/${REC_FILE_BASE}.mp2
				rm -f ${MKDVD_TMP_DIR}/${REC_FILE_BASE}.m2v
				;;
	
			vob) 	
				cp -f ${MKDVD_TARGET_FILE} ${TARGET}
				;;

			avi)	
				# first pass
				$MENCODER ${MKDVD_TARGET_FILE} ${AUDIO_OPTS} ${VIDEO_OPTS} \
						-o /dev/null ${DEBUG}

				# second pass
				$MENCODER ${MKDVD_TARGET_FILE} ${AUDIO_OPTS_2} ${VIDEO_OPTS_2} \
						-o ${TARGET} ${DEBUG}
				;;
				
			img)	
				# from udrec.script
				mkisofs -dvd-video -quiet -o ${TARGET} ${MKISOFS_DIR}
				# dvdrecord dev=0,0,0 blank=fast
				# dvdrecord speed=1 -dao dev=0,0,0 ${TARGET}
				# /usr/bin/sleep 30
				# md5sum ${TARGET} | tee -a $1.log
				# md5sum /dev/scd0 | tee -a $1.log
				# rm -f ${TARGET}
				# rm -f ${MKDVD_TARGET_DIR}/*
				;;

			*) 	
				echo "unknown"
				;;
		esac

		if [ -e ${TARGET} ]
		then
			echo " ->"
			echo " -> ... done !"
			echo " ->"
			echo " -> file:"
			echo " ->  ${TARGET}"
			echo " -> has been created."
			echo
			echo "Have fun ;)"
			echo
		else 
			echo " ->"
			echo			
			echo "encoding FAILED :(" 	
			echo
		fi

		## do some cleanup
		# 
		rm -f ${MKDVD_TARGET_DIR}/*
		rm -f ${LOCK_FILE}
	
		# CAREFUL : delete *.v0 *.a0 *.a1 usw.
		# Leave this commented if you want to keep your udrec-files	
		# rm -f ${MKDVD_TMP_DIR}/${REC_FILE_BASE}.*

		# finished ...
                exit 0

	else
		echo " -> \"mkdvd\" failed, could not create ${MKDVD_TARGET_FILE} for some reason !"
		echo " -> exiting..."
		rm -f ${MKDVD_TARGET_DIR}/*
		rm -f ${LOCK_FILE}
		exit 1
	fi
else
	echo " -> sorry, no ${MKDVD_TMP_DIR}/${REC_FILE_BASE}.v0 found ..."
	echo " -> exiting ..."
	exit 1
fi
Vielleicht kann jemand damit was anfangen. Das Ding ist historisch gewachsen und ich bitte alle shell-gurus mir evtl. bugs oder Kraut- und Rueben-Code zu verzeihen.

Gruss,
Patrick