Skip to content

Instantly share code, notes, and snippets.

@shiouen
Last active October 24, 2024 21:01
Show Gist options
  • Select an option

  • Save shiouen/d13c716d7ce527731c43ab3532a68c04 to your computer and use it in GitHub Desktop.

Select an option

Save shiouen/d13c716d7ce527731c43ab3532a68c04 to your computer and use it in GitHub Desktop.
Guide: finding the shutter count on a Canon EOS 5D Mark IV

Requirements

  • Windows, Linux or macOS
  • The gphoto2 command (sudo apt-get install gphoto2, also available on brew)
  • A writable SD card in the SD slot

I made this guide based on Windows 11 / WSL2. macOS is untested.

Connecting the camera

The 5DM4 has a USB connection available. The cable provided with the camera will work best, but if you no longer have it you can use a micro USB cable just fine. I assume the smaller portion of the USB connector on the camera body is used to provide power, not data.

On Windows & WSL

My Windows recognized the device and connected it right away.

1. Open up powershell as administrator.

Run usbipd list

PS C:\Users\%user%> usbipd list
Connected:
BUSID  VID:PID    DEVICE                                                        STATE
...
1-5    <hex>:<hex>  Canon EOS 5D Mark IV                                        Not shared
...

Persisted:
GUID                                  DEVICE

The output should show you a list of connected USB devices. My camera was initially Not shared.

2. Attach the camera to WSL

Run usbipd attach -b 1-5 --wsl

usbipd: info: Using WSL distribution 'Ubuntu' to attach; the device will be available in all WSL 2 distributions.
usbipd: info: Using IP address <ip> to reach the host.

Now the camera should be available on WSL.

Test the connection

Run gphoto2 --auto-detect

Model                          Port
----------------------------------------------------------
Canon EOS 5D Mark IV           usb:001,009

Run sudo gphoto2 --summary

Camera summary:
Manufacturer: Canon.Inc
Model: Canon EOS 5D Mark IV
...
tons of properties
...

For some reason, some of gphoto2 subcommands required elevated permissions on my WSL Ubuntu install, your mileage may vary. I could not be bothered with finding out why.

Finding out the shutter count

1. Get a debug log before taking any pictures

Run sudo gphoto2 --debug --debug-logfile=before.log --list-config

This should output a log file in the current directory. The log file is full of hexadecimal byte code and hopefully, somewhere your shutter speed is set. Now go ahead and make 2-5 photos. I just took them with my lens cap on. Make sure you remember or write down the amount of photos you took, this is important later on.

Tip: I first took the photos without a writeable SD card, doing this however obfuscates the shutter count in the log file.

Turn your camera off, this gives the camera time to write a new log file. I had to wait until the sensor cleaning was done, the Windows USB disconnection sound rang and the screen on the camera turned off.

2. Get a debug log after taking the pictures

Turn your camera on and go through the connection processs again. Make sure to reattach the device to WSL if you are on Windows.

Run sudo gphoto2 --debug --debug-logfile=after.log --list-config

Now open the files and compare the two. Try to find a hexadecimal value that changed exactly with the amount of photos you took. For me personally, it was on line 1548, at offset 0x01d0 or just 01d0. I have that offset in my file several times, but this one specifically showed a change in hexadecimal that is equal to the amount of photos I took.

Before: 01d0 00 00 00 00 00 00 00 00-00 00 00 00 07 01 22 0b ..............".

I took 2 pictures...

After: 01d0 00 00 00 00 00 00 00 00-00 00 00 00 07 01 22 0d ..............".

d - b = 2. I assume this equals to a shutter count of 01 22 0d, which reads as 74253 in decimal.

I sincerely hope the 07 is not part of the number ;)

Good luck!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment