video¶
Classes
|
Functions
|
Count number of video streams in video. |
|
|
|
Create name to video stream from given filename and index of stream. |
Gets image size and number of frames from Video file. |
|
|
Get information about video from given path. |
|
Returns HTML link to labeling tool for given url which will be opened in new tab. |
|
Returns url to labeling tool for given video and frame. |
|
Get list of video streams from given list of all streams. |
|
Checks if Video file from given path has supported extension. |
|
Checks if given extension is supported. |
|
Checks if Video file from given path could be read and has supported extension. |
|
Raises error if given extension is not supported. |
|
Raise error if Video file from given path couldn't be read or file extension is not supported. |
|
Create logger if it was not there and displays message about the need for transcoding. |
Description
Functions for processing videos
- count_video_streams(all_streams)[source]¶
Count number of video streams in video.
- Parameters
- all_streams : List[dict]
List of Video file audio and video streams.
- Returns
Number of video streams in Video file
- Return type
int
- gen_video_stream_name(file_name, stream_index)[source]¶
Create name to video stream from given filename and index of stream.
- Parameters
- file_name : str
Video file name.
- stream_index : int
Stream index.
- Returns
str
- Return type
str
- Usage example
stream_name = gen_video_stream_name('my_video.mp4', 2) print(stream_name) # Output: my_video_stream_2_CULxO.mp4
- get_image_size_and_frames_count(path)[source]¶
Gets image size and number of frames from Video file.
- Parameters
- path : str
Path to Video file.
- Returns
Image size and number of Video frames.
- Return type
Tuple[Tuple[int, int], int]- Usage example
import supervisely as sly video_path = "/home/admin/work/videos/Cars/ds0/video/6x.mp4" video_info = sly.video.get_image_size_and_frames_count(video_path) print(video_info) # Output: ((720, 1280), 152)
-
get_info(video_path, cpu_count=
None)[source]¶ Get information about video from given path.
- Parameters
- video_path : str
Video file path.
- cpu_count : int
CPU count.
- Raises
ValueErrorif no video streams found.- Returns
Information about video
- Return type
Dict- Usage example
from supervisely.video.video import get_info video_info = get_info('/home/video/1.mp4') print(json.dumps(video_info, indent=4)) # Output: { # "streams": [ # { # "index": 0, # "width": 1920, # "height": 1080, # "duration": 16.666667, # "rotation": 0, # "codecName": "mpeg4", # "codecType": "video", # "startTime": 0, # "framesCount": 500, # "framesToTimecodes": [ # 0.0, # 0.033333, # 0.066667, # 0.1, # ... # 16.566667, # 16.6, # 16.633333 # ] # } # ], # "formatName": "mov,mp4,m4a,3gp,3g2,mj2", # "duration": 16.667, # "size": "61572600" # }
-
get_labeling_tool_link(url, name=
'open in labeling tool')[source]¶ Returns HTML link to labeling tool for given url which will be opened in new tab.
- Parameters
- url : str
URL for the HTML link.
- name : Optional[str]
text of the link, defaults to “open in labeling tool”.
- Returns
HTML link to labeling tool.
- Return type
str
-
get_labeling_tool_url(dataset_id, video_id, frame=
0, link=False, link_text='open in labeling tool')[source]¶ Returns url to labeling tool for given video and frame. If link is True, returns html link to labeling tool, which will be opened in new tab. See usage example below.
- Parameters
- dataset_id : int
ID of the dataset, where video is stored.
- video_id : int
ID of the video to get labeling tool url for.
- frame : Optional[int]
Frame number to get labeling tool url for, defaults to 0.
- link : Optional[bool]
If True, returns html link to labeling tool, defaults to False.
- link_text : Optional[str]
Text of the link, defaults to “open in labeling tool”.
- Returns
Labeling tool url or html link to labeling tool.
- Return type
str
- Usage example
import os from dotenv import load_dotenv import supervisely as sly # Load secrets and create API object from .env file (recommended) # Learn more here: https://developer.supervisely.com/getting-started/basics-of-authentication load_dotenv(os.path.expanduser("~/supervisely.env")) api = sly.Api.from_env() dataset_id = 123 video_id = 456 # Get url to labeling tool for the 20 frame of the video url = sly.video.get_labeling_tool_url(dataset_id, video_id, frame=20) print(url) # Output: http://your-supervisely-server.com/app/videos_v2/?datasetId=123&videoId=456&videoFrame=20 # Get html link to labeling tool for the 20 frame of the video link = sly.video.get_labeling_tool_url(dataset_id, video_id, frame=20, link=True) print(link) # Output: <a href="http://your-supervisely-server.com/app/videos_v2/?datasetId=123&videoId=456&videoFrame=20" # rel="noopener noreferrer" target="_blank">open in labeling tool<i class="zmdi zmdi-open-in-new" style="margin-left: 5px"></i></a>
- get_video_streams(all_streams)[source]¶
Get list of video streams from given list of all streams.
- Parameters
- all_streams : List[dict]
List of Video file audio and video streams.
- Returns
List of video streams in Video file.
- Return type
list
- has_valid_ext(path)[source]¶
Checks if Video file from given path has supported extension.
- Parameters
- path : str
Path to Video file.
- Returns
bool
- Return type
bool- Usage example
import supervisely as sly video_path = "/home/admin/work/videos/Cars/ds0/video/6x.mp4" sly.video.has_valid_ext(video_path) # True
- is_valid_ext(ext)[source]¶
Checks if given extension is supported.
- Parameters
- ext : str
Video file extension.
- Returns
bool
- Return type
bool- Usage example
import supervisely as sly sly.video.is_valid_ext(".mp4") # True sly.video.is_valid_ext(".jpeg") # False
- is_valid_format(path)[source]¶
Checks if Video file from given path could be read and has supported extension.
- Parameters
- path : str
Path to Video file.
- Returns
True if file format in list of supported video formats, False - in otherwise
- Return type
bool- Usage example
import supervisely as sly video_path = "/video/video.jpg" sly.video.is_valid_format(video_path) # False
- validate_ext(ext)[source]¶
Raises error if given extension is not supported.
- Parameters
- ext : str
Video extension. Available extensions: avi, mp4, 3gp, flv, webm, wmv, mov, mkv.
- Raises
UnsupportedVideoFormatif given video with extension that is not supported.- Returns
None
- Return type
NoneType- Usage example
import supervisely as sly sly.video.validate_ext(".jpeg") # Unsupported video extension: .jpeg. # Only the following extensions are supported: ['.avi', '.mp4', '.3gp', '.flv', '.webm', '.wmv', '.mov', '.mkv'].
- validate_format(path)[source]¶
Raise error if Video file from given path couldn’t be read or file extension is not supported.
- Parameters
- path : str
Path to Video file.
- Raises
VideoReadExceptionif Video file from given path couldn’t be read or file extension is not supported- Returns
None
- Return type
NoneType- Usage example
import supervisely as sly video_path = "/home/paul/work/sphinx-docs/supervisely_py/docs/source/debug/video/Prius_360/ds0/video/video.jpg" sly.video.validate_format(video_path) # Unsupported video extension: .jpg. Only the following extensions are supported: ['.avi', '.mp4', '.3gp', '.flv', '.webm', '.wmv', '.mov', '.mkv'].