extract Exif.CanonFi.FileNumber metadata

Bug #754531 reported by Ech on 2011-04-08
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Rapid Photo Downloader

Bug Description

A new kind of "part" for rename format would be great:
The possibility to use any exif tag as rename part would be really usefull ( ex: filenumber for canon camera)

See https://bugs.launchpad.net/rapid/+bug/511646/comments/3

Related branches

Ech (ech1965) on 2011-04-08
description: updated
Ech (ech1965) wrote :

I spoted the source file where the actual renaming takes place, but I'm still looking for the location of the code responsible for handling the user interface and saving into the preferences... I'd be glad to prepare a patch if developers agree and point me to the right direction....

Damon Lynch (dlynch3) wrote :

I'm sorry, I don't know what you mean by "part". Is this a feature request that is separate from accessing new EXIF tags?

The problem with allowing the user to specify completely arbitrary EXIF tags at runtime is that the formats for the data varies depending on the tag.

Ech (ech1965) wrote :

Let me try to be more understandable.

If I look at the contents of my CF card ( from a Canon400D)


what i want as a final filename is


( C is an arbitary letter I'd manually change when I reset the view counter counter in my 400D. )

the $filenumber of exiftool gives me 146-0101.CR2 which is close to what I need

see in the DCIM spec ( http://en.wikipedia.org/wiki/Design_rule_for_Camera_File_system#Directory_and_file_structure)
for more details about de structure of the DCIM structure.

The advantage of the $filenumber exif field is that it does not depend on the parent directory but only uses info already in the picture

Sorry for the noise but english is not my mother tongue

Damon Lynch (dlynch3) wrote :

I would like to add this metadata value, but unfortunately exiv2 has a bug that results in a value of 0:


Changed in rapid:
status: New → Confirmed
importance: Undecided → Wishlist
tags: added: metadata
summary: - Add a new kind of entry in rename format for arbitary exif field
+ extract Exif.CanonFi.FileNumber metadata
Ech (ech1965) wrote :
Download full text (3.2 KiB)


Looks like things aren't moving that fast on the exiv2 bug so I looked into the exiftool code and found out how the file number is encoded: in brain dead way: ( at least on my canon 400D)

in file : http://cpansearch.perl.org/src/EXIFTOOL/Image-ExifTool-8.60/lib/Image/ExifTool/Canon.pm
look for string "# File number information (MakerNotes tag 0x93)"

I hacked rapid-photo-downloader to implement this and you might be interested in integrating my ideas "your way".

Here is what I did:

in file metadataphoto.py: Here is my version of the shutter_count method ( bit shuffling to come with a 7 figures number:)

TODO: guard those changes with a check on the camera model number ( see exiftool code) ( maybe those shuffling should be in exvi2)

    def shutter_count(self, missing=''):
            keys = self.exif_keys
            if 'Exif.Nikon3.ShutterCount' in keys:
                v = self['Exif.Nikon3.ShutterCount'].raw_value
            elif 'Exif.CanonFi.FileNumber' in keys:
                v = self['Exif.CanonFi.FileNumber'].raw_value
                v = int(v)
                d = (v & 0xffc00) >> 10
                while d < 100:
                  d += 0x40
                v = d*10000 + ((v & 0x3ff ) << 4 ) + ((v >> 20) & 0x0f);
            elif 'Exif.Canon.FileNumber' in keys:
                v = self['Exif.Canon.FileNumber'].raw_value
            elif 'Exif.Canon.ImageNumber' in keys:
                v = self['Exif.Canon.ImageNumber'].raw_value
                return missing
            return str(v)
            return missing

in file generatenameconfig.py I added two sub choices for formatting the shutter_count value

TODO: create values specific to this use case: DCIM_DIRECTORY_NUMBER DCIM_IMAGE_NUMBER ?


in file generatename.py in method _get_metadata_component

        elif self.L1 == SHUTTER_COUNT:
            v = self.rpd_file.metadata.shutter_count()
            if self.L2 in [ SUBFOLDER_SEQ_NUMBER, STORED_SEQ_NUMBER ] :
                if self.L2 == SUBFOLDER_SEQ_NUMBER :
                    v = str(v)
                    v = v[:-4]
                if self.L2 == STORED_SEQ_NUMBER :
                    v = str(v)
                    v = v[-4:]
                if v:
                    v = int(v)
                    padding = LIST_SHUTTER_COUNT_L2.index(self.L2) + 3
                    formatter = '%0' + str(padding) + "i"
                    v = formatter % v
        elif self.L1 == OWNER_NAME:
            v = self.rpd_file.metadata.owner_name()

Those patches work for my Canon 400D ( and also for a old Canon A85 compact camera).

If theses changes are more or less in line with your "roadmap", I can put a real patch together.

I don't have a lot of DSLR so it's difficult for me to do regression tests ...

With those changes I can configure rapid-photo-downloader ...


Damon Lynch (dlynch3) on 2011-10-05
Changed in rapid:
assignee: nobody → Ech (ech1965)
milestone: none → 0.4.3
Damon Lynch (dlynch3) wrote :

Hi Etienne,

Thanks for taking the time to work on this. It's the best way to get things done, as I'm currently extremely busy working on my doctoral studies.

Rather than submitting a patch, why don't you use bzr and submit your changes using launchpad. That way, you will be an official contributor to the code. That is a very good outcome for the project and for you!

Thanks again,

Ech (ech1965) wrote :

Hello Damon,

I'd be glad to contribute !

I'm gonne learn how to register a branch in launchapd and commit my changes.
( I'll try to make them as robust as possible).
BTW, Do you use a python IDE for developing rapid ?


That's great, thanks. Personally I use Geany to code in python.

Damon Lynch (dlynch3) wrote :

I revised the code you submitted to make it fit with how the rest of the code works.

There is an error in this function, which must be fixed:


The generated value is not what I expect. This is what exiftool gives for a sample Canon 5D Mk II RAW file:
$ exiftool -f -FileNumber _MG_1929.CR2
File Number : 100-1929

but the code gives this incorrect value: 1280000

I don't understand Perl, so if you could fix the bug that would helpful, thanks.

Ech (ech1965) wrote :

Hello, Damon,

My code was guarded with a test for a specific camera model ( 400D) because the decoding is DSLR model dependent.
Unfortunaely, I'm not rich enough ;-) to afford me a 5D mkII...

Would you be kind to send me ( or attach it to this bug) a sample image and I'll try to figure out how to do it on 5D mkII images.

( the "ShutterCount" exif tag might work but I have to test it and dig a bit futher into the exiftool source code...)


Damon Lynch (dlynch3) wrote :

I didn't realize it was model specific. I assumed it wouldn't be. You can
find some samples 5D Mk II RAW files here:
If it becomes too difficult, one solution that will work (albeit slowly) is
to call exiftool and get it's results. I'm going to have to do that for
another feature request, which is to read metadata from MTS video files,
bug #695517. So implementing that will in itself add a dependency on

Damon Lynch (dlynch3) on 2011-11-13
Changed in rapid:
status: Confirmed → In Progress
Ech (ech1965) wrote :


Dealing with the maker notes is a big maintenance burden... so I think calling exitool is a lot less work.

If you want me to reimplement the feature based on exiftool.. please tell me when you a have a branch ready with your other feature request. I'll add it in a branch based on that.

Would you be kind to give me some advice on how to implement to be "compliant" with the rest of the code ? That would make the merging easier for you

Kind regards

Damon Lynch (dlynch3) wrote :

Hi Etienne,

The primary problem with the merged code last time was that it didn't match the design of the file renaming preferences. Things like stored values have very specific meanings. There are three levels of renaming: category, value, and formatting. A stored value is in the category sequence, and its value is a counter that increments and can be set in the user preferences, and its formatting is the number of digits it should take up.

I have already done the work to get exiftool working with MTS videos, but I'm not finished. The next step is to have exiftool be the default fallback option for all videos, as for some reason Fedora does not package hachoir metadata or kaa metadata. That means Fedora users currently cannot download videos using Rapid Photo Downloader. Using exiftool, they should be able to. I need to better integrate the exiftool code I've written. When I've done that, you can add the function to call the exiftool code for the file number. It should be really easy.


Damon Lynch (dlynch3) wrote :

Hi Etienne, I just went ahead and implemented the solution using ExifTool because it was easier to write the code rather than describe how it ought to be done! You can see the code in trunk.

Changed in rapid:
status: In Progress → Fix Committed
Damon Lynch (dlynch3) on 2012-01-08
Changed in rapid:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers