Writer

class plugins.convert.writer.gif.Writer(output_folder: str, total_count: int, frame_ranges: list[tuple[int, int]] | None, **kwargs)

Bases: Output

GIF output writer using PIL.

Parameters:
  • output_folder (str) – The folder to save the output gif to

  • total_count (int) – The total number of frames to be converted

  • frame_ranges (list[tuple[int, int]] | None) – List of tuples for starting and end values of each frame range to be converted or None if all frames are to be converted

  • kwargs – Any additional standard plugins.convert.writer._base.Output key word arguments.

Attributes Summary

is_stream

Whether the writer outputs a stream or a series images.

output_alpha

Override if the plugin can output an alpha channel and the user configuration option is set to use it.

Methods Summary

cache_frame(filename, image)

Add the incoming converted frame to the cache ready for writing out.

close()

Close the GIF writer on completion.

get_output_filename(filename, extension[, ...])

Obtain the full path for the output file, including the correct extension, for the given input filename.

pre_encode(image, **kwargs)

Some writer plugins support the pre-encoding of images prior to saving out.

write(filename, image)

Frames come from the pool in arbitrary order, so frames are cached for writing out in the correct order.

Attributes Documentation

is_stream

Whether the writer outputs a stream or a series images.

Writers that write to a stream have a frame_order parameter to dictate the order in which frames should be written out (eg. gif/ffmpeg)

output_alpha

Override if the plugin can output an alpha channel and the user configuration option is set to use it. Default False

Methods Documentation

cache_frame(filename: str, image: ndarray) None

Add the incoming converted frame to the cache ready for writing out.

Used for ffmpeg and gif writers to ensure that the frames are written out in the correct order.

Parameters:
  • filename (str) – The filename of the incoming frame, where the frame index can be extracted from

  • image (ndarray) – The converted frame corresponding to the given filename

Return type:

None

close() None

Close the GIF writer on completion.

Return type:

None

get_output_filename(filename: str, extension: str, separate_mask: bool = False) list[str]

Obtain the full path for the output file, including the correct extension, for the given input filename.

Parameters:
  • filename (str) – The input frame filename to generate the output file name for

  • extension (str) – The extension to use for the output file

  • separate_mask (bool) – True if the mask should be saved out to a sub-folder otherwise False

Returns:

  • The full path for the output converted frame to be saved to in position 1. The full path

  • for the mask to be output to in position 2 (if requested)

Return type:

list[str]

pre_encode(image: ndarray, **kwargs) Any

Some writer plugins support the pre-encoding of images prior to saving out. As patching is done in multiple threads, but writing is done in a single thread, it can speed up the process to do any pre-encoding as part of the converter process.

If the writer supports pre-encoding then override this to pre-encode the image in lib.convert to speed up saving.

Parameters:

image (ndarray) – The converted image that is to be run through the pre-encoding function

Returns:

  • If None then the writer does not support pre-encoding, otherwise return output of the

  • plugin specific pre-encode function

Return type:

Any

write(filename: str, image: npt.NDArray[np.uint8]) None

Frames come from the pool in arbitrary order, so frames are cached for writing out in the correct order.

Parameters:
  • filename (str) – The incoming frame filename.

  • image (npt.NDArray[np.uint8]) – The converted image to be written

Return type:

None

close() None

Close the GIF writer on completion.

Return type:

None

write(filename: str, image: npt.NDArray[np.uint8]) None

Frames come from the pool in arbitrary order, so frames are cached for writing out in the correct order.

Parameters:
  • filename (str) – The incoming frame filename.

  • image (npt.NDArray[np.uint8]) – The converted image to be written

Return type:

None