Bref, je fais un post propre pour cette version :
#!/bin/bash
PATH=$PATH:/sbin:/usr/sbin
#### Anonyme ###############################################################################
# 22-03-2019
# Archlinux
# MPlayer SVN-r38101
# ffmpeg version n4.1.1
# lsdvd 0.17
# ogmtools v1.5 (dvdxchap)
# mkvtoolnix-cli 32.0.0-1 (mkvmerge)
# mencoder-38125-5
##############################################################################################
declare -a MPLAYER_IDENTIFY
declare -a LSDVD_X
menage () {
rm -f "$FOLDER"/*.idx
rm -f "$FOLDER"/*.sub
rm -f "$FOLDER/$i-$TITLE+CHAPTERS.mkv"
}
mplayer_identify () {
if [[ "${#MPLAYER_IDENTIFY[@]}" -eq 0 ]]; then
mapfile MPLAYER_IDENTIFY < <(mplayer -vo null -ao null -frames 0 \
-identify dvd://"$1" -dvd-device "$DEVICE" 2>/dev/null)
fi
echo -n "${MPLAYER_IDENTIFY[@]}"
}
awk_lang () {
local ilang="$1"
local olang="$2"
awk "/language: $ilang/ && /format:/ \
{printf \"-metadata:s:a:\"\$3\" language=$olang -metadata:s:a:\"\$3\" title=\"\$5\$6\" \"}"
}
awk_lpcm () {
local ilang="$1"
local olang="$2"
awk "/language: $ilang/ && /format: lpcm/ \
{printf \"-metadata:s:a:0 language=$olang -metadata:s:a:0 title=\"\$5\$6\" \"}"
}
lsdvd_x () {
if [[ "${#LSDVD_X[@]}" -eq 0 ]]; then
mapfile LSDVD_X < <(lsdvd -x "$DEVICE" -t "$1" 2> /dev/null)
fi
echo -n "${LSDVD_X[@]}"
}
## CONDITION : UN SEUL DVD-VIDÉO
COUNT_DEVICE=$(blkid /dev/sr* | \
awk '{print $1}' | \
sed -e 's/://g' | \
awk '{x=x+NF}END{print x}')
if [[ "$COUNT_DEVICE" -eq "1" ]] ; then
echo "Proceed..."
else
echo "Aucun DVD-Vidéo ou 2 DVD-Vidéos/DVD-ROM ... dans différents lecteurs ?"
exit 0
fi
DEVICE=$(blkid /dev/sr* | awk '{print $1}' | sed -e 's/://g')
## LABEL DU DVD-VIDÉO & NOMBRE TOTAL DE TITRES SUR CELUI-CI
TITLE=$(lsdvd "$DEVICE" | head -1 | awk '{print $3}')
TITLE_COUNT=$(lsdvd "$DEVICE" | grep -c ^'Title: ')
DIR=$(xdg-user-dir DESKTOP)
FOLDER="$DIR/$TITLE"
if [ ! -d "$FOLDER" ]; then
echo "$FOLDER n'existe pas !"
echo "Création Du Dossier $FOLDER"
mkdir -p "$FOLDER"
fi
for (( i=1; i<=TITLE_COUNT; i++ ))
do
## METADATAS DIVERS [À COMPLETER AU CAS OÙ IL MANQUERAIT QUELQUES LANGUES]
## https://fr.wikipedia.org/wiki/Liste_des_codes_ISO_639-1
FR=$(mplayer_identify "$i" | awk_lang fr fra)
FR_LPCM=$(mplayer_identify "$i" | awk_lpcm fr fra)
EN=$(mplayer_identify "$i" | awk_lang en en)
EN_LPCM=$(mplayer_identify "$i" | awk_lpcm en en)
DE=$(mplayer_identify "$i" | awk_lang de ger)
DE_LPCM=$(mplayer_identify "$i" | awk_lpcm de ger)
IT=$(mplayer_identify "$i" | awk_lang it ita)
IT_LPCM=$(mplayer_identify "$i" | awk_lpcm it ita)
ES=$(mplayer_identify "$i" | awk '/language: es/ && /format:/ {printf "-metadata:s:a:"$3" language=spa -metadata:s:a:"$3" title="$5$6" "}')
ES_LPCM=$(mplayer_identify "$i" | awk '/language: es/ && /format: lpcm/ {printf "-metadata:s:a:0 language=spa -metadata:s:a:0 title="$5$6" "}')
NL=$(mplayer_identify "$i" | awk '/language: nl/ && /format:/ {printf "-metadata:s:a:"$3" language=nld -metadata:s:a:"$3" title="$5$6" "}')
NL_LPCM=$(mplayer_identify "$i" | awk '/language: nl/ && /format: lpcm/ {printf "-metadata:s:a:0 language=nld -metadata:s:a:0 title="$5$6" "}')
HE=$(mplayer_identify "$i" | awk '/language: he/ && /format:/ {printf "-metadata:s:a:"$3" language=heb -metadata:s:a:"$3" title="$5$6" "}')
HE_LPCM=$(mplayer_identify "$i" | awk '/language: he/ && /format: lpcm/ {printf "-metadata:s:a:0 language=heb -metadata:s:a:0 title="$5$6" "}')
HU=$(mplayer_identify "$i" | awk '/language: hu/ && /format:/ {printf "-metadata:s:a:"$3" language=hun -metadata:s:a:"$3" title="$5$6" "}')
HU_LPCM=$(mplayer_identify "$i" | awk '/language: hu/ && /format: lpcm/ {printf "-metadata:s:a:0 language=hun -metadata:s:a:0 title="$5$6" "}')
PL=$(mplayer_identify "$i" | awk '/language: pl/ && /format:/ {printf "-metadata:s:a:"$3" language=pol -metadata:s:a:"$3" title="$5$6" "}')
PL_LPCM=$(mplayer_identify "$i" | awk '/language: pl/ && /format: lpcm/ {printf "-metadata:s:a:0 language=pol -metadata:s:a:0 title="$5$6" "}')
CS=$(mplayer_identify "$i" | awk '/language: cs/ && /format:/ {printf "-metadata:s:a:"$3" language=cze -metadata:s:a:"$3" title="$5$6" "}')
CS_LPCM=$(mplayer_identify "$i" | awk '/language: cs/ && /format: lpcm/ {printf "-metadata:s:a:0 language=cze -metadata:s:a:0 title="$5$6" "}')
JA=$(mplayer_identify "$i" | awk '/language: ja/ && /format:/ {printf "-metadata:s:a:"$3" language=jpn -metadata:s:a:"$3" title="$5$6" "}')
JA_LPCM=$(mplayer_identify "$i" | awk '/language: ja/ && /format: lpcm/ {printf "-metadata:s:a:0 language=jpn -metadata:s:a:0 title="$5$6" "}')
SV=$(mplayer_identify "$i" | awk '/language: sv/ && /format:/ {printf "-metadata:s:a:"$3" language=swe -metadata:s:a:"$3" title="$5$6" "}')
SV_LPCM=$(mplayer_identify "$i" | awk '/language: sv/ && /format: lpcm/ {printf "-metadata:s:a:0 language=swe -metadata:s:a:0 title="$5$6" "}')
UNKNOWN=$(mplayer_identify "$i" | awk '/language: unknown/ && /format:/ {printf "-metadata:s:a:"$3" language=und -metadata:s:a:"$3" title="$5$6" "}')
UNKNOWN_LPCM=$(mplayer_identify "$i" | awk '/language: unknown/ && /format: lpcm/ {printf "-metadata:s:a:0 language=und -metadata:s:a:0 title="$5$6" "}')
EMPTY_LANG=$(mplayer_identify "$i" | awk '(/language: aid:/) && /format:/ {printf "-metadata:s:a:"$3" language=und -metadata:s:a:"$3" title="$5$6" "}')
EMPTY_LANG_LPCM=$(mplayer_identify "$i" | awk '(/language: aid:/) && /format: lpcm/ {printf "-metadata:s:a:0 language=und -metadata:s:a:0 title="$5$6" "}')
TAGS_ID_STREAMS="${FR}${EN}${DE}${IT}${ES}${NL}${HE}${HU}${PL}${CS}${JA}${SV}${UNKNOWN}${EMPTY_LANG}"
TAGS_ID_STREAMS_LPCM="${FR_LPCM}${EN_LPCM}${DE_LPCM}${IT_LPCM}${ES_LPCM}${NL_LPCM}${HE_LPCM}${HU_LPCM}${PL_LPCM}${CS_LPCM}${JA_LPCM}${SV_LPCM}${UNKNOWN_LPCM}${EMPTY_LANG_LPCM}"
## TITRES D'UNE DURÉE DE PLUS DE .... SECONDES [ ICI, 1200 SECONDES = 20 MINUTES]
LIMIT_TIME=$(mplayer_identify "$i" | grep ID_LENGTH | sed 's/.*=\([0-9]*\)/\1/' | sed "s/\\..*//")
B=1200
if [[ "$LIMIT_TIME" -gt "$B" ]]; then
mplayer -identify -dvd-device "$DEVICE" dvd://"$i" \
-nocache -dumpstream -dumpfile "$FOLDER/$i-$TITLE.vob"
## DISNEY A-R-C-C-O-S
#mplayer dvdnav://"$i" -dvd-device "$DEVICE" -dumpstream -dumpfile "$i-$TITLE.vob"
COUNT_LPCM=$(lsdvd_x "$i" |grep 'lpcm' | awk '{print$8}' | \
awk '{x=x+NF}END{print x}')
COUNT_AC3_DTS_MPEG1=$(lsdvd_x "$i" | grep 'ac3,\|dts,\|mpeg1,' | \
awk '{print$8}' |awk '{x=x+NF}END{print x}')
# MAP_ID_STREAMS=( $(lsdvd_x "$i" |grep "Audio:" | \
# sed -n -e 's/.*\(0x\)/\1/p' |sed -e 's/c/1c/g' | \
# awk '/0x/{gsub (/^/,"-map i:")}1') )
read -r -a MAP_ID_STREAMS < <(lsdvd_x "$i" |grep "Audio:" | \
sed -n -e 's/.*\(0x\)/\1/p' |sed -e 's/c/1c/g' | \
awk '/0x/{gsub (/^/,"-map i:")}1')
# MAP_ID_STREAMS_LPCM=$(lsdvd_x "$i" |grep 'lpcm' | \
# sed -n -e 's/.*\(0x\)/\1/p' | sed -e 's/c/1c/g' | \
# awk '/0x/{gsub (/^/,"-map i:")}1')
read -r -a MAP_ID_STREAMS_LPCM < <(lsdvd_x "$i" |grep 'lpcm' | \
sed -n -e 's/.*\(0x\)/\1/p' | sed -e 's/c/1c/g' | \
awk '/0x/{gsub (/^/,"-map i:")}1')
SIDFR=$(lsdvd_x "$i" | grep "Subtitle:" | grep "Language: fr" | \
awk '{print$2}' | sed s'/.$//' | \
awk 'BEGIN { RS="[^0-9]"; OFS=""; ORS=""; } {if(length($0)) {print ($0-1);}print RT}')
COUNT_SID_FR=$(mplayer_identify "$i" | \
grep "subtitle ( sid ):" | grep "language: fr" | \
awk '{print$7}' | awk '{x=x+NF}END{print x}')
RATIO=$(lsdvd_x "$i" | head -3 | grep "Aspect ratio:" | \
awk '{print$11}' | sed '$ s/.$//' | sed 's/\//:/')
#CROP=$(ffmpeg -i "$FOLDER/$i-$TITLE.vob" -ss 60 -t 15 -t 1 -vf cropdetect -f null - 2>&1 | awk '/crop/ { print $NF }' | tail -1)
INFO_AC3_DTS_MPEG1=$(lsdvd_x "$i" |awk '/ac3,/ {printf ""$4","}' | \
sed -e 's/,*$//g')
INFO_LPCM=$(lsdvd_x "$i" |awk '/ac3,/ {printf ""$4","}' | \
sed -e 's/,*$//g')
## ENCODAGE
## GPU
## FILMS
## AC3 & DTS & MPEG1
## SOUS-TITRAGE(S) VF
if [[ "$COUNT_LPCM" -eq "0" ]] && \
[[ "$COUNT_AC3_DTS_MPEG1" -ge "1" ]] && \
[[ "$COUNT_SID_FR" -ge "1" ]]
then
ffmpeg -hwaccel auto -c:v mpeg2_cuvid -i "$FOLDER/$i-$TITLE.vob" \
-map 0:v -metadata title="$TITLE" \
-c:v h264_nvenc -preset slow -profile:v high -level 4.2 \
-loglevel repeat+verbose "${MAP_ID_STREAMS[@]}" \
-c:a copy ${TAGS_ID_STREAMS} -movflags +faststart -qmin 18 -qmax 23 \
-filter:v hue=b=0.1:s=0.7,hqdn3d=1.5:1.5:4:4,unsharp=luma_msize_x=5:luma_msize_y=5:luma_amount=0.5,noise=c0s=2:c1s=2:c2s=2:c0f=a+t \
-y "$FOLDER/$i-$TITLE.mkv"
rm -f "$FOLDER/$i-$TITLE.vob"
dvdxchap -t "$i" "$DEVICE" > "$FOLDER/$i-$TITLE-CHAPTERS.txt"
mkvmerge "$FOLDER/$i-$TITLE.mkv" --chapters "$FOLDER/$i-$TITLE-CHAPTERS.txt" \
-o "$FOLDER/$i-$TITLE+CHAPTERS.mkv"
rm -f "$FOLDER/$i-$TITLE-CHAPTERS.txt"
rm -f "$FOLDER/$i-$TITLE.mkv"
for n in $SIDFR; do
mencoder -dvd-device "$DEVICE" "dvd://$i" \
-nosound -ovc copy -force-avi-aspect "$RATIO" \
-o /dev/null -ifo "/run/media/$USER/$TITLE/VIDEO_TS/VTS_01_0.IFO" \
-sid "$n" -vobsubout "$FOLDER/$i-vobsubs-fr" -vobsuboutindex "$n"
done
mkvmerge "$FOLDER/$i-$TITLE+CHAPTERS.mkv" -a fre --default-language fr \
"$FOLDER"/*.idx \
-o "$FOLDER/$i-$TITLE-[Language:$INFO_AC3_DTS_MPEG1]+SUBVF.mkv"
menage
## ENCODAGE
## GPU
## CONCERTS LIVE
## LPCM (ON GARDE QUE LA PISTE LPCM)
## PAS DE SOUS-TITRAGE
elif [[ "$COUNT_LPCM" -ge "1" ]] && \
[[ "$COUNT_AC3_DTS_MPEG1" -ge "0" ]] && \
[[ "$COUNT_SID_FR" -eq "0" ]]
then
ffmpeg -hwaccel auto -c:v mpeg2_cuvid -i "$FOLDER/$i-$TITLE.vob" \
-map 0:v -metadata title="$TITLE" -c:v h264_nvenc -preset hq \
-profile:v high -level 4.2 -loglevel repeat+verbose \
"${MAP_ID_STREAMS_LPCM[@]}" -acodec pcm_s16be ${TAGS_ID_STREAMS_LPCM} \
-movflags +faststart -qmin 18 -qmax 23 -y "$FOLDER/$i-$TITLE.mkv"
rm -f "$FOLDER/$i-$TITLE.vob"
dvdxchap -t "$i" "$DEVICE" > "$FOLDER/$i-$TITLE-CHAPTERS.txt"
mkvmerge "$FOLDER/$i-$TITLE.mkv" --chapters "$FOLDER/$i-$TITLE-CHAPTERS.txt" \
-o "$FOLDER/$i-$TITLE-[Language:$INFO_LPCM].mkv"
rm -f "$FOLDER/$i-$TITLE.mkv"
rm -f "$FOLDER/$i-$TITLE-CHAPTERS.txt"
## ENCODAGE
## GPU
## CONCERTS LIVE
## LPCM (ON GARDE QUE LA PISTE LPCM)
## SOUS-TITRAGE(S) VF
elif [[ "$COUNT_LPCM" -ge "1" ]] && \
[[ "$COUNT_AC3_DTS_MPEG1" -ge "0" ]] && \
[[ "$COUNT_SID_FR" -ge "1" ]]
then
ffmpeg -hwaccel cuvid -c:v mpeg2_cuvid -i "$FOLDER/$i-$TITLE.vob" \
-map 0:v -metadata title="$TITLE" \
-c:v h264_nvenc -preset hq -profile:v high -level 4.2 \
-loglevel repeat+verbose "${MAP_ID_STREAMS_LPCM[@]}" \
-acodec pcm_s16be ${TAGS_ID_STREAMS_LPCM} -movflags +faststart \
-qmin 18 -qmax 23 -y "$FOLDER/$i-$TITLE.mkv"
rm -f "$FOLDER/$i-$TITLE.vob"
dvdxchap -t "$FOLDER/$i" "$DEVICE" > "$FOLDER/$i-$TITLE-CHAPTERS.txt"
mkvmerge "$FOLDER/$i-$TITLE.mkv" --chapters "$FOLDER/$i-$TITLE-CHAPTERS.txt" \
-o "$FOLDER/$i-$TITLE+CHAPTERS.mkv"
rm -f "$FOLDER/$i-$TITLE-CHAPTERS.txt"
rm -f "$FOLDER/$i-$TITLE.mkv"
for n in $SIDFR; do
mencoder -dvd-device "$DEVICE" dvd://"$i" \
-nosound -ovc copy -force-avi-aspect "$RATIO" \
-o /dev/null -ifo "/run/media/$USER/$TITLE/VIDEO_TS/VTS_01_0.IFO" \
-sid "$n" -vobsubout "$FOLDER/$i-vobsubs-fr" -vobsuboutindex "$n"
done
mkvmerge "$FOLDER/$i-$TITLE+CHAPTERS.mkv" \
-a fre --default-language fr "$FOLDER"/*.idx \
-o "$FOLDER/$i-$TITLE-[Language:$INFO_LPCM]+SUBVF.mkv"
menage
## LA PETITE MAISON DANS LA PRAIRIE
elif [[ "$COUNT_LPCM" -eq "0" ]] &&
[[ "$COUNT_AC3_DTS_MPEG1" -ge "1" ]] &&
[[ "$COUNT_SID_FR" -eq "0" ]]
then
ffmpeg -hwaccel auto -c:v mpeg2_cuvid \
-i "$FOLDER/$i-$TITLE.vob" -map 0:v -metadata title="$TITLE" \
-c:v h264_nvenc -preset hq -profile:v high -level 4.2\
-loglevel repeat+verbose "${MAP_ID_STREAMS[@]}" \
-c:a copy ${TAGS_ID_STREAMS} -movflags +faststart \
-qmin 18 -qmax 23 -y "$FOLDER/$i-$TITLE.mkv"
rm -f "$FOLDER/$i-$TITLE.vob"
dvdxchap -t "$i" "$DEVICE" > "$FOLDER/$i-$TITLE-CHAPTERS.txt"
mkvmerge "$FOLDER/$i-$TITLE.mkv" \
--chapters "$FOLDER/$i-$TITLE-CHAPTERS.txt" -o \
"$FOLDER/$i-$TITLE-[Language:$INFO_AC3_DTS_MPEG1].mkv"
rm -f "$FOLDER/$i-$TITLE-CHAPTERS.txt"
rm -f "$FOLDER/$i-$TITLE.mkv"
fi
fi
done
Et voilà. Il avait juste un « sed - » qui était passé à trappe
Dans ce script, j'ai fait les modifications dont je parlais dans le
post #66 pour les fonctions mplayer_identify et lsdvd_x. Du coup le
script devrait être plus rapide. Et ça fera moins d'accès au lecteur
dvd.
À présent je me demande si on ne peut pas optimiser ce qui se passe
ici :
SIDFR=$(lsdvd_x "$i" | grep "Subtitle:" | grep "Language: fr" | \
awk '{print$2}' | sed s'/.$//' | \
awk 'BEGIN { RS="[^0-9]"; OFS=""; ORS=""; } {if(length($0)) {print ($0-1);}print RT}')
COUNT_SID_FR=$(mplayer_identify "$i" | \
grep "subtitle ( sid ):" | grep "language: fr" | \
awk '{print$7}' | awk '{x=x+NF}END{print x}')
Parce que si COUNT_SID_FR, c'est juste le nombre de chaîne dans SIDFR
c'est facile à compter. Pour la variable SIDFR on pourrait aussi
utiliser un tableau…
Dernière modification par enicar (10-06-2019 16:15:10)