save metadata to images

This commit is contained in:
pixxy 2025-07-17 22:29:47 +01:00
parent 0be33acb57
commit d174f71c59

16
wgp.py
View File

@ -4738,11 +4738,15 @@ def generate_video(
if metadata_choice == "json": if metadata_choice == "json":
with open(path.replace(f'.{extension}', '.json'), 'w') as f: with open(path.replace(f'.{extension}', '.json'), 'w') as f:
json.dump(configs, f, indent=4) json.dump(configs, f, indent=4)
elif metadata_choice == "metadata" and not is_image: elif metadata_choice == "metadata":
from mutagen.mp4 import MP4 if is_image:
file = MP4(path) with Image.open(path) as img:
file.tags['©cmt'] = [json.dumps(configs)] img.save(path, comment=json.dumps(configs))
file.save() else:
from mutagen.mp4 import MP4
file = MP4(path)
file.tags['©cmt'] = [json.dumps(configs)]
file.save()
if is_image: if is_image:
print(f"New image saved to Path: "+ path) print(f"New image saved to Path: "+ path)
else: else:
@ -7621,7 +7625,7 @@ def generate_configuration_tab(state, blocks, header, model_choice, prompt_enhan
metadata_choice = gr.Dropdown( metadata_choice = gr.Dropdown(
choices=[ choices=[
("Export JSON files", "json"), ("Export JSON files", "json"),
("Add metadata to video", "metadata"), ("Embed metadata (Exif tag)", "metadata"),
("Neither", "none") ("Neither", "none")
], ],
value=server_config.get("metadata_type", "metadata"), value=server_config.get("metadata_type", "metadata"),