RhetTbull / makelive

Create Live Photos from a photo+video pair compatible with Apple Photos
MIT License
30 stars 1 forks source link

If "exiftool -all= img.heic" is used to strip metadata, makelive crashes #10

Open RhetTbull opened 3 months ago

RhetTbull commented 3 months ago

Steps to reproduce:

On a test heic and mov file, run exiftool -all= test.heic. This removes the entire metadata dictionary (and is something you should do as it also removes the color profile). Then run makelive test.*. This results in a crash:

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/Users/rhet/Library/Application Support/pyapp/makelive/8517997354123992902/0.5.0/lib/python3.11/site-packages/makelive/__main__.py", line 135, in <module>
    main()
  File "/Users/rhet/Library/Application Support/pyapp/makelive/8517997354123992902/0.5.0/lib/python3.11/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rhet/Library/Application Support/pyapp/makelive/8517997354123992902/0.5.0/lib/python3.11/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/Users/rhet/Library/Application Support/pyapp/makelive/8517997354123992902/0.5.0/lib/python3.11/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rhet/Library/Application Support/pyapp/makelive/8517997354123992902/0.5.0/lib/python3.11/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rhet/Library/Application Support/pyapp/makelive/8517997354123992902/0.5.0/lib/python3.11/site-packages/makelive/__main__.py", line 127, in main
    asset_id = make_live_photo(image, video)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rhet/Library/Application Support/pyapp/makelive/8517997354123992902/0.5.0/lib/python3.11/site-packages/makelive/makelive.py", line 269, in make_live_photo
    add_asset_id_to_image_file(image_path, asset_id)
  File "/Users/rhet/Library/Application Support/pyapp/makelive/8517997354123992902/0.5.0/lib/python3.11/site-packages/makelive/makelive.py", line 128, in add_asset_id_to_image_file
    metadata = metadata_dict_for_asset_id(image_data, asset_id)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/rhet/Library/Application Support/pyapp/makelive/8517997354123992902/0.5.0/lib/python3.11/site-packages/makelive/makelive.py", line 106, in metadata_dict_for_asset_id
    metadata_as_mutable = metadata.mutableCopy()
                          ^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'mutableCopy'

I tried creating an empty metadata dict if none was found but that results an 0-byte file when written.

am1006 commented 3 months ago

I had a go and it also crashed. I wonder if we could detect the empty metadata status, and if it's empty, manually add an entry of metadata (for example, something as simple as exif version or a user comment) to restore the metadata dict.

RhetTbull commented 3 months ago

That's a good idea. Maybe ProcessingSoftware?

The name and version of the software used to post-process the picture.
am1006 commented 3 months ago

Sounds good! I will take a look at this problem and see if I can create a patch.

am1006 commented 1 month ago

Hi @RhetTbull ! Long time no see - I had a quite busy July & just got back on coding stuff.

I wonder what's your thought on introducing exiftools to this project. Or I should just use Core Graphic & AV Foundation?

Cheers.

RhetTbull commented 1 month ago

Hi @am1006 I'd prefer to keep this as a native library without external dependencies. The entire reason I created this was exiftool could not create the necessary metadata but now that I have it's nice to be able to use this without calling exiftool (and in some use cases I have planned, calling an external process won't be possible due to app sandboxing).