MCAP Video ingest in Python

This guide will walk you through the process of downloading a sample MCAP file, inspecting it to find video topics, and ingesting the video into Nominal.

Prerequisites

Make sure you have the following Python packages installed:

  • huggingface_hub
  • mcap
  • nominal

You can install them all using:

1pip3 install huggingface_hub mcap nominal

Step 1: Download the Sample MCAP File

First, download a sample MCAP file using the huggingface_hub library.

1from huggingface_hub import hf_hub_download
2
3video_path = hf_hub_download(
4 repo_id="nominal-io/xplane",
5 filename="xplane.mcap",
6 repo_type='dataset'
7)
8
9print(f"File saved to: {video_path}")

Step 2: Inspect the MCAP File to Find Video Topics

Next, use the mcap library to inspect the MCAP file and identify available video topics.

1from mcap.reader import make_reader
2
3with open(video_path, "rb") as f:
4 reader = make_reader(f)
5
6 schemas = reader.get_summary().schemas
7 channels = reader.get_summary().channels
8
9 def schema_name(channel):
10 schema = schemas.get(channel.schema_id)
11 if not schema:
12 return None
13 return schema.name
14
15 video_topics = [
16 channel.topic for channel in channels.values()
17 if schema_name(channel) == "foxglove.CompressedVideo"
18 ]
19
20 print("Video topics: ", video_topics)

This script will output the video topics available in the MCAP file, which you’ll use in the next step.

Step 3: Connect to Nominal

Before ingesting the video, ensure you’re connected to Nominal.

Get your Nominal API token from your User settings page.

See the Quickstart for more details on connecting to Nominal from Python.

1import nominal.nominal as nm
2
3nm.set_token(
4 base_url = 'https://api.gov.nominal.io/api',
5 token = '* * *' # Replace with your Access Token from
6 # https://app.gov.nominal.io/settings/user?tab=tokens
7)
If you’re not sure whether your company has a Nominal tenant, please reach out to us.

Step 4: Ingest the Video

Finally, upload the video to Nominal using a topic from the list.

1import nominal.nominal as nm
2
3video = nm.upload_mcap_video(video_path, "video")
4print(video)