oozcitak / exiflibrary

A .Net Standard library for editing Exif metadata
MIT License
131 stars 48 forks source link

Partial second in date causes #82

Open davidebbo opened 3 years ago

davidebbo commented 3 years ago

I have a jpg with a creation time that has a partial second: "2016:07:31 10:10:20.291".

This causes it to blow up when parsing the date:

System.FormatException
  HResult=0x80131537
  Message=Input string was not in a correct format.
  Source=System.Private.CoreLib
  StackTrace:
   at System.Number.ThrowOverflowOrFormatException(ParsingStatus status, TypeCode type)
   at System.Number.ParseInt32(ReadOnlySpan`1 value, NumberStyles styles, NumberFormatInfo info)
   at System.Int32.Parse(String s)
   at ExifLibrary.ExifBitConverter.ToDateTime(Byte[] data, Boolean hastime) in D:\Code\Github\exiflibrary\ExifLibrary\ExifBitConverter.cs:line 74
   at ExifLibrary.ExifBitConverter.ToDateTime(Byte[] data) in D:\Code\Github\exiflibrary\ExifLibrary\ExifBitConverter.cs:line 101
   at ExifLibrary.ExifPropertyFactory.Get(UInt16 tag, UInt16 type, UInt32 count, Byte[] value, ByteOrder byteOrder, IFD ifd, Encoding encoding) in D:\Code\Github\exiflibrary\ExifLibrary\ExifPropertyFactory.cs:line 44
   at ExifLibrary.JPEGFile.ReadExifAPP1() in D:\Code\Github\exiflibrary\ExifLibrary\JPEGFile.cs:line 735

The image is personal, so I'll share it separately via email.

RudyTheDev commented 2 years ago

I encountered the same problem. My images are extracted from video footage and this means milliseconds are important.

For my purposes, I had to parse the actual millisecond value; add a flag to ExifDateTime specifying if the loaded timestamp had milliseconds, allow property collection Set() to specify if milliseconds are to be written and finally supply the actual byte data with the millisecond part if present/needed (https://github.com/RudyTheDev/exiflibrary/commit/4d87cf05b9d6eccd1fe6ddfc68775b9a610ecbb9).

I haven't added any tests.

I understand that this doesn't follow the EXIF spec, but that's the only way to work with sub-second values with stuff like Mapillary.

RudyTheDev commented 2 years ago

I just found there is SubSecTimeXxx in EXIF spec for fractional seconds. The issue though is that the source software does not use this, nor does the target software.