#!/bin/bash
# Filename: qd-dvd
# Version: 061111
# Author: robz
# Quick n' dirty single "movie.mpg" to "dvd.iso" to dvdrw/dvdr disk.
# The "movie.mpg" will need to be a dvd compatible file, eg with ffmpeg the
# "-target" switch will be required with pal-dvd or ntsc-dvd or film-dvd set.
# Script will overwrite rw disks without asking so make sure you have the
# right disk in your drive, in my case that drive is /dev/sr0 yours may be
# different.
# Make the script executable and chuck it in the "nautilus-scripts" directory.
# Usage: Insert a disk, right-click file to burn > Scripts > qd-dvd.
trap "killall -q dvdauthor genisoimage growisofs; rm -rf 'tmp-files'; \
exit" INT TERM EXIT # Clean on exit/error.
author_it ()
{
echo -e "\033[1m\E[37mWorking on - $MOVIE" # Colour the headings.
echo -e "\033[1m\E[36mCreating the DVD file structure\033[0m\E[37m"
nice -n 19 dvdauthor -o tmp-files -t $MOVIE && \
echo -e "\033[1m\E[34mSuccessfully created file structure"
echo -e "\033[1m\E[36m\nFinalize the structure\033[0m\E[37m"
VIDEO_FORMAT=PAL nice -n 19 dvdauthor -o tmp-files -T && \
echo -e "\033[1m\E[34mFile Structure finalized"
}
iso_it ()
{
MOVIE=${MOVIE%.mpg}.iso # Change extension.
echo -e "\033[1m\E[36m\nCreating $MOVIE\033[0m\E[37m\
\nThis may take a while, please wait...."
nice -n 19 genisoimage -quiet -V "DVD" -o "$MOVIE" -dvd-video tmp-files && \
tput cuu1; tput el; \
echo -e "\033[1m\E[34mISO created successfully\n\033[0m\E[37m"
}
burn_it ()
{
if ! udisks --show-info /dev/sr0 | grep "media: *optical_dvd_plus_r"; then
echo -e "\033[1m\E[33mOOPS\033[1m\E[37m"
echo -e "No writeable disk! Burn created .iso later eh. \033[1m\E[34m"
read -p "Hit a key to exit" -n1; exit
else
tput cuu1; tput el; tput cuu1
echo -e "\033[1m\E[36m\nBurning $MOVIE\033[0m\E[37m"
echo "This may take a while, please wait.... "
nice -n 19 growisofs -quiet -dvd-compat -Z /dev/sr0="$MOVIE"\
-use-the-force-luke=notray -use-the-force-luke=tty # My drive sr0, yours?
if [ "$?" = "0" ]; then # Did it burn OK?
echo -e "\033[1m\E[32m$MOVIE burned - job done - Bye! \n\033[1m\E[36m"
rm "$MOVIE" # Clean up iso file.
else echo -e "\033[1m\E[31mERROR\033[1m\E[37m burn failed"
fi
fi
sleep 2
eject -r sr0; read -t10 -p "Remove disk and hit a key to exit";
}
export -f author_it; export -f iso_it; export -f burn_it; export MOVIE="$1"
gnome-terminal --title="Quick n' Dirty MPG>ISO>DISK" \
--geometry=85x55+0+25 -x bash -c "tput civis; author_it; iso_it; burn_it"
Mint Serena 64 bit using the Mate desktop environment. Most of the following scripts will run on this machine, although some have only been tested with the Gnome desktop. Extra software requirements can be met by the Ubuntu and safe PPA repositories. Scripts may be re-written or added to from time to time, the date serves as the version number. Syntax highlighting on these pages is provided by GVim's "Convert to HTML" option.
Showing posts with label convert. Show all posts
Showing posts with label convert. Show all posts
FFmpeg with progress bar (re-work)
#!/bin/bash
# File name: ZAVI2MPG - saved in the "nautilus-scripts" directory.
# Author: robz
# Version: 130511
# This is a re-re-work of a previous script for converting .avi television
# files to a "burnable to DVD" format. This time though conversion statistics
# visual output is supplied by the Zenity dialogue. Stats logfile also added.
# File locations in some variables are specific to my PC check "# Vars" first.
# The script is called by right clicking on the ".avi file" then clicking
# the appropriate choice in the nautilus-scripts menu.
# You'll need "FFmpeg" an FFmpeg notify-send icon and a ding-dong.wav sound.
# Vars.
ICON=$HOME/Pictures/user_graphics/Icons/ffmpeg-logo-small.png
LOG=$HOME/Torrents/re-coding.log
display () # Calculate/collect progress bar info. & pipe to Zenity.
{
START=$(date +%s); FR_CNT=0; ETA=0; ELAPSED=0
while [ -e /proc/$PID ]; do # Is FFmpeg running?
sleep 2
VSTATS=$(awk '{gsub(/frame=/, "")}/./{line=$1-1} END{print line}' \
"$RM"/vstats*) # Parse vstats file.
if [ $VSTATS -gt $FR_CNT ]; then # Parsed sane or no?
FR_CNT=$VSTATS
PERCENTAGE=$(( 100 * FR_CNT / TOT_FR )) # Progbar calc.
ELAPSED=$(( $(date +%s) - START )); echo $ELAPSED > /tmp/elapsed.value
ETA=$(date -d @$(awk 'BEGIN{print int(('$ELAPSED' / '$FR_CNT') *\
('$TOT_FR' - '$FR_CNT'))}') -u +%H:%M:%S) # ETA calc.
fi
echo "# Working on file: $COUNT of $OF - Length: $DUR - Frames: $TOT_FR\
\nFilename: ${NFILE%.*}\nSaved to: $SAVEAS\
\nTelevision standard is set to: $TFORM2\
\nRe-coding with FFmpeg, method: $QUAL\
\nFrame: $FR_CNT of $TOT_FR Elapsed: $(date -d @$ELAPSED -u\
+%H:%M:%S) ET to finish: $ETA" # Text for stats. output.
echo $PERCENTAGE # Feed the progbar.
done | zenity\
--progress\
--window-icon $ICON\
--title="AVI-2-MPG ${QUAL:10:13}"\
--text="Initializing please wait..."\
--percentage=0\
--auto-close\
--auto-kill
}
SEL=$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS # Right clicked selection.
RM=$(pwd)
trap "killall ffmpeg ZAVI2MPG; rm -f "$RM/ffmpeg2pass*" "$RM/vstats*"; exit" \
INT TERM EXIT # Kill & clean if stopped.
# Select re-coded file destination.
SAVEAS=$(zenity --file-selection --directory\
--window-icon $ICON --title ">>SELECT DESTINATION FOR RE-CODED FILE<<")
if [ "$?" = 1 ]; then
exit $?
fi
# Select quality of re-code.
QUAL=$(zenity --window-icon $ICON --title "AVI-2-MPG"\
--width 340 --height 170 --list --text "Recode Mode"\
--radiolist --column "Select " --column "FFmpeg re-code option"\
FALSE 'One Pass, same Q big file, fast.'\
TRUE 'Two Pass, same Q smaller file, slow.');
if [ $? = 1 ]; then
exit $?
elif [ "${QUAL:0:8}" = "One Pass" ]; then
QUAL="One Pass - Re-coding..."
fi
SAVEIFS=$IFS # Make "for loops" handle
IFS=$(echo -en "\n\b") # filenames with spaces.
for FILE in $SEL; do ((OF+=1)); done # Count right click
echo -e $(date +%c)" - Files processed: $OF\n" >> $LOG # selected files, log.
# Loop through counted file selection and process in turn.
for FILE in $SEL; do ((COUNT+=1))
NFILE=$(basename "$FILE")
# Get duration and PAL/NTSC fps then calculate total frames.
FPS=$(ffprobe "$FILE" 2>&1 | sed -n "s/.*, \(.*\) tbr.*/\1/p")
DUR=$(ffprobe "$FILE" 2>&1 | sed -n "s/.* Duration: \([^,]*\), .*/\1/p")
HRS=$(echo $DUR | cut -d":" -f1)
MIN=$(echo $DUR | cut -d":" -f2)
SEC=$(echo $DUR | cut -d":" -f3)
TOT_FR=$(echo "($HRS*3600+$MIN*60+$SEC)*$FPS" | bc | cut -d"." -f1)
if [ ! "$TOT_FR" -gt "0" ]; then zenity --error; exit; fi
# TV format to FFmpeg friendly.
TFORM=$(echo "$FPS" |\
sed "s/25/pal-dvd/g; s/30/pal-dvd/g; s/29.98/ntsc-dvd/g;\
s/29.97/ntsc-dvd/g; s/23.98/ntsc-dvd/g;")
TFORM2=$(echo "$FPS" |\
sed "s/25/PAL @ 25fps/g; s/30/PAL @ 30fps/g;\
s/29.98/NTSC @ 29.98fps/g; s/29.97/NTSC @ 29.97fps/g;\
s/23.98/NTSC-Film @ 23.98fps/g;")
# Re-code with it.
if [ "$QUAL" = "One Pass - Re-coding..." ]; then # Same Q big file.
nice -n 15 ffmpeg -i "$FILE"\
-target $TFORM\
-sameq\
-r $FPS\
-vstats\
-y\
$SAVEAS/${NFILE%.*}.mpg & # Background FFmpeg.
PID=$! && display # GUI stats. func.
rm -f "$RM"/vstats* # Clean up tmp files.
else
QUAL="Two Pass - Analysing..." # Analyse video only.
nice -n 15 ffmpeg -i "$FILE"\
-pass 1\
-target $TFORM\
-r $FPS\
-vstats\
-b 2800k\
-an\
-y\
/dev/null & # Background FFmpeg.
PID=$! && display # GUI stats. func.
rm -f "$RM"/vstats* # Clean up.
AN_TM=$(cat /tmp/elapsed.value) # Get analyse time.
((BATCH+=$AN_TM)) # Batch time totaling.
QUAL="Two Pass - Re-coding..." # Do smaller re-code.
nice -n 15 ffmpeg -i "$FILE"\
-pass 2\
-target $TFORM\
-r $FPS\
-vstats\
-b 2800k\
-acodec ac3\
-ar 48000\
-ab 128k\
-y\
$SAVEAS/${NFILE%.*}.mpg & # Background FFmpeg.
PID=$! && display # GUI stats. func.
rm -f "$RM"/ffmpeg2pass* "$RM"/vstats* # Clean up tmp files.
fi
# Statistics for logfile entry.
((BATCH+=$(cat /tmp/elapsed.value))) # Batch time totaling.
ELAPSED=$(cat /tmp/elapsed.value) # Per file time.
echo -e $COUNT\. ${NFILE%.*}\
"\nDuration: $DUR - Total frames: $TOT_FR\
\nCoded to $TFORM2 standard using \"${QUAL:0:8}\" option." >> $LOG
# Elapsed time for 1 pass, average for 2 passes, fps average for both.
if [ "${QUAL:0:8}" = "Two Pass" ]; then
((ELAPSED+=$AN_TM)); AV_RATE=$(( TOT_FR * 2 / ELAPSED ))
else
AV_RATE=$(( TOT_FR / ELAPSED ))
fi
echo -e "Re-coding time taken: $(date -d @$ELAPSED -u +%H:%M:%S)"\
"at an average rate of $AV_RATE""fps.\n" >> $LOG
done
# Notify finished batch ding-dong gong and message, log it, all done bye ;¬)
TEXT="Total re-coding time: $(date -d @$BATCH -u +%H:%M:%S)."
echo -e "$TEXT\n\
__________________________________________________________________" >> $LOG
notify-send -i $ICON "ZAVI2MPG Re-code completed" "$TEXT"
/usr/bin/canberra-gtk-play --volume 2 -f $HOME/Audio/2tone.wav
# File name: ZAVI2MPG - saved in the "nautilus-scripts" directory.
# Author: robz
# Version: 130511
# This is a re-re-work of a previous script for converting .avi television
# files to a "burnable to DVD" format. This time though conversion statistics
# visual output is supplied by the Zenity dialogue. Stats logfile also added.
# File locations in some variables are specific to my PC check "# Vars" first.
# The script is called by right clicking on the ".avi file" then clicking
# the appropriate choice in the nautilus-scripts menu.
# You'll need "FFmpeg" an FFmpeg notify-send icon and a ding-dong.wav sound.
# Vars.
ICON=$HOME/Pictures/user_graphics/Icons/ffmpeg-logo-small.png
LOG=$HOME/Torrents/re-coding.log
display () # Calculate/collect progress bar info. & pipe to Zenity.
{
START=$(date +%s); FR_CNT=0; ETA=0; ELAPSED=0
while [ -e /proc/$PID ]; do # Is FFmpeg running?
sleep 2
VSTATS=$(awk '{gsub(/frame=/, "")}/./{line=$1-1} END{print line}' \
"$RM"/vstats*) # Parse vstats file.
if [ $VSTATS -gt $FR_CNT ]; then # Parsed sane or no?
FR_CNT=$VSTATS
PERCENTAGE=$(( 100 * FR_CNT / TOT_FR )) # Progbar calc.
ELAPSED=$(( $(date +%s) - START )); echo $ELAPSED > /tmp/elapsed.value
ETA=$(date -d @$(awk 'BEGIN{print int(('$ELAPSED' / '$FR_CNT') *\
('$TOT_FR' - '$FR_CNT'))}') -u +%H:%M:%S) # ETA calc.
fi
echo "# Working on file: $COUNT of $OF - Length: $DUR - Frames: $TOT_FR\
\nFilename: ${NFILE%.*}\nSaved to: $SAVEAS\
\nTelevision standard is set to: $TFORM2\
\nRe-coding with FFmpeg, method: $QUAL\
\nFrame: $FR_CNT of $TOT_FR Elapsed: $(date -d @$ELAPSED -u\
+%H:%M:%S) ET to finish: $ETA" # Text for stats. output.
echo $PERCENTAGE # Feed the progbar.
done | zenity\
--progress\
--window-icon $ICON\
--title="AVI-2-MPG ${QUAL:10:13}"\
--text="Initializing please wait..."\
--percentage=0\
--auto-close\
--auto-kill
}
SEL=$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS # Right clicked selection.
RM=$(pwd)
trap "killall ffmpeg ZAVI2MPG; rm -f "$RM/ffmpeg2pass*" "$RM/vstats*"; exit" \
INT TERM EXIT # Kill & clean if stopped.
# Select re-coded file destination.
SAVEAS=$(zenity --file-selection --directory\
--window-icon $ICON --title ">>SELECT DESTINATION FOR RE-CODED FILE<<")
if [ "$?" = 1 ]; then
exit $?
fi
# Select quality of re-code.
QUAL=$(zenity --window-icon $ICON --title "AVI-2-MPG"\
--width 340 --height 170 --list --text "Recode Mode"\
--radiolist --column "Select " --column "FFmpeg re-code option"\
FALSE 'One Pass, same Q big file, fast.'\
TRUE 'Two Pass, same Q smaller file, slow.');
if [ $? = 1 ]; then
exit $?
elif [ "${QUAL:0:8}" = "One Pass" ]; then
QUAL="One Pass - Re-coding..."
fi
SAVEIFS=$IFS # Make "for loops" handle
IFS=$(echo -en "\n\b") # filenames with spaces.
for FILE in $SEL; do ((OF+=1)); done # Count right click
echo -e $(date +%c)" - Files processed: $OF\n" >> $LOG # selected files, log.
# Loop through counted file selection and process in turn.
for FILE in $SEL; do ((COUNT+=1))
NFILE=$(basename "$FILE")
# Get duration and PAL/NTSC fps then calculate total frames.
FPS=$(ffprobe "$FILE" 2>&1 | sed -n "s/.*, \(.*\) tbr.*/\1/p")
DUR=$(ffprobe "$FILE" 2>&1 | sed -n "s/.* Duration: \([^,]*\), .*/\1/p")
HRS=$(echo $DUR | cut -d":" -f1)
MIN=$(echo $DUR | cut -d":" -f2)
SEC=$(echo $DUR | cut -d":" -f3)
TOT_FR=$(echo "($HRS*3600+$MIN*60+$SEC)*$FPS" | bc | cut -d"." -f1)
if [ ! "$TOT_FR" -gt "0" ]; then zenity --error; exit; fi
# TV format to FFmpeg friendly.
TFORM=$(echo "$FPS" |\
sed "s/25/pal-dvd/g; s/30/pal-dvd/g; s/29.98/ntsc-dvd/g;\
s/29.97/ntsc-dvd/g; s/23.98/ntsc-dvd/g;")
TFORM2=$(echo "$FPS" |\
sed "s/25/PAL @ 25fps/g; s/30/PAL @ 30fps/g;\
s/29.98/NTSC @ 29.98fps/g; s/29.97/NTSC @ 29.97fps/g;\
s/23.98/NTSC-Film @ 23.98fps/g;")
# Re-code with it.
if [ "$QUAL" = "One Pass - Re-coding..." ]; then # Same Q big file.
nice -n 15 ffmpeg -i "$FILE"\
-target $TFORM\
-sameq\
-r $FPS\
-vstats\
-y\
$SAVEAS/${NFILE%.*}.mpg & # Background FFmpeg.
PID=$! && display # GUI stats. func.
rm -f "$RM"/vstats* # Clean up tmp files.
else
QUAL="Two Pass - Analysing..." # Analyse video only.
nice -n 15 ffmpeg -i "$FILE"\
-pass 1\
-target $TFORM\
-r $FPS\
-vstats\
-b 2800k\
-an\
-y\
/dev/null & # Background FFmpeg.
PID=$! && display # GUI stats. func.
rm -f "$RM"/vstats* # Clean up.
AN_TM=$(cat /tmp/elapsed.value) # Get analyse time.
((BATCH+=$AN_TM)) # Batch time totaling.
QUAL="Two Pass - Re-coding..." # Do smaller re-code.
nice -n 15 ffmpeg -i "$FILE"\
-pass 2\
-target $TFORM\
-r $FPS\
-vstats\
-b 2800k\
-acodec ac3\
-ar 48000\
-ab 128k\
-y\
$SAVEAS/${NFILE%.*}.mpg & # Background FFmpeg.
PID=$! && display # GUI stats. func.
rm -f "$RM"/ffmpeg2pass* "$RM"/vstats* # Clean up tmp files.
fi
# Statistics for logfile entry.
((BATCH+=$(cat /tmp/elapsed.value))) # Batch time totaling.
ELAPSED=$(cat /tmp/elapsed.value) # Per file time.
echo -e $COUNT\. ${NFILE%.*}\
"\nDuration: $DUR - Total frames: $TOT_FR\
\nCoded to $TFORM2 standard using \"${QUAL:0:8}\" option." >> $LOG
# Elapsed time for 1 pass, average for 2 passes, fps average for both.
if [ "${QUAL:0:8}" = "Two Pass" ]; then
((ELAPSED+=$AN_TM)); AV_RATE=$(( TOT_FR * 2 / ELAPSED ))
else
AV_RATE=$(( TOT_FR / ELAPSED ))
fi
echo -e "Re-coding time taken: $(date -d @$ELAPSED -u +%H:%M:%S)"\
"at an average rate of $AV_RATE""fps.\n" >> $LOG
done
# Notify finished batch ding-dong gong and message, log it, all done bye ;¬)
TEXT="Total re-coding time: $(date -d @$BATCH -u +%H:%M:%S)."
echo -e "$TEXT\n\
__________________________________________________________________" >> $LOG
notify-send -i $ICON "ZAVI2MPG Re-code completed" "$TEXT"
/usr/bin/canberra-gtk-play --volume 2 -f $HOME/Audio/2tone.wav
FFmpeg - 2 pass option
#!/bin/bash
# File name: avi2mpg-multi
# Author: robz
# Version: 021210
# robz script to convert a generic AVI television file to DVD compatible
# format. The script is called from right click link in nautilus scripts menu.
# You need "ffmpeg" and you'll need to choose a notify-send icon and sounds
# Colours
C1="\033[1m\E[32m" # green
C2="\033[1m\E[33m" # yellow
C3="\033[1m\E[36m" # cyan
C4="\033[1m\E[37m" # white
# Titles & verbals
T1=">>SELECT DESTINATION FOR RE-CODED FILE<<"
T2="robz BATCH RE-CODE2MPG Script"
H1=$C3"Original filename:"$C4
H2=$C3"New filename:"$C4
H7=$C3"Television standard is set to: "
H3=$C3"Re-coded file saved in:"$C4
H4=$C2"Start-- Re-coding with FFmpeg"
H5="-------------------------------------------------------------------------"
# Functions
single_pass() {
gnome-terminal --geometry=100x52+0+0 --title="$T2" -x bash -c "echo -e \
'$H1\n$NFILE\n$H2\n'${NFILE%.*}.mpg'\n$H3\n$SAVEAS';\
echo -e '$H7$TFORM2\n\n$H4\nMethod: $METH';\
echo -e '$H5';\
tput sgr0;\
nice -n 19 $OPT;\
echo -ne '$C1$H5';\
gong;\
sleep 5";
}
two_pass() {
gnome-terminal --geometry=100x65+0+0 --title="$T2" -x bash -c "echo -e \
'$H1\n$NFILE\n$H2\n'${NFILE%.*}.mpg'\n$H3\n$SAVEAS';\
echo -e '$H7$TFORM2\n\n$H4\nMethod: $METH';\
echo -e '$H5\nPASS 1 --- Analysing';\
tput sgr0;\
nice -n 19 $PASS1;\
echo -e '$H5\nPASS 2 --- Re-coding';\
tput sgr0;\
nice -n 19 $PASS2;\
echo -ne '$C1$H5';\
gong;\
rm -f "$RM"/ffmpeg2pass*;\
sleep 5";
}
gong() {
ICON=$HOME/Pictures/user_graphics/Icons/ffmpeg-logo-small.png
notify-send -i $ICON "##### AVI-2-MPG ######" "### File re-code completed ###"
/usr/bin/canberra-gtk-play --volume 6 -f $SOUND
}
## Start here.#####
SEL=$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS # Start here with right clicked file.
export SOUND=$HOME/Audio/2tone.wav
export -f gong
RM=$(pwd)
trap "killall ffmpeg; rm -f "$RM"/ffmpeg2pass*; exit" \
INT TERM EXIT
## Select file destination.
SAVEAS=$(zenity --file-selection --directory --title="$T1")
if [ "$?" = 1 ]; then
exit $?
fi
## Quality of re-code.
QUAL=$(zenity --title "NEW-AVI2MPG" --width 280 --height 200 --list \
--text "Select Re-code Mode" --radiolist --column \
"Select" --column "FFmpeg Options" TRUE 'Single Pass High'\
FALSE 'Single Pass Low' FALSE 'Two Pass');
if [ $? = 1 ]; then
exit $?
fi
## Make "for loop" handle filenames with spaces!!!!
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
## Loop through multiple file selections.
for FILE in $SEL; do
NFILE=$(basename "$FILE")
## TV format frame rate to FFmpeg friendly.
FPS=$(ffprobe "$FILE" 2>&1 | sed -n "s/.*, \(.*\) tbr.*/\1/p")
TFORM=$(echo "$FPS" |\
sed "s/25/pal-dvd/g; s/30/ntsc-dvd/g; s/29.98/ntsc-dvd/g;\
s/29.97/ntsc-dvd/g; s/23.98/ntsc-dvd -r 23.98/g;")
TFORM2=$(echo "$FPS" |\
sed "s/25/PAL @ 25fps/g; s/29.98/NTSC @ 29.98fps/g;\
s/29.97/NTSC @ 29.97fps/g; s/23.98/NTSC-Film @ 23.98fps/g;")
## FFmpeg options.
# Single pass implied vbr same quality as original.
HIGHBR="ffmpeg -i '$FILE'\
-target $TFORM\
-sameq\
'$SAVEAS/${NFILE%.*}.mpg'"
# Single pass low options.
LOWBR="ffmpeg -i '$FILE'\
-target $TFORM\
-b 2000k\
-acodec ac3\
-ar 48000\
-ab 96k\
'$SAVEAS/${NFILE%.*}.mpg'"
# Two pass options.
PASS1="ffmpeg -i '$FILE'\
-pass 1\
-target $TFORM\
-b 2600k\
-an\
-y\
/dev/null"
PASS2="ffmpeg -i '$FILE'\
-pass 2\
-target $TFORM\
-b 2600k\
-acodec ac3\
-ar 48000\
-ab 128k\
'$SAVEAS/${NFILE%.*}.mpg'"
## Determine quality then re-code to it.
if [ "$QUAL" = "Single Pass High" ]; then
METH="$QUAL"
OPT="$HIGHBR"
single_pass & wait
elif [ "$QUAL" = "Single Pass Low" ]; then
METH="$QUAL"
OPT="$LOWBR"
single_pass & wait
else
METH="Two Pass High"
two_pass
fi
done
# File name: avi2mpg-multi
# Author: robz
# Version: 021210
# robz script to convert a generic AVI television file to DVD compatible
# format. The script is called from right click link in nautilus scripts menu.
# You need "ffmpeg" and you'll need to choose a notify-send icon and sounds
# Colours
C1="\033[1m\E[32m" # green
C2="\033[1m\E[33m" # yellow
C3="\033[1m\E[36m" # cyan
C4="\033[1m\E[37m" # white
# Titles & verbals
T1=">>SELECT DESTINATION FOR RE-CODED FILE<<"
T2="robz BATCH RE-CODE2MPG Script"
H1=$C3"Original filename:"$C4
H2=$C3"New filename:"$C4
H7=$C3"Television standard is set to: "
H3=$C3"Re-coded file saved in:"$C4
H4=$C2"Start-- Re-coding with FFmpeg"
H5="-------------------------------------------------------------------------"
# Functions
single_pass() {
gnome-terminal --geometry=100x52+0+0 --title="$T2" -x bash -c "echo -e \
'$H1\n$NFILE\n$H2\n'${NFILE%.*}.mpg'\n$H3\n$SAVEAS';\
echo -e '$H7$TFORM2\n\n$H4\nMethod: $METH';\
echo -e '$H5';\
tput sgr0;\
nice -n 19 $OPT;\
echo -ne '$C1$H5';\
gong;\
sleep 5";
}
two_pass() {
gnome-terminal --geometry=100x65+0+0 --title="$T2" -x bash -c "echo -e \
'$H1\n$NFILE\n$H2\n'${NFILE%.*}.mpg'\n$H3\n$SAVEAS';\
echo -e '$H7$TFORM2\n\n$H4\nMethod: $METH';\
echo -e '$H5\nPASS 1 --- Analysing';\
tput sgr0;\
nice -n 19 $PASS1;\
echo -e '$H5\nPASS 2 --- Re-coding';\
tput sgr0;\
nice -n 19 $PASS2;\
echo -ne '$C1$H5';\
gong;\
rm -f "$RM"/ffmpeg2pass*;\
sleep 5";
}
gong() {
ICON=$HOME/Pictures/user_graphics/Icons/ffmpeg-logo-small.png
notify-send -i $ICON "##### AVI-2-MPG ######" "### File re-code completed ###"
/usr/bin/canberra-gtk-play --volume 6 -f $SOUND
}
## Start here.#####
SEL=$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS # Start here with right clicked file.
export SOUND=$HOME/Audio/2tone.wav
export -f gong
RM=$(pwd)
trap "killall ffmpeg; rm -f "$RM"/ffmpeg2pass*; exit" \
INT TERM EXIT
## Select file destination.
SAVEAS=$(zenity --file-selection --directory --title="$T1")
if [ "$?" = 1 ]; then
exit $?
fi
## Quality of re-code.
QUAL=$(zenity --title "NEW-AVI2MPG" --width 280 --height 200 --list \
--text "Select Re-code Mode" --radiolist --column \
"Select" --column "FFmpeg Options" TRUE 'Single Pass High'\
FALSE 'Single Pass Low' FALSE 'Two Pass');
if [ $? = 1 ]; then
exit $?
fi
## Make "for loop" handle filenames with spaces!!!!
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
## Loop through multiple file selections.
for FILE in $SEL; do
NFILE=$(basename "$FILE")
## TV format frame rate to FFmpeg friendly.
FPS=$(ffprobe "$FILE" 2>&1 | sed -n "s/.*, \(.*\) tbr.*/\1/p")
TFORM=$(echo "$FPS" |\
sed "s/25/pal-dvd/g; s/30/ntsc-dvd/g; s/29.98/ntsc-dvd/g;\
s/29.97/ntsc-dvd/g; s/23.98/ntsc-dvd -r 23.98/g;")
TFORM2=$(echo "$FPS" |\
sed "s/25/PAL @ 25fps/g; s/29.98/NTSC @ 29.98fps/g;\
s/29.97/NTSC @ 29.97fps/g; s/23.98/NTSC-Film @ 23.98fps/g;")
## FFmpeg options.
# Single pass implied vbr same quality as original.
HIGHBR="ffmpeg -i '$FILE'\
-target $TFORM\
-sameq\
'$SAVEAS/${NFILE%.*}.mpg'"
# Single pass low options.
LOWBR="ffmpeg -i '$FILE'\
-target $TFORM\
-b 2000k\
-acodec ac3\
-ar 48000\
-ab 96k\
'$SAVEAS/${NFILE%.*}.mpg'"
# Two pass options.
PASS1="ffmpeg -i '$FILE'\
-pass 1\
-target $TFORM\
-b 2600k\
-an\
-y\
/dev/null"
PASS2="ffmpeg -i '$FILE'\
-pass 2\
-target $TFORM\
-b 2600k\
-acodec ac3\
-ar 48000\
-ab 128k\
'$SAVEAS/${NFILE%.*}.mpg'"
## Determine quality then re-code to it.
if [ "$QUAL" = "Single Pass High" ]; then
METH="$QUAL"
OPT="$HIGHBR"
single_pass & wait
elif [ "$QUAL" = "Single Pass Low" ]; then
METH="$QUAL"
OPT="$LOWBR"
single_pass & wait
else
METH="Two Pass High"
two_pass
fi
done
Powered by ScribeFire.
Subscribe to:
Posts (Atom)