Created
March 25, 2013 16:48
-
-
Save danixland/5238593 to your computer and use it in GitHub Desktop.
psp video maker, a shell script that converts videos for the psp using ffmpeg.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
##### EXIT STATUS ##### | |
E_INTERROR=71 | |
E_NOINPUTVIDEOT=72 | |
E_ALREADYTHM=73 | |
E_NOSEC=74 | |
E_NOINPUTVIDEOV=75 | |
E_NOOUTPUTVID=76 | |
E_NOOPT=77 | |
E_HELP=78 | |
E_COMMNOTFOUND=79 | |
##### FUNZIONI ##### | |
# showerror | |
showerror () | |
{ | |
if [ -z $1 ];then | |
echo "INTERNAL ERROR - ABORTING" | |
exit $E_INTERROR | |
fi | |
case $1 in | |
01) | |
echo "non hai indicato un video da cui prendere l'anteprima o il video \"$INPUT_VIDEO\" non esiste" | |
exit $E_NOINPUTVIDEOT | |
;; | |
02) | |
echo "il file di output \"$THUMBNAME.thm\" esiste già" | |
exit $E_ALREADYTHM | |
;; | |
03) | |
echo "non hai indicato il secondo da cui prendere il fotogramma per l'anteprima" | |
exit $E_NOSEC | |
;; | |
04) | |
echo "non hai indicato un video da convertire o il video \"$INPUT_VIDEO\" non esiste" | |
exit $E_NOIMPUTVIDEOV | |
;; | |
05) | |
echo "non hai indicato un nome per creare il video di output o \"$OUTPUT_VIDEO.mp4\" esiste già" | |
exit $E_NOOUTPUTVID | |
;; | |
06) | |
echo "non hai specificato nessuna opzione" | |
showhelp | |
exit $E_NOOPT | |
;; | |
esac | |
} | |
# showhelp | |
showhelp () | |
{ | |
echo -e "USO: $(basename $0) <option> [input video name.ext] [time] [output video name]" | |
echo -e "\tdove <option> è una tra:";echo | |
echo -e "\t-v | --video\tconverte il video [input video name.ext] nel video [output video name].mp4" | |
echo -e "\t\t\tl'opzione richiede 2 nomi, il primo deve essere il video da convertire, il secondo" | |
echo -e "\t\t\tè il nome del video risultante (senza l'estensione)" | |
echo -e "\t-t | --thumb\testrae un'anteprima dal video e la salva con lo stesso nome del file di" | |
echo -e "\t\t\torigine ma con estensione .thm per poter essere letta dalla psp. Richiede il nome" | |
echo -e "\t\t\tdel file di origine e il tempo, espresso in secondi, da cui estrarre l'immagine." | |
echo | |
echo -e "ESEMPI:" | |
echo -e "$(basename $0) --video /home/danix/completa_attenzione.avi completa_attenzione" | |
echo | |
echo -e "$(basename $0) --thumb /home/danix/completa_attenzione.mp4 22" | |
echo | |
} | |
##### MAIN ##### | |
if [ $# -eq 0 ];then | |
showerror 06 | |
#echo "showerror(06)" | |
else | |
while [ $# -gt 0 ];do | |
case $1 in | |
-t|--thumb) | |
INPUT_VIDEO=$2 | |
SECOND=$3 | |
#NAME=$(echo $INPUT_VIDEO|sed -re "s/(.*\/)(.*.[amf][vlp][igv4])$/\2/") | |
#THUMBNAME=${NAME%[amf][vlp][igv4]}thm | |
THUMBNAME=$(echo $INPUT_VIDEO | rev | cut -f 2 -d .| rev) | |
shift | |
if [[ -z $INPUT_VIDEO || ! -f $INPUT_VIDEO ]];then | |
showerror 01 | |
#echo "showerror(01)" | |
#exit 1 | |
elif [[ -f $THUMBNAME.thm ]];then | |
showerror 02 | |
#echo "showerror(02)" | |
#exit 1 | |
elif [ -z $SECOND ];then | |
showerror 03 | |
#echo "showerror(03)" | |
#exit 1 | |
fi | |
ffmpeg -y -i $INPUT_VIDEO -f image2 -ss $SECOND -vframes 1 -s 160×120 -an $THUMBNAME.thm | |
exit 0 | |
;; | |
-v|--video) | |
INPUT_VIDEO=$2 | |
OUTPUT_VIDEO=$3 | |
shift | |
if [[ -z $INPUT_VIDEO || ! -f $INPUT_VIDEO ]];then | |
showerror 04 | |
#echo "showerror(04)" | |
#exit 1 | |
elif [[ -z $OUTPUT_VIDEO || -f ${OUTPUT_VIDEO}.mp4 ]];then | |
showerror 05 | |
#echo "showerror(05)" | |
#exit 1 | |
fi | |
ffmpeg -i $INPUT_VIDEO -f psp -r 29.97 -b 768k -ar 24000 -ab 64k -s 320x240 $OUTPUT_VIDEO.mp4 | |
exit 0 | |
;; | |
-h|--help) | |
showhelp | |
exit $E_HELP | |
;; | |
*) | |
showhelp | |
exit $E_COMMNOTFOUND | |
;; | |
esac | |
shift | |
done | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm no longer using the psp, but I thought you could make use of this little script somehow.. :) enjoy!!