Skip to content

Instantly share code, notes, and snippets.

@hohonuuli
Last active August 29, 2018 20:39
Show Gist options
  • Save hohonuuli/1b01625de926d3a4f6313a9b20a36ad7 to your computer and use it in GitHub Desktop.
Save hohonuuli/1b01625de926d3a4f6313a9b20a36ad7 to your computer and use it in GitHub Desktop.
MBARI Media Management - Demonstrate how to register a video in the `vampire-squid` video asset manager
import datetime
import json
import sys
import requests
host = "http://localhost:8084"
client_secret = "foo"
# Useful vampire-squid endpoints
vampire_squid = "{}/vam/v1".format(host)
auth_url = "{}/auth".format(vampire_squid)
media_url = "{}/media".format(vampire_squid)
def main(url, timeString):
# -- Authenticate so that we can make a post request
jwt_auth_header = {"Authorization": "APIKEY " + client_secret}
jwt_response = requests.post(auth_url, headers=jwt_auth_header).json()
access_token = jwt_response['access_token']
# -- Use POST to create media
# This is totally mock data. The only real data is the URL and
# time stamp. In production the media_data would be parse from the
# file system, file names and or file metadata
auth_header = {"Authorization": "Bearer " + access_token}
media_data = {"video_sequence_name": "Ventana 0952",
"camera_id": "Ventana",
"video_name": "Ventana 0952 {}".format(timeString),
"uri": url,
"start_timestamp": timeString,
"duration_millis": 123456}
return requests.post(media_url, media_data, headers=auth_header).json()
if __name__ == "__main__":
"""
Args:
url -> A URL to a file. Should start with http but file URLS will work to
time_string -> Start time of the video. Formatted as yyyy-MM-ddTHH:mm:ssZ
Just use UTC times for now.
"""
url = sys.argv[1]
time_string = sys.argv[2]
response_body = main(url, time_string)
print(response_body)
@hohonuuli
Copy link
Author

This is a super simple mock up using some mock values. You can use it as:

python register_video.py <movie url> <time stamp as iso8601>

Example:

python register_video.py \
    http://m3.shore.mbari.org/videos/M3/mezzanine/DocRicketts/2018/07/1047/D1047_20180730T162551Z_h264.mp4 \  
    2018-07-30T16:25:51Z

@hohonuuli
Copy link
Author

A media_data can have the following params:

Required parameters

  • video_sequence_name: String name that used to group videos from a single camera deployment
  • camera_id: String name of that identifies the camera used to collect the video
  • video_name: String name of the video segment from the deployment
  • uri: The URL that points to your video. Other URI types are allowed.
  • start_timestamp: UTC time formatted as yyyy-MM-ddTHH:mm:ss[.ssss]Z for example 2018-07-30T16:25:51Z or 2018-07-30T16:25:51.123Z

Optional parameters

  • duration_millis: The length of the video in milliseconds
  • container: Identifier for the media container. No real constraints but I usually use the mimetype of the video file here
  • video_codec: String to ID the codec used to encode the video track. There's no standard so use what makes sense to you
  • audio_codec: String to ID the coded used to encode the audio track.
  • width: The width of the video in pixels (e.g. 1920)
  • height: The height of the video in pixels (e.g. 1080)
  • frame_rate: Decimal frame rate. Since it's a decimal this will only be an approximation of the actual framerate.
  • size_bytes: Size of the video file in bytes
  • video_description: Free form text to describe the video
  • sha512: sha512 check sum encoded as a HEX string

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment