43 lines
1.4 KiB
Bash
43 lines
1.4 KiB
Bash
get_rotation_filter() {
|
||
local f="$1"
|
||
local rotation
|
||
rotation=$(exiftool -Rotation -n "$f" | awk '{print $3}')
|
||
case "$rotation" in
|
||
*) echo "transpose=1" ;;
|
||
esac
|
||
}
|
||
export -f get_rotation_filter
|
||
|
||
reencode_with_rotation() {
|
||
set -x
|
||
local src="$1"
|
||
local dst="$2"
|
||
local filter
|
||
filter="$(get_rotation_filter "$src")"
|
||
|
||
if [ -n "$filter" ]; then
|
||
#echo " Correction d’orientation (rotation=${filter})"
|
||
if ffmpeg -encoders 2>/dev/null | grep -q 'h264_videotoolbox'; then
|
||
ffmpeg -nostdin -i "$src" -vf "$filter" \
|
||
-c:v h264_videotoolbox -b:v 5M -c:a aac -map_metadata -1 -y "$dst"
|
||
else
|
||
ffmpeg -nostdin -i "$src" -vf "$filter" \
|
||
-c:v libx264 -preset fast -crf 18 -c:a aac -map_metadata -1 -y "$dst"
|
||
fi
|
||
else
|
||
# Pas de rotation → simple copie (ou réencodage minimal)
|
||
if ffmpeg -y -i "$src" -c copy -map 0 -movflags +faststart "$dst" < /dev/null 2>/dev/null; then
|
||
:
|
||
else
|
||
if ffmpeg -encoders 2>/dev/null | grep -q 'h264_videotoolbox'; then
|
||
ffmpeg -nostdin -i "$src" \
|
||
-c:v h264_videotoolbox -b:v 5M -c:a aac -map_metadata -1 -y "$dst"
|
||
else
|
||
ffmpeg -nostdin -i "$src" \
|
||
-c:v libx264 -preset fast -crf 18 -c:a aac -map_metadata -1 -y "$dst"
|
||
fi
|
||
fi
|
||
fi
|
||
set +x
|
||
}
|
||
export -f reencode_with_rotation |