Skip to content

Capturing & Video

Screen/element capture and video recording, ported from FlaUI.Core.Capturing. Capture provides static helpers that return a CaptureImage (savable via to_file and usable as a context manager). VideoRecorder records the screen to a file and requires ffmpeg (see VideoRecorder.download_ffmpeg).

Settings

CaptureSettings and VideoRecorderSettings are Pydantic models: values are validated in Python (for example output_scale must be positive and frame_rate at least 1) before they reach FlaUI. cs_object builds the C# settings object and from_cs reads one back, so CaptureImage.settings returns the typed model the image was captured with.

C# property Python field Default
CaptureSettings.OutputWidth output_width -1 (keep aspect ratio)
CaptureSettings.OutputHeight output_height -1 (keep aspect ratio)
CaptureSettings.OutputScale output_scale 1.0
VideoRecorderSettings.ffmpegPath ffmpeg_path None
VideoRecorderSettings.FrameRate frame_rate 5
VideoRecorderSettings.TargetVideoPath target_video_path None
VideoRecorderSettings.UseCompressedImages use_compressed_images True
VideoRecorderSettings.VideoFormat video_format VideoFormat.x264
VideoRecorderSettings.VideoQuality video_quality 0
VideoRecorderSettings.EncodeWithLowPriority encode_with_low_priority False
VideoRecorderSettings.LogMissingFrames log_missing_frames True

Overlays

MouseOverlay and InfoOverlay are built from the image they draw on and passed straight to CaptureImage.apply_overlays. Raw C# ICaptureOverlay objects are still accepted, and the two can be mixed in one call.

from flaui.core.capturing import Capture, InfoOverlay, InfoOverlayPosition, MouseOverlay
from flaui.lib.system.drawing import Color

with Capture.element(window) as image:
    info = InfoOverlay(
        image,
        overlay_string_format="{dt:HH:mm:ss} / {name}",  # time and machine name
        overlay_position=InfoOverlayPosition.BottomRight,
        overlay_text_color=Color.Yellow,
    )
    image.apply_overlays(MouseOverlay(image), info).to_file(str(tmp_path / "annotated.png"))
using (var image = Capture.Element(window))
{
    var info = new InfoOverlay(image)
    {
        OverlayStringFormat = "{dt:HH:mm:ss} / {name}",
        OverlayPosition = InfoOverlayPosition.BottomRight,
        OverlayTextColor = Color.Yellow,
    };
    image.ApplyOverlays(new MouseOverlay(image), info).ToFile(@"C:\temp\annotated.png");
}

Durations are datetime.timedelta on the Python side: VideoRecorder.record_time_span and InfoOverlay.record_time_span (the {rt} placeholder) both use it. The overlay's font stays a C# System.Drawing.Font.

Recording video

The frame callback receives the running recorder, so each frame can stamp the elapsed time:

from flaui.core.capturing import (
    Capture,
    CaptureImage,
    CaptureSettings,
    InfoOverlay,
    MouseOverlay,
    VideoFormat,
    VideoRecorder,
    VideoRecorderSettings,
)

settings = VideoRecorderSettings(
    ffmpeg_path=r"C:\tools\ffmpeg.exe",  # or VideoRecorder.download_ffmpeg(folder)
    target_video_path=str(tmp_path / "run.mp4"),
    frame_rate=10,
    video_format=VideoFormat.xvid,  # bigger file, less CPU than x264
)

def frame(recorder: VideoRecorder) -> CaptureImage:
    """Capture one frame with the cursor and the elapsed recording time ({rt}) drawn on it."""
    image = Capture.main_screen(CaptureSettings(output_scale=0.5))
    info = InfoOverlay(image, overlay_string_format="{rt:hh\\:mm\\:ss}", record_time_span=recorder.record_time_span)
    return image.apply_overlays(info, MouseOverlay(image))

