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:
|
1 2 3 4 5 6 7 8 |
# 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 available exiftool P7120919.JPG | grep -i bracket exiftool P7120919.JPG | grep -i focus exiftool P7120919.JPG | grep -i sequence |
I 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 shutter
Claude 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:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
P7120857.JPG P7120857.ORF P7120858.JPG P7120858.ORF P7120859.JPG P7120859.ORF P7120860.JPG P7120860.ORF P7120861.JPG P7120861.ORF P7120863.JPG P7120863.ORF P7120864.JPG P7120864.ORF P7120865.JPG P7120865.ORF |
Into this:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
├── 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.ORF |
Implementing
- 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.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
#!/bin/bash # Analyze focus bracket sequences (dry run) analyze_focus_brackets() { echo "=== Focus Bracket Analysis ===" echo local series_num=1 local prev_shot_num=999 local series_files=() # Sort by filename (chronological order) instead of modification time for file in $(ls P*.ORF P*.JPG 2>/dev/null | sort); do [[ -f "$file" ]] || continue # Get both drive mode and timestamp for verification drive_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]+) ]]; then shot_num="${BASH_REMATCH[1]}" echo " Found shot number: $shot_num" # If shot number reset (went backwards), we found a new series if [[ $shot_num -lt $prev_shot_num ]]; then if [[ ${#series_files[@]} -gt 0 ]]; then echo "Series $((series_num-1)): ${#series_files[@]} shots" printf " %s\n" "${series_files[@]}" echo fi series_files=() echo "--- Starting Series $series_num ---" ((series_num++)) fi series_files+=("$file (Shot $shot_num, $timestamp)") prev_shot_num=$shot_num else echo " Not a focus bracket shot, skipping" fi done # Print final series if [[ ${#series_files[@]} -gt 0 ]]; then echo "Series $((series_num-1)): ${#series_files[@]} shots" printf " %s\n" "${series_files[@]}" fi echo echo "Total series found: $((series_num-1))" } # Function to actually move files after confirmation move_focus_brackets() { echo "Moving files to series folders..." local series_num=1 local prev_shot_num=999 for file in $(ls P*.ORF P*.JPG 2>/dev/null | sort); do [[ -f "$file" ]] || continue drive_mode=$(exiftool -DriveMode -T "$file" 2>/dev/null) if [[ "$drive_mode" =~ "Focus Bracketing, Shot "([0-9]+) ]]; then shot_num="${BASH_REMATCH[1]}" if [[ $shot_num -lt $prev_shot_num ]]; then ((series_num++)) fi series_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_num fi done } # Run analysis first analyze_focus_brackets echo read -p "Proceed with moving files? (y/N): " -n 1 -r echo if [[ $REPLY =~ ^[Yy]$ ]]; then move_focus_brackets echo "Done!" else echo "Aborted. Files not moved." fi |