Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ErrUnparseableValue error when reading in a JPEG file taken with a Sony digital camera #80

Open
matti777 opened this issue Jul 24, 2023 · 4 comments · May be fixed by #81
Open

ErrUnparseableValue error when reading in a JPEG file taken with a Sony digital camera #80

matti777 opened this issue Jul 24, 2023 · 4 comments · May be fixed by #81

Comments

@matti777
Copy link

matti777 commented Jul 24, 2023

Im getting an ErrUnparseableValue error when reading the EXIF of a JPEG image taken with a Sony digital camera. Is that expected, what is the workaround? I would rather not toss away the existing EXIF, instead just be able to skip any unrecognized tags.

Image included as attachment; I am using the below code to read it:

	goexif "github.com/dsoprea/go-exif/v3"
	goexifundefined "github.com/dsoprea/go-exif/v3/undefined"
	jpeg "github.com/dsoprea/go-jpeg-image-structure/v2"
	"github.com/pkg/errors"

	parser := jpeg.NewJpegMediaParser()
	mediaCtx, err := parser.ParseFile(filepath)
	if err != nil {
		return 0, errors.Errorf("failed to parse JPEG file: %v", err)
	}

	sl := mediaCtx.(*jpeg.SegmentList)

	rootIb, err := sl.ConstructExifBuilder()
	if err != nil {
		if errors.Is(err, goexifundefined.ErrUnparseableValue) {
			// TODO create EXIF from scratch?
			log.Printf("No EXIF data, creating it from scratch: rootIb: %v, err: %v", rootIb, err)
		} else {
			return 0, errors.Wrap(err, "Failed to construct EXIF builder")
		}
	}

DSC00098

@georgethebeatle
Copy link

Hi @matti777 I believe I have hit the same issue with all images produced by my Sony NEX 3N camera. With some debugging I was able to identify that it was the PrintImageMatching tag that is causing the error you are getting.

The error is coming from here and is due to the fact that there is no registered decoder for this tag so one cannot be looked up here

A trivial solution is to simply skip tags with this name in the loop in the ifd builder's AddTagsFromExisting method. You can go mod vendor and edit that file directly adding

if ite.TagName() == "PrintImageMatching" {
    fmt.Println("Skipping tag ", ite.TagName())
    continue
}

to that loop. This did the trick for me, but is just a hack rather than a real solution.

As for the real solution there are two options that I can think of:

  • Add a proper way of ignoring certain tags
  • Add a decoder for the PrintImageMatching tag

My intuition is that the latter is preferable.

I would also prefer if the library's errors were more detailed so that you know what is the name of the problematic tag from the error message. However, this is probably worth opening a separate issue for.

I hope all of this helps!

@georgethebeatle georgethebeatle linked a pull request Aug 17, 2023 that will close this issue
@georgethebeatle
Copy link

I just opened a PR where I try to fix this issue.

@dsoprea
Copy link
Owner

dsoprea commented Aug 26, 2023

Actually, a third solution (also a hack) would be to add support for removing a given tag from the tags-index. When the enumerator tries to parse a tag whose ID is unknown, it'll just skip. Just copy-and-paste the Add() method as Remove() and replace its logic with remove semantics.

@dsoprea
Copy link
Owner

dsoprea commented Aug 26, 2023

@georgethebeatle Posted comments to the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants