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.

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



Powered by ScribeFire.

No comments: