vc2_conformance.file_format
: Picture file format I/O¶
The vc2_conformance.file_format
module contains functions for reading
and writing raw pictures and their metadata as files.
Picture and metadata files must come in pairs with the raw planar picture data file having the extension ‘.raw’ and the metadata file having the extension ‘.json’. See Video file format for a description of the file format.
The following functions may be used to read and write picture/metadata files:
-
read
(filename)¶ Read a picture from a data and metadata file.
Convenience wrapper around
read_picture()
andread_metadata()
.- Parameters
- filenamestr
The filename of either the picture data file (.raw) or metadata file (.json). The name of the other file will be inferred automatically.
- Returns
- picture{“Y”: [[s, …], …], “C1”: …, “C2”: …, “pic_num”: int}
- video_parameters
VideoParameters
- picture_coding_mode
PictureCodingModes
-
write
(picture, video_parameters, picture_coding_mode, filename)¶ Write a picture to a data and metadata file.
Convenience wrapper around
write_picture()
andwrite_metadata()
.- Parameters
- picture{“Y”: [[s, …], …], “C1”: …, “C2”: …, “pic_num”: int}
- video_parameters
VideoParameters
- picture_coding_mode
PictureCodingModes
- filenamestr
The filename of either the picture data file (.raw) or metadata file (.json). The name of the other file will be inferred automatically.
The above functions are just wrappers around the following functions which read and write picture and metadata files in isolation:
-
read_metadata
(file)¶ Read a JSON picture metadata file.
- Parameters
- file
file
A file open for binary reading.
- file
- Returns
- video_parameters
VideoParameters
- picture_coding_mode
PictureCodingModes
- picture_numberint
- video_parameters
-
read_picture
(video_parameters, picture_coding_mode, picture_number, file)¶ Read a picture from a file.
- Parameters
- video_parameters
VideoParameters
- picture_coding_mode
PictureCodingModes
- picture_numberint
- file
file
A file open for binary reading.
- video_parameters
- Returns
- picture{“Y”: [[s, …], …], “C1”: …, “C2”: …, “pic_num”: int}
-
write_metadata
(picture, video_parameters, picture_coding_mode, file)¶ Write the metadata associated with a decoded picture to a file as JSON.
- Parameters
- picture{“Y”: [[s, …], …], “C1”: …, “C2”: …, “pic_num”: int}
- video_parameters
VideoParameters
- picture_coding_mode
PictureCodingModes
- file
file
A file open for binary writing.
-
write_picture
(picture, video_parameters, picture_coding_mode, file)¶ Write a decoded picture to a file as a planar image.
- Parameters
- picture{“Y”: [[s, …], …], “C1”: …, “C2”: …, “pic_num”: int}
- video_parameters
VideoParameters
- picture_coding_mode
PictureCodingModes
- file
file
A file open for binary writing.
Finally, the following function may be used to get the filenames for both parts of a picture/metadata file pair:
-
get_metadata_and_picture_filenames
(filename)¶ Given either the filename of a saved picture (.raw) or metadata file (.json), return a (metadata_filename, picture_filename) tuple with the names of the two corresponding files.