[MPlayer-dev-eng] [TOOL] Shell script for mencoder

Michele gattonero at freepass.it
Sat Sep 28 15:02:19 CEST 2002


Hi,
I wrote a simple shell script, in attachment, based on the dialog command
in Slackware style (pkgtool for example).
It encodes, using mencoder, a Dvd movie to DivX;-), asking to the user a
few simple questions. It computes crop and video bitrate automatically.
I'm working on it to add new features.
I hope you'll find it useful.
Bye!!!


71: 69 with two fingers up your ass.
(George Carlin)

-------------- next part --------------
#!/bin/bash

#
# (c) 2002 by Michele <gattonero at freepass.it>
#
# versione 0.2  
#
# 20/09/2002: aggiunta la funzionalita' di taglio automatico!
#
# Se avete commenti, critiche, suggerimenti, etc..
# scrivetemi un e-mail.
# Ringrazio gli sviluppatori di MPlayer per il loro eccezionale
# programma e Patrick J. Volkerding che con "pkgtool"
# mi ha dato l'ispirazione.
#
# Questo script e' software libero; potete ridistribuirlo
# e/o modificarlo secondo i termini stabiliti dalla GNU
# General Public License pubblicata dalla Free Software
# Foundation.
#
# Questo script viene distribuito nella speranza di essere utile
# ma SENZA ALCUNA GARANZIA.
# Vedi la GNU General Public License per ulteriori dettagli.
# Se non ne avete ricevuta una copia con questo software
# fate riferimento a: http://www.fsf.org/licenses/gpl.txt
#

#
# README:
# Durante le mie prove ho verificato che l'opzione -alang non 
# sempre funziona correttamente; se la traccia audio estratta
# non e' quella desiderata editate lo script ed usate invece 
# l'opzione -aid.
#
# Attenzione inoltre ad avere i permessi di scrittura nella
# directory /tmp e di poter eseguire lo shutdown del sistema
# (in caso contrario usate il programma sudo).
#
# Non dimenticate di settare i parametri del vostro masterizzatore.
#
# E' tutto. 
# Buon divertimento!
#

# Specificare i settaggi del proprio masterizzatore:
CDR_DEVICE=/dev/scd1
CDR_SPEED=4
CDR_ID=0,1,0

dialog --backtitle "MencTool 0.2" --menu "Quanti cd (700 Mb) si desidera usare?" 9 45 2 1 "un cd (consigliato)" 2 "due cd (se il film supera i 150 min)" 2>/tmp/f;

SPACE=`cat /tmp/f`

# Crea il file di summary
echo "Cd necessari: `echo $SPACE`" > /tmp/summary;

# Calcola lo spazio totale a disposizione per il film (Kbit)
SPACE=`expr $SPACE \* 690 \* 8192`

dialog --backtitle "MencTool 0.2" --inputbox "Quale titolo si desidera rippare?" 9 30 1 2>/tmp/f;

TRACK=`cat /tmp/f`

dialog --backtitle "MencTool 0.2" --inputbox "Inserisci la durata del film (minuti):" 9 30 2>/tmp/f;

TIME=`cat /tmp/f`

# Conversione in secondi
TIME=`expr $TIME \* 60`

dialog --backtitle "MencTool 0.2" --menu "Scegli il bitrate audio:" 11 30 4 64 "Kbit/s" 96 "Kbit/s" 112 "Kbit/s" 128 "Kbit/s" 2>/tmp/f;

A_BITRATE=`cat /tmp/f` 

# Trova lo spazio occupato dalla traccia audio
AUDIO=`expr $A_BITRATE \* $TIME`

# Calcola il bitrate video da usare
BITRATE=`expr $SPACE - $AUDIO`
BITRATE=`expr $BITRATE / $TIME`

# Imposta il bitrate video a 6000 Kbit/s se questo risulta maggiore
if [ $BITRATE -gt 6000 ]
	then BITRATE=6000
fi

dialog --backtitle "MencTool 0.2" --menu "Scegli la lingua:" 12 30 5 "en" inglese "it" italiano "fr" francese "de" tedesco "hu" ungherese 2>/tmp/f

LANGUAGE=`cat /tmp/f`

dialog --backtitle "MencTool 0.2" --menu "Scegli la risoluzione:" 14 30 7 720:576 "(originale)" 640:480 "" 640:360 "" 480:360 "" 480:270 "" 360:270 "" 360:202 "" 2>/tmp/f;

RESOLUTION=`cat /tmp/f` 

dialog --backtitle "MencTool 0.2" --inputbox "Inserire il nome da assegnare al file:" 9 30 .avi 2>/tmp/f;

FILENAME=`cat /tmp/f; rm -f /tmp/f`

dialog --backtitle "MencTool 0.2" --yesno "Al termine del ripping vuoi masterizzare il film?" 9 30

BURN=$?