# with VideoRecorder.start(settings, frame) as recorder:  # needs ffmpeg at settings.ffmpeg_path
#     ...  # drive the application; leaving the block stops and encodes the video
var settings = new VideoRecorderSettings
{
    ffmpegPath = @"C:\tools\ffmpeg.exe",
    TargetVideoPath = @"C:\temp\run.mp4",
    FrameRate = 10,
    VideoFormat = VideoFormat.xvid,
};
using (var recorder = new VideoRecorder(settings, r =>
{
    var image = Capture.MainScreen(new CaptureSettings { OutputScale = 0.5 });
    var info = new InfoOverlay(image) { OverlayStringFormat = @"{rt:hh\:mm\:ss}", RecordTimeSpan = r.RecordTimeSpan };
    return image.ApplyOverlays(info, new MouseOverlay(image));
}))
{
    // drive the application
}

Reference

flaui.core.capturing.Capture

Static screen/element capture helpers (mirrors FlaUI.Core.Capturing.Capture).

element(element, settings=None) staticmethod

Capture a single automation element.

Parameters:

Name Type Description Default
element 'AutomationElement'

The element to capture.

required
settings Optional[CaptureSettings]

Optional output sizing settings.

None

Returns:

Type Description
CaptureImage

The captured image.

Source code in flaui/core/capturing.py
@staticmethod
@handle_csharp_exceptions
def element(element: "AutomationElement", settings: Optional[CaptureSettings] = None) -> CaptureImage:
    """Capture a single automation element.

    :param element: The element to capture.
    :param settings: Optional output sizing settings.
    :return: The captured image.
    """
    from FlaUI.Core.Capturing import Capture as CSCapture  # pyright: ignore

    return CaptureImage(raw_image=CSCapture.Element(element.raw_element, _cs_settings(settings)))

element_rectangle(element, rectangle, settings=None) staticmethod

Capture a rectangle (relative to the element) inside an element.

Parameters:

Name Type Description Default
element 'AutomationElement'

The element whose region to capture.

required
rectangle Rectangle

The rectangle relative to the element's top-left corner.

required
settings Optional[CaptureSettings]

Optional output sizing settings.

None

Returns:

Type Description
CaptureImage

The captured image.

Source code in flaui/core/capturing.py
@staticmethod
@handle_csharp_exceptions
def element_rectangle(
    element: "AutomationElement", rectangle: Rectangle, settings: Optional[CaptureSettings] = None
) -> CaptureImage:
    """Capture a rectangle (relative to the element) inside an element.

    :param element: The element whose region to capture.
    :param rectangle: The rectangle relative to the element's top-left corner.
    :param settings: Optional output sizing settings.
    :return: The captured image.
    """
    from FlaUI.Core.Capturing import Capture as CSCapture  # pyright: ignore

    return CaptureImage(
        raw_image=CSCapture.ElementRectangle(element.raw_element, rectangle.raw_value, _cs_settings(settings))
    )

main_screen(settings=None) staticmethod

Capture the primary screen.

Parameters:

Name Type Description Default
settings Optional[CaptureSettings]

Optional output sizing settings.

None

Returns:

Type Description
CaptureImage

The captured image.

Source code in flaui/core/capturing.py
@staticmethod
@handle_csharp_exceptions
def main_screen(settings: Optional[CaptureSettings] = None) -> CaptureImage:
    """Capture the primary screen.

    :param settings: Optional output sizing settings.
    :return: The captured image.
    """
    from FlaUI.Core.Capturing import Capture as CSCapture  # pyright: ignore

    return CaptureImage(raw_image=CSCapture.MainScreen(_cs_settings(settings)))

rectangle(bounds, settings=None) staticmethod

Capture a desktop-relative rectangle.

Parameters:

Name Type Description Default
bounds Rectangle

The screen region to capture.

required
settings Optional[CaptureSettings]

Optional output sizing settings.

None

Returns:

Type Description
CaptureImage

The captured image.

Source code in flaui/core/capturing.py
@staticmethod
@handle_csharp_exceptions
def rectangle(bounds: Rectangle, settings: Optional[CaptureSettings] = None) -> CaptureImage:
    """Capture a desktop-relative rectangle.

    :param bounds: The screen region to capture.
    :param settings: Optional output sizing settings.
    :return: The captured image.
    """
    from FlaUI.Core.Capturing import Capture as CSCapture  # pyright: ignore

    return CaptureImage(raw_image=CSCapture.Rectangle(bounds.raw_value, _cs_settings(settings)))

screen(screen_index=-1, settings=None) staticmethod

Capture a screen (or the whole virtual desktop when screen_index is out of range).

Parameters:

Name Type Description Default
screen_index int

Zero-based monitor index; -1 captures all monitors.

-1
settings Optional[CaptureSettings]

Optional output sizing settings.

None

Returns:

Type Description
CaptureImage

The captured image.

Source code in flaui/core/capturing.py
@staticmethod
@handle_csharp_exceptions
def screen(screen_index: int = -1, settings: Optional[CaptureSettings] = None) -> CaptureImage:
    """Capture a screen (or the whole virtual desktop when ``screen_index`` is out of range).

    :param screen_index: Zero-based monitor index; ``-1`` captures all monitors.
    :param settings: Optional output sizing settings.
    :return: The captured image.
    """
    from FlaUI.Core.Capturing import Capture as CSCapture  # pyright: ignore

    return CaptureImage(raw_image=CSCapture.Screen(screen_index, _cs_settings(settings)))

screens_with_element(element, settings=None) staticmethod

Capture every screen the given element overlaps.

Parameters:

Name Type Description Default
element 'AutomationElement'

The element to locate across screens.

required
settings Optional[CaptureSettings]

Optional output sizing settings.

None

Returns:

Type Description
CaptureImage

The captured image.

Source code in flaui/core/capturing.py
@staticmethod
@handle_csharp_exceptions
def screens_with_element(element: "AutomationElement", settings: Optional[CaptureSettings] = None) -> CaptureImage:
    """Capture every screen the given element overlaps.

    :param element: The element to locate across screens.
    :param settings: Optional output sizing settings.
    :return: The captured image.
    """
    from FlaUI.Core.Capturing import Capture as CSCapture  # pyright: ignore

    return CaptureImage(raw_image=CSCapture.ScreensWithElement(element.raw_element, _cs_settings(settings)))

flaui.core.capturing.CaptureImage

Bases: BaseModel

A captured image (mirrors FlaUI.Core.Capturing.CaptureImage).

Wraps the C# result of a :class:Capture call. Use :meth:to_file to persist it, or use it as a context manager to dispose the underlying bitmap automatically.

bitmap property

Return the underlying C# Bitmap.

bitmap_image property

Return the image as a C# WPF System.Windows.Media.Imaging.BitmapImage.

Each access encodes the bitmap again, so keep the result if you need it more than once.

original_bounds property

Return the desktop-relative bounding rectangle this image was captured from.

settings property

Return the settings the image was captured with, or None when none were given.

__enter__()

Enter the context manager.

Returns:

Type Description
'CaptureImage'

This :class:CaptureImage.

Source code in flaui/core/capturing.py
def __enter__(self) -> "CaptureImage":
    """Enter the context manager.

    :return: This :class:`CaptureImage`.
    """
    return self

__exit__(*exc_info)

Dispose the image on context-manager exit.

Parameters:

Name Type Description Default
exc_info Any

Standard (exc_type, exc, tb) tuple (unused).

()
Source code in flaui/core/capturing.py
def __exit__(self, *exc_info: Any) -> None:
    """Dispose the image on context-manager exit.

    :param exc_info: Standard ``(exc_type, exc, tb)`` tuple (unused).
    """
    self.dispose()

apply_overlays(*overlays)

Draw the given overlays onto the image, in order.

Parameters:

Name Type Description Default
overlays Union['ICaptureOverlay', Any]

Python overlays (:class:MouseOverlay, :class:InfoOverlay, any :class:ICaptureOverlay) or raw C# ICaptureOverlay instances; both may be mixed.

()

Returns:

Type Description
'CaptureImage'

This :class:CaptureImage (for chaining).

