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() and read_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_parametersVideoParameters
picture_coding_modePictureCodingModes
write(picture, video_parameters, picture_coding_mode, filename)

Write a picture to a data and metadata file.

Convenience wrapper around write_picture() and write_metadata().

Parameters
picture{“Y”: [[s, …], …], “C1”: …, “C2”: …, “pic_num”: int}
video_parametersVideoParameters
picture_coding_modePictureCodingModes
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
filefile

A file open for binary reading.

Returns
video_parametersVideoParameters
picture_coding_modePictureCodingModes
picture_numberint
read_picture(video_parameters, picture_coding_mode, picture_number, file)

Read a picture from a file.

Parameters
video_parametersVideoParameters
picture_coding_modePictureCodingModes
picture_numberint
filefile

A file open for binary reading.

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_parametersVideoParameters
picture_coding_modePictureCodingModes
filefile

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_parametersVideoParameters
picture_coding_modePictureCodingModes
filefile

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.