sannies / mp4parser

A Java API to read, write and create MP4 files
Apache License 2.0
2.76k stars 566 forks source link

Inject Spherical video metadata (360) #223

Closed GuillaumeHugot closed 8 years ago

GuillaumeHugot commented 8 years ago

To inject spherical metadata (defined by Google), our UserBox UUID is ffcc8263-f855-4a93-8814-587a02521fdd But it seems that the buffer used by the WritableByteChannel is too small to handle it as we have a BufferOutOfBoundException when we try to do out.writeContainer() after injecting the meta.

Here is our code : String sphericalVideoGlobalMetadata = "<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:Spherical>true</GSpherical:Spherical>" + "<GSpherical:Stitched>true</GSpherical:Stitched>" + "<GSpherical:StitchingSoftware>our soft</GSpherical:StitchingSoftware>" + "<GSpherical:ProjectionType>equirectangular</GSpherical:ProjectionType>" + "</rdf:SphericalVideo>"; String UUID_ID = "ffcc8263-f855-4a93-8814-587a02521fdd"; UserBox sphericalAtom = new UserBox(UUID_ID.getBytes()); sphericalAtom.setData(sphericalVideoGlobalMetadata.getBytes()); trackBox.addBox(sphericalAtom); [...] FileOutputStream fos = new FileOutputStream(dst); WritableByteChannel fc = fos.getChannel(); try { out.writeContainer(fc);//here is the error }catch (Exception e) { Log.e("error", e.toString()); }finally { fc.close(); fos.close(); file.close(); }

This code works when we use a shorter UUID