gif — gif recording¶
The gif module is used for gif recording.
class Gif – Gif recorder¶
You can use the gif module to record small video clips. Note that gif files save
uncompressed image data. So, they are best for recording short video clips that
you want to share. Use mjpeg for long clips.
Example usage:
import csi, gif
# Setup camera.
csi0 = csi.CSI()
csi0.reset()
csi0.pixformat(csi.GRAYSCALE)
csi0.framesize(csi.QQVGA)
csi0.snapshot(time=2000)
# Create the gif object.
g = gif.Gif("example.gif")
# Add frames.
for i in range(100):
g.add_frame(csi0.snapshot())
# Finalize.
g.close()
- class gif.Gif(filename: str, width: int | None = None, height: int | None = None, color: bool | None = None, loop: bool = True)¶
Creates a Gif object which frames can be added to.
filenameis the path to save the gif recording to.widthdefaults to the main framebuffer horizontal resolution.heightdefaults to the main framebuffer vertical resolution.colordefaults to the main framebuffer color mode:False results in a
sensor.GRAYSCALE7-bit per pixel gif.True results in a
sensor.RGB5657-bit per pixel gif.
loopwhen True results in the gif automatically looping on playback.- format() int¶
Returns
sensor.RGB565if color is True orsensor.GRAYSCALEotherwise.
- add_frame(image: image.Image, delay: int = 10) None¶
Adds an image to the gif recording. The image width, height, and color mode must match the values used in the constructor.
delayis the number of centi-seconds to wait before displaying this frame after the previous frame.