In [16]:
import json
with open("steve-walking-rotation.json") as f:
j = json.load(f)
out_j = []
last_rotation = 10000
for l in j:
if l["rotation"] != last_rotation:
out_j.append({
"time": float(l["timestamp"] - 1484941465098)/1000.0,
"rotation": -1*l["rotation"] + 90,
})
last_rotation = l["rotation"]
with open("steve-walking-rotation-out.json", "w") as f:
json.dump(out_j, f, indent=4)
In [1]:
# convert rotation json to new json format
# format found here: https://docs.google.com/document/d/1miKwDYnjdYtGWoPyTIBrjXlq3iuWFY5paQ5gzWWdKsk/edit
import json
import math
math.pi
Out[1]:
In [7]:
with open("rotations.json") as f:
j = json.load(f)
new_rotations = []
for i in range(len(j)):
if i != 0:
r1 = j[i - 1]
r2 = j[i]
r1_f = ( (r1["rotation"]+180) / 360.0) * 2.0 * math.pi
r1_s = ( (r1["rotation"]) / 360.0) * 2.0 * math.pi
new_rotation = {"orientations": [r1_f, r1_s],
"start": r1["time"],
"end": r2["time"]}
new_rotations.append(new_rotation)
lr_f = ((j[-1]["rotation"]+180) / 360.0) * 2.0 * math.pi
lr_s = ((j[-1]["rotation"]) / 360.0) * 2.0 * math.pi
last_rotation = {"orientations": [lr_f, lr_s],
"start": j[-1]["time"],
"end": 900000 }
new_rotations.append(last_rotation)
new_subtitles = []
for rotation in new_rotations:
new_subtitles.append({"start": rotation["start"], "end": rotation["end"], "text": ""})
out_json = {"videos": [{"fn": "../video/nocuts.mp4"}],
"subtitles": new_subtitles,
"orientation": new_rotations}
with open("spec-files/nocuts.json", "w") as f:
json.dump(out_json, f, indent=4)
# with open("spec-files/nocuts.json") as f_old:
# j_old = json.load(f_old)
# j_old["orientation"] = new_rotations
# f_old.close()
# with open("spec-files/nocuts.json", "w") as f_new:
# json.dump(j_old, f, indent=4)
In [ ]: