mjpeg — mjpeg recording¶
The mjpeg module is used for mjpeg recording. Use it to record long video
clips as compressed image data. Use gif for short clips.
Example usage:
import csi, mjpeg, time
# Setup camera.
csi0 = csi.CSI()
csi0.reset()
csi0.pixformat(csi.RGB565)
csi0.framesize(csi.QVGA)
csi0.snapshot(time=2000)
c = time.clock()
# Create the mjpeg object.
m = mjpeg.Mjpeg("example.mjpeg")
# Add frames.
for i in range(100):
c.tick()
m.add_frame(csi0.snapshot())
# Finalize.
m.close()
class Mjpeg – Mjpeg recorder¶
- class mjpeg.Mjpeg(path: str, width: int | None = None, height: int | None = None)¶
Create a Mjpeg object which you can add frames to.
pathis the file system path to save the mjpeg recording to.widthis the horizontal resolution of the mjpeg file. Defaults to the main framebuffer width when not specified.heightis the vertical resolution of the mjpeg file. Defaults to the main framebuffer height when not specified.- is_closed() bool¶
Returns
Trueif the file has been closed. No more data can be written to a closed file.
- add_frame(image: image.Image, roi: Tuple[int, int, int, int] | None = None, rgb_channel: int = -1, alpha: int = 255, color_palette: image.Image | None = None, alpha_palette: image.Image | None = None, hint: int = 0, quality: int = 90) None¶
Append
imageto the mjpeg recording. The image is automatically scaled while preserving aspect ratio to the resolution specified when the file was created. Any image format is accepted; this method decompresses, scales/converts, and re-compresses as needed.roiis the region-of-interest rectangle tuple(x, y, w, h)ofimageto copy. Defaults to the whole image.rgb_channelis the RGB channel (0=R, 1=G, 2=B) to extract from an RGB565 source image and render in grayscale.-1(default) disables channel extraction.alpha(0-255) controls how much of the source image to blend into the destination.255is opaque; lower values blend with a black background;0results in a black frame.color_paletteis either a color palette enum (e.g.image.PALETTE_RAINBOW) or a 256-pixel RGB565 image used as a color lookup table on the grayscale value of the source image. Applied afterrgb_channelextraction.alpha_paletteis a 256-pixel grayscale image used as an alpha lookup table modulatingalphaper source pixel based on its grayscale value.255is opaque;0is transparent. Applied afterrgb_channelextraction.hintis a logical OR of:image.AREA: Use area scaling when downscaling.image.BILINEAR: Use bilinear scaling.image.BICUBIC: Use bicubic scaling.image.CENTER: Center the image on the destination.image.HMIRROR: Horizontally mirror the image.image.VFLIP: Vertically flip the image.image.TRANSPOSE: Transpose the image (swap x/y).image.EXTRACT_RGB_CHANNEL_FIRST: Applyrgb_channelbefore scaling.image.APPLY_COLOR_PALETTE_FIRST: Applycolor_palettebefore scaling.image.SCALE_ASPECT_KEEP: Scale to fit inside the destination.image.SCALE_ASPECT_EXPAND: Scale to fill the destination (crops).image.SCALE_ASPECT_IGNORE: Scale to fill the destination (stretches).image.ROTATE_90: Rotate by 90 degrees (VFLIP | TRANSPOSE).image.ROTATE_180: Rotate by 180 degrees (HMIRROR | VFLIP).image.ROTATE_270: Rotate by 270 degrees (HMIRROR | TRANSPOSE).
quality(0-100) is the JPEG compression quality used for non-JPEG source images.
- write(image: image.Image, roi: Tuple[int, int, int, int] | None = None, rgb_channel: int = -1, alpha: int = 255, color_palette: image.Image | None = None, alpha_palette: image.Image | None = None, hint: int = 0, quality: int = 90) None¶
Alias for
Mjpeg.add_frame().