9595]
9696
9797class Metadata (object ):
98- def __init__ (self , projection = None , stereo_mode = None ):
98+ def __init__ (self , projection = None , stereo_mode = None , bounds = None ):
9999 self .projection = None if (not projection or projection == "none" ) else projection
100100 self .stereo_mode = None if (not stereo_mode or stereo_mode == "none" ) else stereo_mode
101+ if bounds :
102+ bounds = [max (0 , min (int (b , 0 ), 0xFFFFFFFF )) for b in bounds .split (":" )]
103+ if len (bounds ) != 4 :
104+ print ("Error: input bounds is incorrectly specified" )
105+ self .bounds = bounds
101106 self .video = None
102107 self .audio = None
103108
@@ -186,7 +191,7 @@ def mpeg4_add_spherical_xml_v1(mpeg4_file, in_fh, metadata):
186191 mpeg4_file .resize ()
187192 return True
188193
189- def mpeg4_add_spherical_v2 (mpeg4_file , in_fh , projection , stereo_mode ):
194+ def mpeg4_add_spherical_v2 (mpeg4_file , in_fh , projection , stereo_mode , bounds ):
190195 for element in mpeg4_file .moov_box .contents :
191196 if element .name == mpeg .constants .TAG_TRAK :
192197 for sub_element in element .contents :
@@ -199,18 +204,20 @@ def mpeg4_add_spherical_v2(mpeg4_file, in_fh, projection, stereo_mode):
199204 in_fh .seek (position )
200205 if in_fh .read (4 ) == mpeg .constants .TAG_VIDE :
201206 ret = inject_spatial_video_v2_atoms (
202- in_fh , sub_element , projection , stereo_mode )
207+ in_fh , sub_element , projection , stereo_mode , bounds )
203208 mpeg4_file .resize ()
204209 return ret
205210
206211
207- def inject_spatial_video_v2_atoms (in_fh , video_media_atom , projection , stereo_mode ):
212+ def inject_spatial_video_v2_atoms (in_fh , video_media_atom , projection , stereo_mode , bounds ):
208213 """Adds spherical v2 boxes to an mpeg4 file for all video tracks.
209214
210215 Args:
211- mpeg4_file: mpeg4, Mpeg4 file structure to add metadata.
212216 in_fh: file handle, Source for uncached file contents.
213- metadata: string, xml metadata to inject into spherical tag.
217+ video_media_atom: parent media atom.
218+ projection: the projection type.
219+ stereo_mode: stereo mode (if 3d), else none.
220+ bounds: equirect bounds.
214221 """
215222 for atom in video_media_atom .contents :
216223 if atom .name != mpeg .constants .TAG_MINF :
@@ -240,7 +247,7 @@ def inject_spatial_video_v2_atoms(in_fh, video_media_atom, projection, stereo_mo
240247 proj_atom .name = mpeg .constants .TAG_PROJ
241248
242249 proj_atom .add (mpeg .sv3d .PRHDBox .create ())
243- proj_atom .add (mpeg .sv3d .EQUIBox .create ())
250+ proj_atom .add (mpeg .sv3d .EQUIBox .create (bounds = bounds ))
244251
245252 sv3d_atom = mpeg .container .Container (header_size = 8 )
246253 sv3d_atom .name = mpeg .constants .TAG_SV3D
@@ -465,7 +472,8 @@ def inject_mpeg4(input_file, output_file, metadata, console):
465472 console ("Error failed to insert spherical data" )
466473
467474 if ((metadata .projection or metadata .stereo_mode )
468- and not mpeg4_add_spherical_v2 (mpeg4_file , in_fh , metadata .projection , metadata .stereo_mode )):
475+ and not mpeg4_add_spherical_v2 (mpeg4_file , in_fh , metadata .projection ,
476+ metadata .stereo_mode , metadata .bounds )):
469477 console ("Error failed to insert spherical data v2" )
470478
471479 if metadata .audio :
0 commit comments