80 lines
2.8 KiB
Bash
80 lines
2.8 KiB
Bash
#!/bin/bash
|
||
# run: sh ffmpeg-convertMP4v6.sh /volume1/video/TV_ts /volume1/video/TV
|
||
#v5: notifications, logs
|
||
#v6: modif date dans les logs
|
||
|
||
LOG=/volume1/homes/bruno/logs # dossier du fichier .log
|
||
ENREGISTREMENTS=/volume1/video/TV_2
|
||
# http://www.cyberciti.biz/faq/linux-unix-formatting-dates-for-display/
|
||
timestamp()
|
||
{
|
||
date +"%d-%m-%Y %T"
|
||
}
|
||
|
||
# création du fichier log
|
||
touch $LOG/ffmpeg.log
|
||
echo $(date +"%d-%m-%Y %T") "Demarrage du script" >> $LOG/ffmpeg.log
|
||
|
||
# Variables Section
|
||
#==============================================================
|
||
# list process to monitor in the variable below.
|
||
PROGRAM1=ffmpeg
|
||
# APPCHK varible checks to see if $PROGRAM1 is running.
|
||
APPCHK=$(ps -ea | grep $PROGRAM1 | grep -v grep | wc -l)
|
||
#==================================================================
|
||
# The ‘if’ statement below checks to see if the process is running
|
||
# with the ‘ps’ command. If the value is returned as a ‘0’ then
|
||
# a message is prompted
|
||
if [ $APPCHK -eq 0 ];
|
||
then
|
||
|
||
cd "$1"
|
||
for FILE in *;
|
||
do
|
||
|
||
#on supprime les espaces dans les noms de fichiers
|
||
RENAME=$(echo "$FILE" | sed -e 's/[[:blank:]]/_/g');
|
||
if [ -e "$RENAME" ];then
|
||
echo "">/dev/null;
|
||
else
|
||
mv "$FILE" "$RENAME";
|
||
fi
|
||
|
||
#on récupère le nom sans extension
|
||
NAME=$(echo "$RENAME" | sed 's/\.[^\.]*$//')
|
||
|
||
#nom des fichiers
|
||
INPUT_FILE="$1/$RENAME"
|
||
OUTPUT_FILE=$(echo "$2/$NAME.mp4")
|
||
|
||
#if [ "$NAME" != "@eaDir" -a ! -f "$OUTPUT_FILE" ];
|
||
if [ "$NAME" != "@eaDir" ];
|
||
then
|
||
|
||
echo "Conversion du fichier: $OUTPUT_FILE"
|
||
|
||
#echo "$JOUR Debut conversion du fichier $FILE" >> $LOG/ffmpeg.log
|
||
echo "$(date +"%d-%m-%Y %T") Debut conversion du fichier $FILE" >> $LOG/ffmpeg.log
|
||
|
||
#/volume1/homes/bruno/scripts/ffmpeg -i "$INPUT_FILE" -map 0:0 -map 0:1 -c:a aac -strict -2 -async 1 -c:v libx264 -crf 20 -r 25 -s 1920x1080 -aspect 16:9 -qmin 3 -qmax 51 -qdiff 4 -y "$OUTPUT_FILE"
|
||
/volume1/homes/bruno/scripts/ffmpeg -i "$INPUT_FILE" -map 0:0 -map 0:1 -c:a aac -b:a 160k -async 1 -c:v libx264 -crf 20 -r 25 -s 1280x720 -aspect 16:9 -y "$OUTPUT_FILE"
|
||
#les originaux sont déplacés dans $ENREGISTREMENTS
|
||
mv "$INPUT_FILE" "$ENREGISTREMENTS/"
|
||
|
||
#echo "$JOUR Conversion du fichier $NAME.mp4 terminee" >> $LOG/ffmpeg.log
|
||
echo "$(date +"%d-%m-%Y %T") Conversion du fichier $NAME.mp4 terminee" >> $LOG/ffmpeg.log
|
||
synodsmnotify @administrators "[ffmpeg-convertMP4.sh]" "Conversion du fichier $FILE terminee"
|
||
|
||
fi
|
||
|
||
done
|
||
else
|
||
#echo “$PROGRAM1 is running”
|
||
#echo "$JOUR $PROGRAM1 est deja actif" >> $LOG/ffmpeg.log
|
||
echo "$(date +"%d-%m-%Y %T") $PROGRAM1 est deja actif" >> $LOG/ffmpeg.log
|
||
synodsmnotify @administrators "[ffmpeg-convertMP4.sh]" "$PROGRAM1 est deja actif"
|
||
|
||
fi
|
||
#echo $JOUR "Fin du script" >> $LOG/ffmpeg.log
|
||
echo "$(date +"%d-%m-%Y %T") Fin du script" >> $LOG/ffmpeg.log
|
||
exit |