writeVideoScenes - Write video sequence to video file - MATLAB (original) (raw)

Write video sequence to video file

Since R2021b

Syntax

Description

[filenames](#mw%5F34cbbe6f-85db-4874-a7d2-b2807a5a6c65) = writeVideoScenes([gTruth](#mw%5F34dcaaf7-7fdf-4cd3-b334-050620eefb3b),[timeRanges](#mw%5Fd5a545a7-be00-485b-956b-6eac62151c56),[folderNames](#mw%5F043d401c-827d-498b-aabd-7c2ae9e158b9)) writes sequences of ground truth data to separate files, filenames, that correspond to time ranges, timeRanges. Video files are written to the folders specified by the folderNames input.

The function writes video scenes using the image data and corresponding timestamp data contained in the specified groundTruth objects. All nonimage data, such as lidar, is ignored.

example

[filenames](#mw%5F34cbbe6f-85db-4874-a7d2-b2807a5a6c65) = writeVideoScenes([gTruth](#mw%5F34dcaaf7-7fdf-4cd3-b334-050620eefb3b),[timeRanges](#mw%5Fd5a545a7-be00-485b-956b-6eac62151c56),[rootFolder](#mw%5F32382a1d-886f-49d6-961c-10f493e65d53),[folderNames](#mw%5F043d401c-827d-498b-aabd-7c2ae9e158b9)) also specifies the root folder name to prepend to each of the folder names.

[filenames](#mw%5F34cbbe6f-85db-4874-a7d2-b2807a5a6c65) = writeVideoScenes(___,[Name=Value](#namevaluepairarguments)) specifies options using name-value arguments, in addition to any combination of input arguments from previous syntaxes. For example,writeVideoScenes(gTruth,timeRanges,folderNames,Verbose=true) displays progress information while writing video scenes to files.

Examples

collapse all

Load ground truth scene label definitions and label data into the workspace.

data = load("groundTruthSceneLabels.mat"); labelDefinitions = data.labelDefinitions; labelData = data.labelData;

Create a ground truth data source using a video file.

gSource = groundTruthDataSource("viptrain.avi");

Create a ground truth object using the ground truth data source.

gTruth = groundTruth(gSource,labelDefinitions,labelData);

Gather all the scene time ranges and the scene labels.

[timeRanges,sceneLabels] = sceneTimeRanges(gTruth);

Select a folder in the temp directory to write the video scenes to.

rootFolder = fullfile(tempdir,"videoScenes");

Use the scene label names as folder names.

folderNames = sceneLabels;

Write the video scenes to the "videoScenes" folder. Specify the subfolder names for each duration as the scene label names.

filenames = writeVideoScenes(gTruth,timeRanges,rootFolder,folderNames);

[==================================================] 100% Elapsed time: 00:00:01 Estimated time remaining: 00:00:00

Input Arguments

collapse all

Time ranges of ground truth source data, specified as an _M_-by-1 cell array for a groundTruth object or an_M_-by-N cell array for agroundTruthMultisignal object. M is the number of elements in gTruth and N represents the number of signals per element. Each cell of the array contains a_T_-by-2 duration matrix, where T is the number of time ranges in the corresponding element of gTruth. Each row of the matrix corresponds to a time range in the ground truth data for which a scene label has been applied, specified in the form [rangeStart _rangeEnd_].

Folder names for the video scenes, specified as an _M_-by-1 cell array for a groundTruth object or an_M_-by-N cell array for agroundTruthMultisignal object. Each cell in the cell array corresponds to an element of gTruth, and contains a_T_-by-1 vector of strings or categorical vector that specifies the paths to the folders for the corresponding time ranges.

You must specify each folder name must be specified as a full path or as a relative path from the current folder. When you specify a folder name that does not exist, the function creates a new folder with the specified name. When writing video scene files, the function overwrites files with the same name that already exists in the specified folder. For example, if you call the writeVideoScenes function twice with the same input arguments, the files output by the second function call overwrite those from the first.

To select and write specific signals in a groundTruthMultisignal object to a specified location, use the selectLabelsBySignalName (Automated Driving Toolbox) function before calling thewriteVideoScene function.

Root folder name to prepend to each of the folder names, specified as a character vector or a string scalar.

Name-Value Arguments

collapse all

Example: writeVideoScenes(gTruth,timeRanges,folderNames,Verbose=true) displays progress information while writing video scenes to files.

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, whereName is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

File name prefix, specified as an array of strings or a cell array of character vectors. Default values depend on the gTruth input type:

Video profile for writing video scenes, specified as one of the video profiles listed in the table. The VideoProfile argument usage is the same as the profile argument of the VideoWriter object.

Value of VideoProfile Description
"Archival" Motion JPEG 2000 file with lossless compression
"Motion JPEG AVI" AVI file using Motion JPEG encoding
"Motion JPEG 2000" Motion JPEG 2000 file
'MPEG-4' MPEG-4 file with H.264 encoding (systems with Windows® 7 or later, or macOS 10.7 and later)
'Uncompressed AVI' Uncompressed AVI file with RGB24 video
'Indexed AVI' Uncompressed AVI file with indexed video
'Grayscale AVI' Uncompressed AVI file with grayscale video

Display progress on screen, specified as a logical1(true) or0(false).

Output Arguments

collapse all

Full path file names to the saved video scenes, returned as an_M_-by-1 cell array of _T_-by-1 vector of strings.M is the number of elements in the gTruth input argument. T is the number of time ranges in the corresponding element of gTruth. Each element of the vector of strings specifies the full path to the saved video scene for the corresponding time range.

The function sets the output file names asNamePrefix_ UID.EXT, where_UID_ is a unique integer index for each written scene and_EXT_ is the video file extension determined by theVideoProfile argument.

Version History

Introduced in R2021b

See Also

Objects

Functions