Skip to content

Commit

Permalink
Support specifying yaw/pitch/roll from cli
Browse files Browse the repository at this point in the history
  • Loading branch information
kodawah committed Feb 27, 2017
1 parent 431ae13 commit 77cd910
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
25 changes: 25 additions & 0 deletions spatialmedia/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,30 @@ def main():
choices=["equirectangular", "cubemap"],
default=None,
help="spherical mode (equirectangular | cubemap)")
video_group.add_argument(
"-y",
"--yaw",
action="store",
dest="yaw",
metavar="YAW",
default=0,
help="yaw")
video_group.add_argument(
"-p",
"--pitch",
action="store",
dest="pitch",
metavar="PITCH",
default=0,
help="pitch")
video_group.add_argument(
"-r",
"--roll",
action="store",
dest="roll",
metavar="ROLL",
default=0,
help="roll")

audio_group = parser.add_argument_group("Spatial Audio")
audio_group.add_argument(
Expand Down Expand Up @@ -98,6 +122,7 @@ def main():
metadata.audio = metadata_utils.SPATIAL_AUDIO_DEFAULT_METADATA

if metadata.stereo or metadata.spherical or metadata.audio:
metadata.orientation = {"yaw": args.yaw, "pitch": args.pitch, "roll": args.roll}
metadata_utils.inject_metadata(args.file[0], args.file[1], metadata,
console)
else:
Expand Down
1 change: 1 addition & 0 deletions spatialmedia/metadata_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class Metadata(object):
def __init__(self):
self.stereo = None
self.spherical = None
self.orientation = None
self.video = None
self.audio = None

Expand Down
15 changes: 11 additions & 4 deletions spatialmedia/mpeg/sv3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ def __init__(self):
self.header_size = 8
self.proj_size = 0
self.content_size = 0
self.yaw = 0
self.pitch = 0
self.roll = 0

@staticmethod
def create(metadata):
Expand All @@ -79,6 +82,9 @@ def create(metadata):
elif new_box.projection == "cubemap":
new_box.content_size = 73 - new_box.header_size
new_box.proj_size = 52
new_box.yaw = float(metadata.orientation["yaw"])
new_box.pitch = float(metadata.orientation["pitch"])
new_box.roll = float(metadata.orientation["roll"])

return new_box

Expand All @@ -87,10 +93,11 @@ def print_box(self, console):
console.
"""
console("\t\tSpherical Mode: %s" % self.projection)
console("\t\t [Yaw: %.02f, Pitch: %.02f, Roll: %.02f]" % (self.yaw, self.pitch, self.roll))

def get_metadata_string(self):
""" Outputs a concise single line audio metadata string. """
return "Spherical mode: %s" % (self.projection)
return "Spherical mode: %s (%f,%f,%f)" % (self.projection, self.yaw, self.pitch, self.roll)

def save(self, in_fh, out_fh, delta):
if (self.header_size == 16):
Expand All @@ -115,9 +122,9 @@ def save(self, in_fh, out_fh, delta):
out_fh.write(struct.pack(">I", 24)) # size
out_fh.write("prhd") # tag
out_fh.write(struct.pack(">I", 0)) # version+flags
out_fh.write(struct.pack(">I", 0)) # yaw
out_fh.write(struct.pack(">I", 0)) # pitch
out_fh.write(struct.pack(">I", 0)) # roll
out_fh.write(struct.pack(">I", self.yaw * 65536)) # yaw
out_fh.write(struct.pack(">I", self.pitch * 65536)) # pitch
out_fh.write(struct.pack(">I", self.roll * 65536)) # roll

#cmbp or equi
if self.projection == "equirectangular":
Expand Down

0 comments on commit 77cd910

Please sign in to comment.