Videos
Introduction
In this tutorial we will focus on working with videos using Supervisely SDK.
You will learn how to:
π Everything you need to reproduce this tutorial is on GitHub: source code and demo data.
How to debug this tutorial
Step 1. Prepare ~/supervisely.env file with credentials. Learn more here.
Step 2. Clone repository with source code and demo data and create Virtual Environment.
Step 3. Open repository directory in Visual Studio Code.
Step 4. Change workspace ID in local.env file by copying the ID from the context menu of the workspace.

Step 5. Start debugging src/main.py.
Import libraries
Init API client
First, we load environment variables with credentials and init API for communicating with Supervisely Instance.
Get variables from environment
In this tutorial, you will need an workspace ID that you can get from environment variables. Learn more here
Create new project and dataset
Create new project.
Source code:
Output:
Create new dataset.
Source code:
Output:
Upload videos from local directory to Supervisely
Upload single video.
Source code:
Output:

Upload list of videos.
β Supervisely API allows uploading multiple videos in a single request. The code sample below sends fewer requests and it leads to a significant speed-up of our original code.
Source code:
Output:

Get information about videos
Single video.
Get information about video from Supervisely by id.
Source code:
Output:
You can also get information about video from Supervisely by name.
Source code:
Output:
Get all videos from dataset.
Get information about video from Supervisely by id.
Source code:
Output:
Download video
Download video from Supervisely to local directory by id. Source code:
Output:

Get video metadata
Get video metadata from file
Source code:
Output:
Get video metadata from server
Source code:
Output:
Download video frames as images
Download single frame of video as image from Supervisely to local directory.
Source code:
Output:
Download multiple frames in a single requests from Supervisely and save as images to local directory.
Source code:
Output:
Download video frames as RGB NumPy matrix
You can also download video frame as RGB NumPy matrix.
Source code:
Output:
Download multiple frames in a single requests from Supervisely as RGB NumPy matrix.
Source code:
Output:
Remove videos from Supervisely
Remove one video.
Remove video from Supervisely by id
Source code:
Output:
Remove list of videos.
Remove list of videos from Supervisely by ids.
Source code:
Output:
Information about available codecs, extensions, and containers.
Note: Only basic video codecs are available in the Community Edition, for additional video codecs you can try the Enterprise Edition.
The Enterprise Edition allows you to use the full range of extensions, containers and codecs listed below without any limits.
extensions: .avi, .mp4, .3gp, .flv, .webm, .wmv, .mov, .mkv
containers: mp4, webm, ogg, ogv
codecs: h264, vp8, vp9
In the Community Edition, it is recommended to use vp9, h264 codecs with mp4 container.
How to exract frames from videos correctly using the OpenCV library.
In case you need to exract frames from videos, you should be aware of one important detail of the OpenCV library. According to issue #15499, different versions of the OpenCV library have different values of the CAP_PROP_ORIENTATION_AUTO flag. This may cause that VideoCapture to ignore video orientation metadata. To avoid incorrect extraction of frames from videos, it is recommended to directly define flag CAP_PROP_ORIENTATION_AUTO:
Last updated
Was this helpful?