if [ $BURN -eq 0 ]
	then eject $CDR_DEVICE;
	     dialog --backtitle "MencTool 0.2" --msgbox "Inserire un Cd-R da 700 Mb..." 9 30;
fi

dialog --backtitle "MencTool 0.2" --yesno "Si desidera spegnere il sistema al termine delle operazioni?" 8 30

# Variabile verificata al termine dello script per impartire o meno lo shutdown
HALT=$? 

# Crea il file di testo del summary
echo "Titolo selezionato: `echo $TRACK`" >> /tmp/summary;
echo "Bitrate video: `echo $BITRATE` Kbit/s" >> /tmp/summary;
echo "Risoluzione: `echo $RESOLUTION` pixel" >> /tmp/summary;
echo "Bitrate audio: `echo $A_BITRATE` Kbit/s" >> /tmp/summary;
echo "Lingua: `echo $LANGUAGE`" >> /tmp/summary;

dialog --backtitle "MencTool 0.2" --textbox /tmp/summary 11 30 
rm -f /tmp/summary;

clear;

# Log dell'ora di inizio ripping
date > time.txt;

rm -f frameno.avi lavc_stats.txt;

# Trova il valore adeguato di crop per il taglio delle bande nere
mencoder -dvd $TRACK -chapter 2 -endpos 5 -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=$BITRATE:keyint=50:vhq -vop cropdetect,scale=$RESOLUTION -sws 2 -oac copy -o temp.avi | grep vop | tail -n 1 | cut -d "=" -f 2 | tr -d ')' > /tmp/f;

CROP=`cat /tmp/f; rm -f /tmp/f`

# Scarica sul disco il titolo selezionato. Modificare se non si dispone di spazio sufficiente
mencoder -dvd $TRACK -ovc copy -oac copy -alang $LANGUAGE -o TEMP.VOB;

# Primo passo: compressione audio
cat TEMP.VOB | mencoder - -ovc frameno -alang $LANGUAGE -oac mp3lame -lameopts br=$A_BITRATE:cbr:vol=3 -o frameno.avi;

# Secondo passo: primo passo compressione video
cat TEMP.VOB | mencoder - -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=$BITRATE:keyint=50:vhq:vpass=1 -vop crop=$CROP,scale=$RESOLUTION -sws 2 -oac copy -o /dev/null; 

# Terzo passo: secondo passo compressione video e aggiunta dell'audio
cat TEMP.VOB | mencoder - -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=$BITRATE:keyint=50:vhq:vpass=2 -vop crop=$CROP,scale=$RESOLUTION -sws 2 -oac copy -o $FILENAME;
rm -f frameno.avi TEMP.VOB;

# Log dell'ora di fine ripping
date >> time.txt

# Masterizza il film
if [ $BURN -eq 0 ]
	then mkisofs -J -l -V "$FILENAME" $FILENAME | cdrecord -v dev=$CDR_ID speed=$CDR_SPEED -data -
fi

# Impartisce lo shutdown usando il programma sudo (per gli utenti non privilegiati)
if [ $HALT -eq 0 ]
	then sudo halt
fi
-------------- next part --------------
#!/bin/bash

#
# (c) 2002 by Michele <gattonero at freepass.it>
#
# version 0.2  
#
# 20/09/2002: added autocrop functionality!
#
# If you have any comments, critics, suggestions, etc..., 
# send me an e-mail.
# Thanks to the MPlayer developers for this great software and to
# Patrick J. Volkerding with his "pkgtool" that inspired me.
#
# This script is free software; you can redistribute and/or
# modify it under the terms of the GNU General Public
# License as published by the Free Software Foundation. 
#
# This script is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY. 
# See the GNU General Public License for more details.
# You should have received a copy of that along with this
# software, if not refer to: http://www.fsf.org/licenses/gpl.txt
#

#
# README:
# In my experience the -alang option not always works properly, if 
# you have trouble with the correct language audio grabbing edit 
# the script and use the -aid option instead.
#
# Also pay attention to have write permission on /tmp directory
# and necessary rights to execute system shutdown (if not use sudo).
#
# Don't forget to edit your cdburner settings 8 lines below.
#
# That's all.
# Happy encoding!
#

# Specify your cdburner settings:
CDR_DEVICE=/dev/scd1
CDR_SPEED=4
CDR_ID=0,1,0

dialog --backtitle "MencTool 0.2" --menu "How many cd's (700 Mb) would you use?" 9 51 2 1 "one cd (recommended)" 2 "two cd's (if movie is longer than 150 min)" 2>/tmp/f;

SPACE=`cat /tmp/f`

# Creates the summary file
echo "Cd number: `echo $SPACE`" > /tmp/summary;

# Avi final size
SPACE=`expr $SPACE \* 690 \* 8192`

dialog --backtitle "MencTool 0.2" --inputbox "Which track would you encode?" 9 30 1 2>/tmp/f;