Source code in flaui/core/capturing.py
@handle_csharp_exceptions
def apply_overlays(self, *overlays: Union["ICaptureOverlay", Any]) -> "CaptureImage":
    """Draw the given overlays onto the image, in order.

    :param overlays: Python overlays (:class:`MouseOverlay`, :class:`InfoOverlay`, any
        :class:`ICaptureOverlay`) or raw C# ``ICaptureOverlay`` instances; both may be mixed.
    :return: This :class:`CaptureImage` (for chaining).
    """
    self.raw_image.ApplyOverlays(*map(_cs_overlay, overlays))
    return self

dispose()

Dispose the underlying bitmap and release its memory.

Source code in flaui/core/capturing.py
@handle_csharp_exceptions
def dispose(self) -> None:
    """Dispose the underlying bitmap and release its memory."""
    self.raw_image.Dispose()

to_file(file_path)

Save the image to a file; the extension selects the format (defaults to PNG).

Parameters:

Name Type Description Default
file_path str

Destination path (.png, .jpg, .gif, .tif, .bmp).

required
Source code in flaui/core/capturing.py
@handle_csharp_exceptions
def to_file(self, file_path: str) -> None:
    """Save the image to a file; the extension selects the format (defaults to PNG).

    :param file_path: Destination path (``.png``, ``.jpg``, ``.gif``, ``.tif``, ``.bmp``).
    """
    self.raw_image.ToFile(file_path)

flaui.core.capturing.CaptureSettings

Bases: BaseModel

Output sizing options for a capture (mirrors FlaUI.Core.Capturing.CaptureSettings).

output_width / output_height take precedence over output_scale; leave one of them at -1 to keep the aspect ratio.

cs_object property

Return the underlying C# CaptureSettings built from this model.

from_cs(cs_settings) classmethod

Build a model from a C# CaptureSettings instance.

Parameters:

Name Type Description Default
cs_settings Any

The C# FlaUI.Core.Capturing.CaptureSettings.

required

Returns:

Type Description
'CaptureSettings'

The equivalent :class:CaptureSettings.

Source code in flaui/core/capturing.py
@classmethod
def from_cs(cls, cs_settings: Any) -> "CaptureSettings":
    """Build a model from a C# ``CaptureSettings`` instance.

    :param cs_settings: The C# ``FlaUI.Core.Capturing.CaptureSettings``.
    :return: The equivalent :class:`CaptureSettings`.
    """
    return cls(
        output_width=cs_settings.OutputWidth,
        output_height=cs_settings.OutputHeight,
        output_scale=cs_settings.OutputScale,
    )

flaui.core.capturing.ICaptureOverlay

Bases: BaseModel

Wraps any C# FlaUI.Core.Capturing.ICaptureOverlay (something that draws onto a capture).

Use it directly to pass a custom C# overlay through the typed API, or use the concrete :class:MouseOverlay / :class:InfoOverlay.

draw(graphics)

Draw the overlay onto a C# System.Drawing.Graphics surface.

:meth:CaptureImage.apply_overlays calls this for you; call it directly only when drawing onto your own Graphics.

Parameters:

Name Type Description Default
graphics Any

The C# Graphics surface to draw on.

required
Source code in flaui/core/capturing.py
@handle_csharp_exceptions
def draw(self, graphics: Any) -> None:
    """Draw the overlay onto a C# ``System.Drawing.Graphics`` surface.

    :meth:`CaptureImage.apply_overlays` calls this for you; call it directly only when drawing
    onto your own ``Graphics``.

    :param graphics: The C# ``Graphics`` surface to draw on.
    """
    self.raw_overlay.Draw(graphics)

flaui.core.capturing.OverlayBase(capture_image=None, /, **data)

Bases: ICaptureOverlay

Base for overlays bound to a :class:CaptureImage (mirrors FlaUI.Core.Capturing.OverlayBase).

Subclasses are constructed from the image they will be drawn on, e.g. MouseOverlay(image). An existing C# overlay can be wrapped with MouseOverlay(raw_overlay=cs_overlay).

