[mythtv-users] my mencoder HDTV to hr.hdtv encoding script

Steven Adeff adeffs.mythtv at gmail.com
Sat Jun 3 19:41:25 UTC 2006


Here's my script, it runs a proper ivtc/decimate depending on the
source and copies over the original AC3 audio...

###################################################
#!/bin/bash
#
# My script to create hr.hdtv encodes.
#
# This script will perform the following tasks:
# 1. Analyze the original mpeg for
#	a. play length
#	b. audio size
#	c. frame speed (60fps/30fps)
# 2. Calculate final file size (350MB or 700MB)
# 3. Calculate final video size based on final file
#    size and audio size.
# 4. Encode.
#
# Note: This uses the original AC3 audio track!
#
# Version 0.1
#

###################################################
#variables
# These affect the encoding time and quality.
# I don't think changing these will necesarily help the
# picture quality, but will increase the encoding time.
# use 'man mencoder' to learn what they do, and play with them as you will.
settings_vhq=0
settings_mequality=5

#Functions
#Video Length Calculation
function VideoSizeCalc() {
	audiosize=`pc $audiobitrate/1000*$totalseconds*0.1220703125/1024`
	echo "Audio Size in MB = $audiosize"
	totalseconds=`echo $totalseconds|sed -e 's/\.[0-9]*//'`
	if [ $totalseconds -lt 1800 ]; then
		totalsize=350
	elif [ $totalseconds -lt 3600 ]; then
		totalsize=700
	else
		echo "I don't know how to handle this length!"
		exit 1
	fi
	echo "Total Size = $totalsize"
	videosize=`pc $totalsize-$audiosize`	# new one since overhead doesn't
						#really matter its so small
	videosize=`echo `${videosize:0:3}``
	echo "Videosize = $videosize MB"
}


function FileNameClean() {
	input=$1
	input=`echo "$input" | sed -e 's/.[Aa][Vv][Ii]//'`
	folder_name=$input
}

#test for arguements
if [[ -z "@ARGV" ]]; then
	echo "first arguement is the original mpg"
	echo "second arguement is the new file name"
	exit
else
	#Reassign variables	
	if [[ ! -e $1 ]]; then
		echo "no such input mpg!"
		exit
	else
		original_name=$1
	fi
	file_name=$2
	FileNameClean $2
	file_name=`echo "$filename" | tr A-Z a-z`
	# display arguments
	echo "Original mpeg is: $original_name"
	echo "File name will be: $file_name"
#	sleep 2
fi

#Grab input file information
echo "Determining total file length..."
totalseconds=`mencoder $original_name -ovc copy -nosound -o /dev/null
-quiet 2>&1 | awk '/^Video stream:/{print $10+$10/$12}'`
echo "total seconds = $totalseconds"
audiobitrate=`mplayer -vo null -ao null -frames 0 -identify
"$original_name" 2>/dev/null | grep "ID_AUDIO_BITRATE" | sed -e
's/ID_AUDIO_BITRATE=//'`
videowidth=`mplayer -vo null -ao null -frames 0 -identify
"$original_name" 2>/dev/null | grep "ID_VIDEO_WIDTH" | sed -e
's/ID_VIDEO_WIDTH=//'`
videoheight=`mplayer -vo null -ao null -frames 0 -identify
"$original_name" 2>/dev/null | grep "ID_VIDEO_HEIGHT" | sed -e
's/ID_VIDEO_HEIGHT=//'`
videofps=`mplayer -vo null -ao null -frames 0 -identify
"$original_name" 2>/dev/null | grep "ID_VIDEO_FPS" | sed -e
's/ID_VIDEO_FPS=//'`
#`mplayer -vo null -ao null -frames 0 -identify "$original_name"
2>/dev/null | grep "ID_" | sed -e 's/ID_=//'`
videofps=`echo `${videofps:0:2}``
echo "FPS: $videofps"
aspect=`pc $videowidth/$videoheight`
aspect=`echo "$aspect" | tr -s [:digit:]`
echo "Aspect Ratio: $aspect"
#Calculate Video size
VideoSizeCalc
sleep 2
videosize=`pc $videosize*1024`
echo "Videosize = $videosize"

if [[ -e "$original_name" ]]; then
	echo start `date +%H:%M`>$file_name.runtime
	if [[ "$videofps" -eq "59" ]]; then
		mencoder $original_name -oac copy -ovc xvid -vf
decimate=2:1000:1600:.001,scale=960:544 -ofps 24000/1001 -xvidencopts
pass=1:vhq=$settings_vhq:me_quality=$settings_mequality:turbo:quant_type=mpeg:aspect=$aspect:max_bframes=0:bitrate=-$videosize
-o /dev/null
		#
		mencoder $original_name -oac copy -ovc xvid -vf
decimate=2:1000:1600:.001,scale=960:544 -ofps 24000/1001 -xvidencopts
pass=2:vhq=$settings_vhq:me_quality=$settings_mequality:quant_type=mpeg:aspect=$aspect:max_bframes=0:bitrate=-$videosize
-o $file_name.avi
	elif [[ "$videofps" -eq "29" ]]; then
		mencoder $original_name -oac copy -ovc xvid -vf
pullup,softskip,scale=960:544 -ofps 24000/1001 -xvidencopts
pass=1:vhq=$settings_vhq:me_quality=$settings_mequality:turbo:quant_type=mpeg:aspect=$aspect:max_bframes=0:bitrate=-$videosize
-o /dev/null
		#
		mencoder $original_name -oac copy -ovc xvid -vf
pullup,softskip,scale=960:544 -ofps 24000/1001 -xvidencopts
pass=2:vhq=$settings_vhq:me_quality=$settings_mequality:quant_type=mpeg:aspect=$aspect:max_bframes=0:bitrate=-$videosize
-o $file_name.avi
	fi
	echo stop `date +%H:%M`>>$file_name.runtime
	echo "Runtime"
	more $file_name.runtime
fi
exit
###################################################

-- 
Steve
Before you ask, read the FAQ!
http://www.mythtv.org/wiki/index.php/Frequently_Asked_Questions
then search the Wiki, and this list,
http://www.gossamer-threads.com/lists/mythtv/
Mailinglist etiquette -
http://www.mythtv.org/wiki/index.php/Mailing_List_etiquette


More information about the mythtv-users mailing list