google / spatial-media

Specifications and tools for 360º video and spatial audio.
Other
1.86k stars 430 forks source link

Ffmpeg add Spatial Media Metadata #226

Open wangpeng-teche opened 5 years ago

wangpeng-teche commented 5 years ago

Can I add Spatial Media Metadata data using FFMPEG? In MP4 encoding, I tried to use ffmpeg's av_stream_add_side_data to add AVSphericalMapping data. It is useful in av_dump_format, but it is not in MP4. Is there a source code or class library for Windows C++?

wangpeng-teche commented 5 years ago

No one is maintaining it? There are very few people using this project.

nbirkbeck commented 4 years ago

There should be support for writing, but you'll have to lessen the strictness (e.g., to at least -strict unofficial): https://github.com/FFmpeg/FFmpeg/blob/94bac7b3f8dcd8af33d9f7e18b4e4e73c73f98dd/libavformat/movenc.c#L2178

Boscop commented 4 years ago

@nbirkbeck I have ffmpeg 4.3, can you please tell me what the right invocation is to inject the metadata with ffmpeg? Based on your comment here, I tried this, with -strict unofficial:

ffmpeg -i vid.mp4 -metadata:s:v spherical-video='GSpherical:Sphericaltrue</GSpherical:Spherical>GSpherical:Stitchedtrue</GSpherical:Stitched>GSpherical:StitchingSoftwareSpherical Metadata Tool</GSpherical:StitchingSoftware>GSpherical:ProjectionTypeequirectangular</GSpherical:ProjectionType></rdf:SphericalVideo>' -c copy -strict unofficial vid_360.mp4

It prints

    Metadata:
      handler_name    : VideoHandler
      spherical-video : <rdf:SphericalVideo xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:GSpherical="http://ns.google.com/videos/1.0/spherical/">GSpherical:Sphericaltrue</GSpherical:Spherical>GSpherical:Stitchedtrue</GSpherical:Stitched>GSpherical:StitchingSoftw

But the resulting video doesn't play as 360° video in VLC. If I inject using the google injector, it plays correctly and has this metadata:

    Metadata:
      handler_name    : VideoHandler
    Side data:
      spherical: equirectangular (0.000000/0.000000/0.000000)

And then a follow up question: Should it also work with MKV? Is the invocation for MKV different?

adiwithadidas commented 3 years ago

@Boscop I know this a bit old, but did you found any solution for this ?

I am trying to add Spatial Medi Metadata in video through ffmpeg, so that players can detect the video as 360.

Can you please guide me to a solution.

Thanks

kairi003 commented 1 year ago

@adiwithadidas Unfortunately, I don't know how to do this with ffmpeg, but you can do this with MKVMerge as shown in #159 . Encode to mkv with -c copy , add metadata with MKVMerge, and then convert back to mp4 with -c copy -strict unofficial.