Create the C# overlay for capture_image, or wrap raw_overlay when given.

Parameters:

Name Type Description Default
capture_image Optional[CaptureImage]

The image the overlay will be drawn on.

None
data Any

Model fields; pass raw_overlay to wrap an existing C# overlay instead.

{}

Raises:

Type Description
ValueError

If neither capture_image nor raw_overlay is given.

Source code in flaui/core/capturing.py
def __init__(self, capture_image: Optional[CaptureImage] = None, /, **data: Any) -> None:
    """Create the C# overlay for ``capture_image``, or wrap ``raw_overlay`` when given.

    :param capture_image: The image the overlay will be drawn on.
    :param data: Model fields; pass ``raw_overlay`` to wrap an existing C# overlay instead.
    :raises ValueError: If neither ``capture_image`` nor ``raw_overlay`` is given.
    """
    if "raw_overlay" not in data:
        if capture_image is None:
            raise ValueError(f"{type(self).__name__} needs a CaptureImage (or raw_overlay=...)")
        data["raw_overlay"] = self._create_cs_overlay(capture_image.raw_image)
    super().__init__(**data)

capture_image property

Return the image this overlay draws on.

flaui.core.capturing.MouseOverlay(capture_image=None, /, **data)

Bases: OverlayBase

Draws the mouse cursor onto a capture (mirrors FlaUI.Core.Capturing.MouseOverlay).

Example::

with Capture.main_screen() as image:
    image.apply_overlays(MouseOverlay(image)).to_file("screen.png")
Source code in flaui/core/capturing.py
def __init__(self, capture_image: Optional[CaptureImage] = None, /, **data: Any) -> None:
    """Create the C# overlay for ``capture_image``, or wrap ``raw_overlay`` when given.

    :param capture_image: The image the overlay will be drawn on.
    :param data: Model fields; pass ``raw_overlay`` to wrap an existing C# overlay instead.
    :raises ValueError: If neither ``capture_image`` nor ``raw_overlay`` is given.
    """
    if "raw_overlay" not in data:
        if capture_image is None:
            raise ValueError(f"{type(self).__name__} needs a CaptureImage (or raw_overlay=...)")
        data["raw_overlay"] = self._create_cs_overlay(capture_image.raw_image)
    super().__init__(**data)

flaui.core.capturing.InfoOverlay(capture_image=None, /, **data)

Bases: OverlayBase

Draws a text bar (time, machine name, CPU/RAM, ...) onto a capture.

Mirrors FlaUI.Core.Capturing.InfoOverlay. Options may be passed as keyword arguments, e.g. InfoOverlay(image, overlay_position=InfoOverlayPosition.BottomRight). The text comes from :attr:overlay_string_format; FlaUI fills placeholders such as {dt} (now), {rt} (the :attr:record_time_span), {name} (machine name), {cpu} and {mem.p.used}.

Create the overlay and apply any option keyword arguments.

Parameters:

Name Type Description Default
capture_image Optional[CaptureImage]

The image the overlay will be drawn on.

None
data Any

raw_overlay to wrap an existing C# overlay, plus any of overlay_string_format, overlay_position, overlay_background_color, overlay_text_color, overlay_text_font and record_time_span.

{}
Source code in flaui/core/capturing.py
def __init__(self, capture_image: Optional[CaptureImage] = None, /, **data: Any) -> None:
    """Create the overlay and apply any option keyword arguments.

    :param capture_image: The image the overlay will be drawn on.
    :param data: ``raw_overlay`` to wrap an existing C# overlay, plus any of
        ``overlay_string_format``, ``overlay_position``, ``overlay_background_color``,
        ``overlay_text_color``, ``overlay_text_font`` and ``record_time_span``.
    """
    options = {name: data.pop(name) for name in _INFO_OVERLAY_OPTIONS if name in data}
    super().__init__(capture_image, **data)
    for name, value in options.items():
        setattr(self, name, value)

overlay_background_color property writable

Get the background color of the text bar.

overlay_position property writable

Get where the text bar is drawn.

overlay_string_format property writable