TRACK=`cat /tmp/f`

dialog --backtitle "MencTool 0.2" --inputbox "Insert total movie time (minutes):" 9 30 2>/tmp/f;

TIME=`cat /tmp/f`

# Conversion from minutes to seconds
TIME=`expr $TIME \* 60`

dialog --backtitle "MencTool 0.2" --menu "Select audio bitrate:" 11 30 4 64 "Kbit/s" 96 "Kbit/s" 112 "Kbit/s" 128 "Kbit/s" 2>/tmp/f;

A_BITRATE=`cat /tmp/f` 

# Finds audio track size
AUDIO=`expr $A_BITRATE \* $TIME`

# Finds video bitrate
BITRATE=`expr $SPACE - $AUDIO`
BITRATE=`expr $BITRATE / $TIME`

# If video bitrate is major than 6000 sets it to 6000 Kbit/s
if [ $BITRATE -gt 6000 ]
	then BITRATE=6000
fi

dialog --backtitle "MencTool 0.2" --menu "Select audio language:" 12 30 5 "en" english "it" italian "fr" french "de" german "hu" hungarian 2>/tmp/f

LANGUAGE=`cat /tmp/f`

dialog --backtitle "MencTool 0.2" --menu "Select resolution:" 14 30 7 720:576 "(original)" 640:480 "" 640:360 "" 480:360 "" 480:270 "" 360:270 "" 360:202 "" 2>/tmp/f;

RESOLUTION=`cat /tmp/f` 

dialog --backtitle "MencTool 0.2" --inputbox "Insert .avi file name:" 9 30 .avi 2>/tmp/f;

FILENAME=`cat /tmp/f;`

dialog --backtitle "MencTool 0.2" --yesno "Would you burn the movie, after ripping?" 9 30

BURN=$?

if [ $BURN -eq 0 ]
	then eject $CDR_DEVICE;
	     dialog --backtitle "MencTool 0.2" --msgbox "Insert a 700 Mb Cd-R..." 9 30;
fi

dialog --backtitle "MencTool 0.2" --yesno "Would you shutdown the system, finally?" 8 30

# Variabile verified at the end of script for shutdown
HALT=$? 

# Appends rip settings to summary file
echo "Selected track: `echo $TRACK`" >> /tmp/summary;
echo "Video bitrate : `echo $BITRATE` Kbit/s" >> /tmp/summary;
echo "Resolution: `echo $RESOLUTION` pixel" >> /tmp/summary;
echo "Audio bitrate : `echo $A_BITRATE` Kbit/s" >> /tmp/summary;
echo "Language: `echo $LANGUAGE`" >> /tmp/summary;

dialog --backtitle "MencTool 0.2" --textbox /tmp/summary 11 30 
rm -f /tmp/summary;

clear;

# Start time log
date > time.txt;

rm -f frameno.avi lavc_stats.txt;

# Detects crop value to cut black bands
mencoder -dvd $TRACK -chapter 2 -endpos 5 -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=$BITRATE:keyint=50:vhq -vop cropdetect,scale=$RESOLUTION -sws 2 -oac copy -o temp.avi | grep vop | tail -n 1 | cut -d "=" -f 2 | tr -d ')' > /tmp/f;

CROP=`cat /tmp/f; rm -f /tmp/f`

# Save on disc selected track. If you don't have enough disk space 
# comment this line and edit the three passes removing 'cat TEMP.VOB |'
# and using 'mencoder -dvd $TRACK ...'; remember to also remove the '-'.
mencoder -dvd $TRACK -ovc copy -oac copy -alang $LANGUAGE -o TEMP.VOB;

# First pass: audio compression 
cat TEMP.VOB | mencoder - -ovc frameno -alang $LANGUAGE -oac mp3lame -lameopts br=$A_BITRATE:cbr:vol=3 -o frameno.avi;

# Second pass: video compression first pass 
cat TEMP.VOB | mencoder - -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=$BITRATE:keyint=50:vhq:vpass=1 -vop crop=$CROP,scale=$RESOLUTION -sws 2 -oac copy -o /dev/null; 

# Third pass: video compression second pass while adding compressed audio
cat TEMP.VOB | mencoder - -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=$BITRATE:keyint=50:vhq:vpass=2 -vop crop=$CROP,scale=$RESOLUTION -sws 2 -oac copy -o $FILENAME;
rm -f frameno.avi TEMP.VOB;

# End time log
date >> time.txt

# Burns the movie
if [ $BURN -eq 0 ]
	then mkisofs -J -l -V "$FILENAME" $FILENAME | cdrecord -v dev=$CDR_ID speed=$CDR_SPEED -data -
fi

# Shutdowns the computer using sudo (for non privileged users)
if [ $HALT -eq 0 ]
	then sudo halt
fi


More information about the MPlayer-dev-eng mailing list