1
$\begingroup$

I'm trying to develop a add-on that could inject a 360 metadata into a video at Blender eevee, but this code, needs to be a button that could be toggle at render properties like, "Inject 360 Metadata?: True or False.

When you render the video, the add on will ad all the metadata without the need of another app to inject those metadatas at the video.

The button doesn't appear at Render Properties panel. After Render it doesn't add the metadatas.

I have this Idea to put this button at the Blender UI to render the video and add the metadatas without the need of another program to inject them.

I made a example but this wasn't functional.

import bpy
import subprocess

bpy.types.Scene.add_metadata = bpy.props.BoolProperty(
    name="Add Metadata",
    description="Enable adding metadata after rendering",
    default=True
)

def add_metadata(scene):
    if scene.add_metadata:
        rendered_filepath = bpy.context.scene.render.filepath

        xml_metadata = '''<?xml version="1.0"?>
        <rdf:SphericalVideo xmlns:GSpherical="http://ns.google.com/videos/1.0/spherical/">
          <GSpherical:Spherical>true</GSpherical:Spherical>
          <GSpherical:Stitched>true</GSpherical:Stitched>
          <GSpherical:StitchingSoftware>Spherical Metadata Tool</GSpherical:StitchingSoftware>
          <GSpherical:ProjectionType>equirectangular</GSpherical:ProjectionType>
        </rdf:SphericalVideo>'''

        temp_xml_file = "/path/to/temp/metadata.xml"

        with open(temp_xml_file, "w") as f:
            f.write(xml_metadata)

        ffmpeg_command = ["ffmpeg", "-i", rendered_filepath, "-i", temp_xml_file, "-c", "copy", "-map", "0", "-map", "1", "-metadata:s:v", "spherical-video", "-metadata:s:v", "rotate=0", rendered_filepath]

        subprocess.run(ffmpeg_command)

        import os
        os.remove(temp_xml_file)

bpy.app.handlers.render_complete.append(add_metadata)

class AddMetadataPanel(bpy.types.Panel):
    bl_label = "Add Metadata"
    bl_idname = "PT_ADD_METADATA"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "render"

    def draw(self, context):
        layout = self.layout
        scene = context.scene

        layout.prop(scene, "add_metadata")

def register():
    bpy.utils.register_class(AddMetadataPanel)

def unregister():
    bpy.utils.unregister_class(AddMetadataPanel)

if __name__ == "__main__":
    register()

```
$\endgroup$
2
  • $\begingroup$ what do you mean with "true or false"? what in the code does not work? don't you know how to add the button? doesn't the button appear? doesn't the ffmpeg command work? it's not clear to me what your problem is.... $\endgroup$
    – Chris
    Commented Feb 24 at 7:04
  • $\begingroup$ I updated the question $\endgroup$ Commented Feb 24 at 14:52

0

You must log in to answer this question.

Browse other questions tagged .