Get the text template drawn by the overlay.

overlay_text_color property writable

Get the text color.

overlay_text_font property writable

Get the text font (a C# System.Drawing.Font).

record_time_span property writable

Get the recording time shown by the {rt} placeholder.

flaui.core.capturing.InfoOverlayPosition

Bases: Enum

Where :class:InfoOverlay draws its text bar (mirrors FlaUI.Core.Capturing.InfoOverlayPosition).

flaui.core.capturing.CaptureUtilities

Scaling and cursor helpers used by captures (mirrors FlaUI.Core.Capturing.CaptureUtilities).

capture_cursor() staticmethod

Capture the current mouse cursor.

Returns:

Type Description
Tuple[Any, Point]

(bitmap, position): the cursor as a C# Bitmap (None when no cursor is shown) and its top-left screen position.

Source code in flaui/core/capturing.py
@staticmethod
@handle_csharp_exceptions
def capture_cursor() -> Tuple[Any, Point]:
    """Capture the current mouse cursor.

    :return: ``(bitmap, position)``: the cursor as a C# ``Bitmap`` (``None`` when no cursor is
        shown) and its top-left screen position.
    """
    from System.Drawing import Point as CSPoint  # pyright: ignore
    from FlaUI.Core.Capturing import CaptureUtilities as CSCaptureUtilities  # pyright: ignore

    bitmap, position = CSCaptureUtilities.CaptureCursor(CSPoint(0, 0))
    return bitmap, Point(raw_value=position)

delete_object(handle) staticmethod

Delete a GDI object handle (wraps the Win32 DeleteObject).

Parameters:

Name Type Description Default
handle int

The GDI handle (e.g. from Bitmap.GetHbitmap()).

required

Returns:

Type Description
bool

True if the handle was deleted.

Source code in flaui/core/capturing.py
@staticmethod
@handle_csharp_exceptions
def delete_object(handle: int) -> bool:
    """Delete a GDI object handle (wraps the Win32 ``DeleteObject``).

    :param handle: The GDI handle (e.g. from ``Bitmap.GetHbitmap()``).
    :return: ``True`` if the handle was deleted.
    """
    from System import IntPtr  # pyright: ignore
    from FlaUI.Core.Capturing import CaptureUtilities as CSCaptureUtilities  # pyright: ignore

    return bool(CSCaptureUtilities.DeleteObject(IntPtr(handle)))

get_scale(original_bounds, settings=None) staticmethod

Return the scale factor settings applies to a capture of original_bounds.

Parameters:

Name Type Description Default
original_bounds Rectangle

The bounds of the area being captured.

required
settings Optional[CaptureSettings]

The capture settings; None means unscaled (1.0).

None

Returns:

Type Description
float

The scale factor.

Source code in flaui/core/capturing.py
@staticmethod
@handle_csharp_exceptions
def get_scale(original_bounds: Rectangle, settings: Optional[CaptureSettings] = None) -> float:
    """Return the scale factor ``settings`` applies to a capture of ``original_bounds``.

    :param original_bounds: The bounds of the area being captured.
    :param settings: The capture settings; ``None`` means unscaled (``1.0``).
    :return: The scale factor.
    """
    from FlaUI.Core.Capturing import CaptureUtilities as CSCaptureUtilities  # pyright: ignore

    return float(CSCaptureUtilities.GetScale(original_bounds.raw_value, _cs_settings(settings)))

scale_according_to_settings(value, settings=None, original_bounds=None) staticmethod

Scale a point or rectangle the way settings scales a capture.

A :class:~flaui.lib.system.drawing.Rectangle is scaled against itself. A point (a :class:~flaui.lib.system.drawing.Point or an (x, y) tuple) needs the original_bounds of the capture it belongs to.

Parameters:

Name Type Description Default
value Union[Point, Rectangle, Tuple[int, int]]

The point or rectangle to scale.

required
settings Optional[CaptureSettings]

The capture settings; None leaves the value unscaled.

None
original_bounds Optional[Rectangle]

Bounds of the captured area (required for points).

None

Returns:

Type Description
Union[Point, Rectangle]

The scaled point or rectangle (same kind as value; tuples come back as a Point).

Raises:

Type Description
ValueError

If a point is given without original_bounds.

Source code in flaui/core/capturing.py
@staticmethod
@handle_csharp_exceptions
def scale_according_to_settings(
    value: Union[Point, Rectangle, Tuple[int, int]],
    settings: Optional[CaptureSettings] = None,
    original_bounds: Optional[Rectangle] = None,
) -> Union[Point, Rectangle]:
    """Scale a point or rectangle the way ``settings`` scales a capture.

    A :class:`~flaui.lib.system.drawing.Rectangle` is scaled against itself. A point (a
    :class:`~flaui.lib.system.drawing.Point` or an ``(x, y)`` tuple) needs the
    ``original_bounds`` of the capture it belongs to.

    :param value: The point or rectangle to scale.
    :param settings: The capture settings; ``None`` leaves the value unscaled.
    :param original_bounds: Bounds of the captured area (required for points).
    :return: The scaled point or rectangle (same kind as ``value``; tuples come back as a Point).
    :raises ValueError: If a point is given without ``original_bounds``.
    """
    from FlaUI.Core.Capturing import CaptureUtilities as CSCaptureUtilities  # pyright: ignore

    cs_settings = _cs_settings(settings)
    if isinstance(value, Rectangle):
        return Rectangle(raw_value=CSCaptureUtilities.ScaleAccordingToSettings(value.raw_value, cs_settings))
    if original_bounds is None:
        raise ValueError("original_bounds is required when scaling a point")
    point = value if isinstance(value, Point) else Point(raw_value=value)
    scaled = CSCaptureUtilities.ScaleAccordingToSettings(point.raw_value, original_bounds.raw_value, cs_settings)
    return Point(raw_value=scaled)

flaui.core.capturing.VideoRecorder

Bases: BaseModel

Records the screen (or a custom frame source) to a video file.

Mirrors FlaUI.Core.Capturing.VideoRecorder. Start a recording with :meth:start, then call :meth:stop (or use it as a context manager). Requires ffmpeg — see the module note.

record_time_span property

Return how long the recorder has been recording (feed it to :attr:InfoOverlay.record_time_span).

target_video_path property

Return the output video file path.

__enter__()

Enter the context manager.

Returns:

Type Description
'VideoRecorder'

This :class:VideoRecorder.

Source code in flaui/core/capturing.py
def __enter__(self) -> "VideoRecorder":
    """Enter the context manager.

    :return: This :class:`VideoRecorder`.
    """
    return self

__exit__(*exc_info)

Stop and dispose the recorder on context-manager exit.

Parameters:

Name Type Description Default
exc_info Any

Standard (exc_type, exc, tb) tuple (unused).

()
Source code in flaui/core/capturing.py
def __exit__(self, *exc_info: Any) -> None:
    """Stop and dispose the recorder on context-manager exit.

    :param exc_info: Standard ``(exc_type, exc, tb)`` tuple (unused).
    """
    self.dispose()

dispose()

Dispose the recorder (stops it if still running).

Source code in flaui/core/capturing.py
@handle_csharp_exceptions
def dispose(self) -> None:
    """Dispose the recorder (stops it if still running)."""
    self.raw_recorder.Dispose()

download_ffmpeg(target_folder) staticmethod

Download a static ffmpeg build into target_folder (blocking).

Parameters:

Name Type Description Default
target_folder str

Folder to download ffmpeg into.

required

Returns:

Type Description
str

The path to the downloaded ffmpeg executable.

Source code in flaui/core/capturing.py
@staticmethod
@handle_csharp_exceptions
def download_ffmpeg(target_folder: str) -> str:
    """Download a static ffmpeg build into ``target_folder`` (blocking).

    :param target_folder: Folder to download ffmpeg into.
    :return: The path to the downloaded ffmpeg executable.
    """
    from FlaUI.Core.Capturing import VideoRecorder as CSVideoRecorder  # pyright: ignore

    return CSVideoRecorder.DownloadFFMpeg(target_folder).Result

start(settings, capture_method=None) classmethod

Start recording.

Parameters:

Name Type Description Default
settings VideoRecorderSettings

Recorder settings (must include target_video_path).

required
capture_method Optional[Callable[['VideoRecorder'], CaptureImage]]

Optional callback (recorder) -> CaptureImage producing each frame. Defaults to capturing the whole virtual desktop.

None

Returns:

Type Description
'VideoRecorder'

The running :class:VideoRecorder.

Source code in flaui/core/capturing.py
@classmethod
@handle_csharp_exceptions
def start(
    cls,
    settings: VideoRecorderSettings,
    capture_method: Optional[Callable[["VideoRecorder"], CaptureImage]] = None,
) -> "VideoRecorder":
    """Start recording.

    :param settings: Recorder settings (must include ``target_video_path``).
    :param capture_method: Optional callback ``(recorder) -> CaptureImage`` producing each frame.
        Defaults to capturing the whole virtual desktop.
    :return: The running :class:`VideoRecorder`.
    """
    from System import Func  # pyright: ignore
    from FlaUI.Core.Capturing import (  # pyright: ignore
        Capture as CSCapture,
        CaptureImage as CSCaptureImage,
        VideoRecorder as CSVideoRecorder,
    )

    if capture_method is None:

        def _frame(_recorder: Any) -> Any:
            """Default frame source: capture the whole desktop."""
            return CSCapture.Screen()
    else:

        def _frame(recorder: Any) -> Any:
            """Bridge the C# frame request to the user's Python capture callback."""
            result = capture_method(cls(raw_recorder=recorder))
            return result.raw_image if isinstance(result, CaptureImage) else result

    delegate = Func[CSVideoRecorder, CSCaptureImage](_frame)
    # pylint: disable-next=too-many-function-args  # C# ctor; pylint resolves FlaUI.Core.Capturing to this module on case-insensitive file systems
    raw = CSVideoRecorder(settings.cs_object, delegate)
    return cls(raw_recorder=raw, keep_alive=(_frame, delegate))

stop()

Stop recording and finish encoding the output file.

Source code in flaui/core/capturing.py
@handle_csharp_exceptions
def stop(self) -> None:
    """Stop recording and finish encoding the output file."""
    self.raw_recorder.Stop()

flaui.core.capturing.VideoRecorderSettings

Bases: BaseModel

Settings for :class:VideoRecorder (mirrors FlaUI.Core.Capturing.VideoRecorderSettings).

cs_object property

Return the underlying C# VideoRecorderSettings built from this model.

from_cs(cs_settings) classmethod

Build a model from a C# VideoRecorderSettings instance.

Parameters:

Name Type Description Default
cs_settings Any

The C# FlaUI.Core.Capturing.VideoRecorderSettings.

required

Returns:

Type Description
'VideoRecorderSettings'

The equivalent :class:VideoRecorderSettings.

Source code in flaui/core/capturing.py
@classmethod
def from_cs(cls, cs_settings: Any) -> "VideoRecorderSettings":
    """Build a model from a C# ``VideoRecorderSettings`` instance.

    :param cs_settings: The C# ``FlaUI.Core.Capturing.VideoRecorderSettings``.
    :return: The equivalent :class:`VideoRecorderSettings`.
    """
    return cls(
        ffmpeg_path=cs_settings.ffmpegPath,
        frame_rate=int(cs_settings.FrameRate),
        target_video_path=cs_settings.TargetVideoPath,
        use_compressed_images=cs_settings.UseCompressedImages,
        video_format=VideoFormat(int(cs_settings.VideoFormat)),
        video_quality=cs_settings.VideoQuality,
        encode_with_low_priority=cs_settings.EncodeWithLowPriority,
        log_missing_frames=cs_settings.LogMissingFrames,
    )

flaui.core.capturing.VideoFormat

Bases: Enum

Video codec used by :class:VideoRecorder (mirrors FlaUI.Core.Capturing.VideoFormat).