convert heic functional script w docker

add docker for new magic version on ubuntu 24
This commit is contained in:
Lucas Serverhost authored and Lucas Vivohost committed 2026-09-14 12:43:38 +02:00
1 parent 14c7e69172
commit f27c172a73
4 files changed
+168 -62

No files matched your search

+68 -23
View File
@@ -18,16 +18,35 @@ convert_one() {
echo "Converting: $src"
# Convert HEIC -> JPEG
if ! magick "$src" \
if command -v magick >/dev/null 2>&1; then
if ! magick "$src" \
-auto-orient \
-quality 100 \
-sampling-factor 4:4:4 \
"jpg:$tmp"; then
echo "ERROR: local conversion failed: $src"
rm -f "$tmp"
return 1
fi
else
if ! docker run --rm \
-u "$(id -u):$(id -g)" \
-v "$PWD:/work" \
-w /work \
--entrypoint magick \
dpokidov/imagemagick \
"$src" \
-auto-orient \
-quality 100 \
-sampling-factor 4:4:4 \
"jpg:$tmp"; then
echo "ERROR: conversion failed: $src"
rm -f "$tmp"
return 1
"jpg:$tmp"; then
echo "ERROR: docker conversion failed: $src"
rm -f "$tmp"
return 1
fi
fi
if [[ ! -s "$tmp" ]]; then
echo "ERROR: output JPEG is empty: $tmp"
rm -f "$tmp"
@@ -76,20 +95,20 @@ convert_mov() {
echo "Converting: $src"
# MOV -> MP4, keep video/audio, drop unsupported data streams
if ! ffmpeg \
-hide_banner \
-loglevel error \
-i "$src" \
-map 0:0 \
-map 0:1 \
-map_metadata 0 \
-c copy \
-movflags use_metadata_tags+faststart \
"$tmp"; then
echo "ERROR: conversion failed: $src"
rm -f "$tmp"
return 1
fi
if ! ffmpeg \
-hide_banner \
-loglevel error \
-i "$src" \
-map 0:0 \
-map 0:1 \
-map_metadata 0 \
-c copy \
-movflags use_metadata_tags+faststart \
"$tmp"; then
echo "ERROR: conversion failed: $src"
rm -f "$tmp"
return 1
fi
if [[ ! -s "$tmp" ]]; then
echo "ERROR: output MP4 is empty: $tmp"
@@ -140,17 +159,43 @@ process_file() {
}
HOSTNAME_EXPECTED="serverhost"
SOURCE_DIR="/torrent/alina/Dropfolder"
TARGET_DIR="/torrent/camera"
# If running on serverhost, perform initial sync
if [[ "$(hostname)" == "$HOSTNAME_EXPECTED" ]]; then
/home/lucas/scripts/serverhost/syncNC.sh -d -c
cd "$SOURCE_DIR" || exit 1
fi
if [[ $# -gt 0 ]]; then
process_file "$1"
else
shopt -s nullglob
files=( *.heic *.mov )
if [[ ${#files[@]} -eq 0 ]]; then
echo "No HEIC or MOV files found."
exit 0
else
for f in "${files[@]}"; do
process_file "$f"
done
fi
fi
for f in "${files[@]}"; do
process_file "$f"
# Run sync again if on serverhost
if [[ "$(hostname)" == "$HOSTNAME_EXPECTED" ]]; then
shopt -s nullglob
for ext in jpg mp4; do
files=("$SOURCE_DIR"/*."$ext")
if ((${#files[@]})); then
mv -n "${files[@]}" "$TARGET_DIR"/
fi
done
fi
shopt -u nullglob
/home/lucas/scripts/serverhost/syncNC.sh -d -c
fi