PetrVys / MotionPhoto2

Mux HEIC and JPG Live Photos into Google/Samsung Motion Photos
MIT License
40 stars 7 forks source link

Error: `lxml.etree.XMLSyntaxError: Extra content at the end of the document` #12

Open ChakshuGupta13 opened 3 weeks ago

ChakshuGupta13 commented 3 weeks ago

While using script over a folder which may contain other files as well, encountered following:

=========================
[30/10/2024 23:27:49] [WARNING] [IMG_2667] - Make sure to have a backup of your image and/or video file
[30/10/2024 23:27:49] [INFO] [IMG_2667] - Live Photo keyframe track number: 4
[30/10/2024 23:27:49] [INFO] [IMG_2667] - Live Photo keyframe: 1401667us
Traceback (most recent call last):
  File "...motionphoto2.py", line 128, in <module>
    ).mux()
      ~~~^^
  File "...Muxer.py", line 238, in mux
    self.merge_xmp(result)
    ~~~~~~~~~~~~~~^^^^^^^^
  File "...Muxer.py", line 171, in merge_xmp
    xmp = lxml.fromstring(xmp)
  File "src/lxml/etree.pyx", line 3306, in lxml.etree.fromstring
  File "src/lxml/parser.pxi", line 1995, in lxml.etree._parseMemoryDocument
  File "src/lxml/parser.pxi", line 1875, in lxml.etree._parseDoc
  File "src/lxml/parser.pxi", line 1105, in lxml.etree._BaseParser._parseUnicodeDoc
  File "src/lxml/parser.pxi", line 633, in lxml.etree._ParserContext._handleParseResultDoc
  File "src/lxml/parser.pxi", line 743, in lxml.etree._handleParseResult
  File "src/lxml/parser.pxi", line 672, in lxml.etree._raiseParseError
  File "<string>", line 1
lxml.etree.XMLSyntaxError: Extra content at the end of the document, line 1, column 2541

I tried to see xmp - maybe it will help later:

[30/10/2024 23:39:47] [INFO] [IMG_2667] - XMP of original file: <?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?> <x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="XMP Core 6.0.0"> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"> <rdf:Description rdf:about="" xmlns:xmp="http://ns.adobe.com/xap/1.0/" xmlns:photoshop="http://ns.adobe.com/photoshop/1.0/" xmp:CreateDate="2023-09-09T19:26:04" xmp:CreatorTool="16.6.1" xmp:ModifyDate="2023-09-09T19:26:04" photoshop:DateCreated="2023-09-09T19:26:04"/> </rdf:RDF> </x:xmpmeta>  

Weirdly, it works next time when video file is re-copied from source for second run.

=========================
[30/10/2024 23:55:24] [WARNING] [IMG_2667] - Make sure to have a backup of your image and/or video file
[30/10/2024 23:55:24] [INFO] [IMG_2667] - Live Photo keyframe track number: 4
[30/10/2024 23:55:24] [INFO] [IMG_2667] - Live Photo keyframe: 1401667us
[30/10/2024 23:55:24] [INFO] [IMG_2667] - XMP metadata - copying attribute {http://www.w3.org/1999/02/22-rdf-syntax-ns#}about
[30/10/2024 23:55:24] [INFO] [IMG_2667] - XMP metadata - copying attribute {http://ns.google.com/photos/1.0/camera/}MotionPhoto
[30/10/2024 23:55:24] [INFO] [IMG_2667] - XMP metadata - copying attribute {http://ns.google.com/photos/1.0/camera/}MotionPhotoVersion
[30/10/2024 23:55:24] [INFO] [IMG_2667] - XMP metadata - copying attribute {http://ns.google.com/photos/1.0/camera/}MotionPhotoPresentationTimestampUs
[30/10/2024 23:55:24] [INFO] [IMG_2667] - Writing output file: ...IMG_2667.HEIC
PetrVys commented 3 weeks ago

Hello,

Thanks for the report. It is strange that it worked once and did not work the second time, in any case the latest update should provide a workaround for issues like this. In case of any failures, some (or all) tags could be ignored during copy if any error occurs.

If you manage to replicate the issue, please check now - you should see message "Could not copy (some of?) the XMP metadata tags from source.", but the mux should succeed.

Longer term, I plan to do some sanitization of the XMP data - strip the xpacket nonsense and strip everything after the end of XML, exiftool sometimes lets through binary uninitialized data from the XMP area within the file. Also, I'd like to start with the source XMP and enrich it for MotionPhoto, that should solve some of the namespace naming and alias placement issues. Hopefully that'll make this whole vector moot...

ChakshuGupta13 commented 3 weeks ago

Just a minor correction - it did NOT work first time but it did second time:

It is strange that it worked once and did not work the second time

By any chance, can you please point to "the latest update" which will help here?

Will try to do that:

If you manage to replicate the issue, please check now - you should see message "Could not copy (some of?) the XMP metadata tags from source.", but the mux should succeed.

PetrVys commented 3 weeks ago

If you manage to replicate the issue, please check now - you should see message "Could not copy (some of?) the XMP metadata tags from source.", but the mux should succeed.

By any chance, can you please point to "the latest update" which will help here?

Just download the latest source code: https://github.com/PetrVys/MotionPhoto2/archive/refs/heads/main.zip

ChakshuGupta13 commented 3 weeks ago

I meant specific commit - but NVM - found it. I did exactly same - that's how locally I worked-around issue - so latest changes shall also work.