So I made this bash script with gemini which is supposed to convert all images in the specified folder to avif and all videos to a matroshka file using avi encoding. However, when I run it, it just doesn't give me any output / logs in the terminal whatsoever and it's done after 0 secs. And the destination folder is empty of course.
#[SOLVED] need support with bash script.
17 messages · Page 1 of 1 (latest)
#!/bin/bash
# Set the source and destination directories
source_dir="/home/bl4ze/Downloads/immich"
dest_dir="/home/bl4ze/Downloads/immich2"
# Find all files in the source directory
find "$source_dir" -type f -print0 | while read -rd '\0' file; do
echo "Processing file: $file"
# Check if the file is an image or video
if [[ "$file" =~ \.(jpg|jpeg|png|webp|gif|bmp|tiff|mp4|mov|avi|mkv|flv|mpeg|mpg)$ ]]; then
# Convert the file to AVIF or Matroshka based on its type
if [[ "$file" =~ \.(jpg|jpeg|png|webp|gif|bmp|tiff)$ ]]; then
echo "Converting image: $file"
convert_image "$file"
else
echo "Converting video: $file"
convert_video "$file"
fi
fi
done
# Function to convert images to AVIF
convert_image() {
file="$1"
new_file="${dest_dir}/${file}"
# Check if the file is an image
if [[ -f "$file" ]] && [[ -r "$file" ]] && [[ -x "$file" ]] && [[ "$file" =~ \.(jpg|jpeg|png|webp|gif|bmp|tiff)$ ]]; then
echo "Converting image to AVIF: $file"
magick convert "$file" -set EXIF:* c -define formats:write_exif=true -quality 100 -colorspace sRGB "$new_file.avif"
echo "Moving original file to $new_file.avif"
mv "$file" "$new_file.avif"
fi
}
# Function to convert videos to Matroshka
convert_video() {
file="$1"
new_file="${dest_dir}/${file}"
# Check if the file is a video
if [[ -f "$file" ]] && [[ -r "$file" ]] && [[ -x "$file" ]] && [[ "$file" =~ \.(mp4|mov|avi|mkv|flv|mpeg|mpg)$ ]]; then
echo "Converting video to Matroshka: $file"
ffmpeg -i "$file" -c:v libx264 -crf 23 -c:a aac -b:a 128k -movflags faststart -metadata title="My Video Title" -metadata artist="John Doe" "$new_file.mkv"
echo "Moving original file to $new_file.mkv"
mv "$file" "$new_file.mkv"
fi
}
DId chat gpt write this?
hello
It did
I fixed it
... solved
#9742 📣 If there is nothing else that we can do for you, please close this thread by adding "[SOLVED]" to the title.
- You can do this on desktop by clicking the three dots on the top right of the page, and pressing "Edit Post".
- You can also do this on Android / iOS by long tapping your post in the text channel list, and tapping "Edit Post".
Your title should be like so: https://cdn.discordapp.com/attachments/503224329191030787/1039841700417384498/image.png
Thank you
also, i recommend distotube's playlist of bash scripting, haven't watched it, but i think it's good. it's also not that long.
i always think about learning bash scripting but i'm tooooo lazy
I know enough to get by and rice