-
Grouping Focus Bracketed Photos from an OM-1 Mark 2
The Problem
I have a folder of image (JPG and RAW) files of some focus bracketed shots from my OM-1 Mark 2. I need to find a way to group them… maybe there is exif data that’d help? Or maybe I can use bash to group by timestamp to find all shots within 1 second of the previous shot… if the gap is more than 1 second then it starts a new “series”.
That was my prompt for Claude.
Claude suggested I try this first, to see what’s available:
12345678# Install exiftool if you don't have it# brew install exiftool # macOS# sudo apt install libimage-exiftool-perl # Ubuntu/Debian# Check what EXIF data is availableexiftool P7120919.JPG | grep -i bracketexiftool P7120919.JPG | grep -i focusexiftool P7120919.JPG | grep -i sequenceI ran the commands and replied:
Ooh good news. There appears to be some metadata in both JPG and ORF files.
Focus Bracket Step Size : 5
White Balance Bracket : 0 0
Drive Mode : Focus Bracketing, Shot 7; Electronic shutterClaude then gave me a bash script. I made a few tweaks, re-prompted, made some tweaks, then it was done.
It turns this flat folder of files:
12345678910111213141516P7120857.JPGP7120857.ORFP7120858.JPGP7120858.ORFP7120859.JPGP7120859.ORFP7120860.JPGP7120860.ORFP7120861.JPGP7120861.ORFP7120863.JPGP7120863.ORFP7120864.JPGP7120864.ORFP7120865.JPGP7120865.ORFInto this:
123456789101112131415161718├── focus_bracket_series_1│ ├── P7120857.JPG│ ├── P7120857.ORF│ ├── P7120858.JPG│ ├── P7120858.ORF│ ├── P7120859.JPG│ ├── P7120859.ORF│ ├── P7120860.JPG│ ├── P7120860.ORF│ ├── P7120861.JPG│ └── P7120861.ORF├── focus_bracket_series_2│ ├── P7120863.JPG│ ├── P7120863.ORF│ ├── P7120864.JPG│ ├── P7120864.ORF│ ├── P7120865.JPG│ ├── P7120865.ORFImplementing
- Write this script somewhere (e.g., ~/scripts/om1-focus-bracket-grouper.sh )
- Make it executable ( chmod +x om1-focus-bracket-grouper.sh )
- Go into the flat folder (e.g., cd ~/Pictures/MacroShots )
- Run it ( ~/scripts/om1-focus-bracket-grouper.sh )
- It will show you what the results will be and then prompt you to hit Y to move the files or N to abort.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697#!/bin/bash# Analyze focus bracket sequences (dry run)analyze_focus_brackets() {echo "=== Focus Bracket Analysis ==="echolocal series_num=1local prev_shot_num=999local series_files=()# Sort by filename (chronological order) instead of modification timefor file in $(ls P*.ORF P*.JPG 2>/dev/null | sort); do[[ -f "$file" ]] || continue# Get both drive mode and timestamp for verificationdrive_mode=$(exiftool -DriveMode -T "$file" 2>/dev/null)timestamp=$(exiftool -DateTimeOriginal -d "%Y-%m-%d %H:%M:%S" -T "$file" 2>/dev/null)echo "Processing: $file - Drive Mode: '$drive_mode'"if [[ "$drive_mode" =~ "Focus Bracketing, Shot "([0-9]+) ]]; thenshot_num="${BASH_REMATCH[1]}"echo " Found shot number: $shot_num"# If shot number reset (went backwards), we found a new seriesif [[ $shot_num -lt $prev_shot_num ]]; thenif [[ ${#series_files[@]} -gt 0 ]]; thenecho "Series $((series_num-1)): ${#series_files[@]} shots"printf " %s\n" "${series_files[@]}"echofiseries_files=()echo "--- Starting Series $series_num ---"((series_num++))fiseries_files+=("$file (Shot $shot_num, $timestamp)")prev_shot_num=$shot_numelseecho " Not a focus bracket shot, skipping"fidone# Print final seriesif [[ ${#series_files[@]} -gt 0 ]]; thenecho "Series $((series_num-1)): ${#series_files[@]} shots"printf " %s\n" "${series_files[@]}"fiechoecho "Total series found: $((series_num-1))"}# Function to actually move files after confirmationmove_focus_brackets() {echo "Moving files to series folders..."local series_num=1local prev_shot_num=999for file in $(ls P*.ORF P*.JPG 2>/dev/null | sort); do[[ -f "$file" ]] || continuedrive_mode=$(exiftool -DriveMode -T "$file" 2>/dev/null)if [[ "$drive_mode" =~ "Focus Bracketing, Shot "([0-9]+) ]]; thenshot_num="${BASH_REMATCH[1]}"if [[ $shot_num -lt $prev_shot_num ]]; then((series_num++))fiseries_dir="focus_bracket_series_$((series_num-1))"mkdir -p "$series_dir"echo "Moving $file to $series_dir"mv "$file" "$series_dir/"prev_shot_num=$shot_numfidone}# Run analysis firstanalyze_focus_bracketsechoread -p "Proceed with moving files? (y/N): " -n 1 -rechoif [[ $REPLY =~ ^[Yy]$ ]]; thenmove_focus_bracketsecho "Done!"elseecho "Aborted. Files not moved."fi -
-