Issue #57 new

Creation date of some .jpg files cannot be parsed

created an issue

The creation date of jpg files shooted with the camera of a friend's android phone cannot be parsed by hachoir. See for example this image (of an on-time clock).


I expect the following python interactive shell session to display the datetime creation, but it fails.

$ python
Python 2.7.11 (default, Dec  9 2015, 00:29:25) 
[GCC 5.3.1 20151205] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from hachoir_core.cmd_line import unicodeFilename
>>> from hachoir_metadata import extractMetadata
>>> from hachoir_parser import createParser
>>> photo = "IMG_20151218_174010_282.jpg"
>>> meta = extractMetadata(createParser(unicodeFilename(photo), photo))
[warn] Error when calling function readGPS(): Can't get field "value_entry[1][0]" from /exif/content/ifd[2]
[warn] Unable to convert creation_date=u'2015:12:18 16:40:9' (unicode) to datetime or date
[warn] [/exif/content/ifd[5]] [Autofix] Delete '/exif/content/ifd[5]/padding[0]' (too large)
[warn] [/exif/content/ifd[5]] [Autofix] Fix parser error: stop parser, add padding
>>> meta.get('creation_date')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/dist-packages/hachoir_metadata/", line 82, in get
    raise ValueError("Metadata has no value '%s' (index %s)" % (key, index))
ValueError: Metadata has no value 'creation_date' (index 0)

Two things to notice:

  • hachoir cannot get the creation date, although it is stored in the file: nautilus, or exifread, for instance, are able to see it.
  • the warning Unable to convert creation_date=u'2015:12:18 16:40:9' (unicode) to datetime or date shows a wrong creation date: the date is correct, but the time should be 17:40 (as pictured) instead of 16:40. This looks like a time zone issue (this is a French phone).

I can provide additional images or information about the phone on request.

Regards, Louis

Comments (3)

  1. Luca Colleoni

    Hi, I have the same problem. However, I have noticed that if you write

    meta = extractMetadata(createParser(unicodeFilename(photo), photo))

    twice, the second time, hachoir can read metadata because it has been fixed by autofix. Now I am looking for the best way of understanding that an outfox has occurred so that i can reload metadata

  2. Luca Colleoni

    Hi, Awesome, thank you very much for the fix, hachoir3 is even better. Honestly, I am using hachoir3 and I haven't noticed this issue was for python2. I will try it tomorrow. However, I still have a question, now I have to read also metadata from mp4 files and I am still encountering some problems with hachoir3. When the file exceed a certain dimension that I am still not able to determine, but I suppose is around 25 mb. Hachoir raises autofix warnings and returns a None object. First times I have noticed it, I have observed that if I read the file again sometimes I was able to read metadata. So I placed the instruction

    meta = extractMetadata(createParser(unicodeFilename(photo), photo))

    in while loop using while(!metadata) { ... }. However, since I need a fast response from hachoir and I want to be sure of being able to exit from the loop, I also added a incremental counter that starts at 0 and once it arrives at 1000 it stops the loop. I have noticed that sometimes with files bigger than 100 mb I am still not able to read metadata. Thus, I have printed the counter value at which hachoir is able to read metadata. I have noticed that even for the same file, the counter value changes between different executions.

    Do you have an idea why is this happening? Is there way to avoid autofix warnings? I have tried to read hachoir code, but it seems really technical in this part.

    Again, Thank you very much.


  3. Log in to comment