Skip to content
This repository has been archived by the owner on Jul 8, 2023. It is now read-only.

Commit

Permalink
GoPro gyro extraction implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
ElvinC committed Aug 8, 2020
1 parent 243fe65 commit 0218699
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 15 deletions.
39 changes: 25 additions & 14 deletions GPMF_gyro.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,39 @@
import gpmf.parse as gpmf_parse
from gpmf.extract import get_gpmf_payloads_from_file
import sys

import numpy as np
from matplotlib import pyplot as plt

class Extractor:
def __init__(self, videopath = "hero5.mp4"):
self.videopath = videopath

payloads, parser = get_gpmf_payloads_from_file(videopath)

self.parsed = []

for gpmf_data, timestamps in payloads:
for element, parents in gpmf_parse.recursive(gpmf_data):
try:
value = gpmf_parse.parse_value(element)
except ValueError:
value = element.data
print("{} {} > {}: {}".format(
timestamps,
' > '.join([x.decode('ascii') for x in parents]),
element.key.decode('ascii'),
value
))
self.parsed.append(gpmf_parse.parse_dict(gpmf_data))





def get_gyro(self):
return 1
self.gyro = []
self.scal = 0
for frame in self.parsed:
for stream in frame["DEVC"]["STRM"]:
if "GYRO" in stream:
self.gyro += stream["GYRO"]
self.scal = stream["SCAL"]



omega = np.array(self.gyro) / self.scal

plt.plot(omega[:,0])
plt.show()

def get_accl(self):
return 1
Expand All @@ -36,4 +46,5 @@ def get_video_length(self):


if __name__ == "__main__":
testing = Extractor()
testing = Extractor()
testing.get_gyro()
48 changes: 47 additions & 1 deletion gpmf/parse.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Derived from:
# https://github.com/rambo/python-gpmf
# The MIT License (MIT)
# Copyright (c) 2014 Eero af Heurlin
# https://github.com/rambo/python-gpmf

#!/usr/bin/env python3
"""Parses the FOURCC data in GPMF stream into fields"""
Expand Down Expand Up @@ -42,6 +43,9 @@

def parse_value(element):
"""Parses element value"""
if not element:
return "HELLOWTHERE"

type_parsed = TYPES.parse(bytes([element.type]))
#print("DEBUG: type_parsed={}, element.repeat={}, element.size={}, len(element.data): {}".format(type_parsed, element.repeat, element.size, len(element.data)))

Expand Down Expand Up @@ -123,7 +127,49 @@ def recursive(data, parents=tuple()):
yield subyield
else:
yield (element, parents)

def parse_list(data, parent = []):
elements = construct.GreedyRange(FOURCC).parse(data)

out_list = []
for element in elements:
if element.type == 0:

out_list.append(parse_list(element.data, out_list))
else:
try:
value = parse_value(element)
except ValueError:
value = element.data

out_list.append(value)
print(element.key)

return out_list

def parse_dict(data):
"""Parse data into a dict recursively
"""

elements = construct.GreedyRange(FOURCC).parse(data)
new_dict = dict()

for element in elements:
if element.type == 0:

if (element.key.decode('ascii') == "STRM"):
new_dict.setdefault("STRM", []).append(parse_dict(element.data))
else:
new_dict[element.key.decode('ascii')] = parse_dict(element.data)

else:
try:
value = parse_value(element)
except ValueError:
value = element.data
new_dict[element.key.decode('ascii')] = value

return new_dict

if __name__ == '__main__':
import sys
Expand Down

0 comments on commit 0218699

Please sign in to comment.