Skip to content

Segmentation fault while creating a text clip #55

@Gandhi-Sagar

Description

@Gandhi-Sagar

Problem

Segmentation fault.
In the logs, I see that PIL throws an error: PIL.Image - DEBUG - Error closing: Operation on closed image - 2023-06-05 20:45:11,107
Celery logs:

  | Traceback (most recent call last):   File "/Users/user1/opt/anaconda3/envs/bab/lib/python3.10/site-packages/billiard/pool.py", line 1265, in mark_as_worker_lost     raise WorkerLostError( billiard.exceptions.WorkerLostError: Worker exited prematurely: signal 11 (SIGSEGV) Job: 0.
-- | --

Code

I don't have a minimal example that replicates the error at the moment, but will add that tomorrow.
Code layout basically is as follows:

  1. API receives a request, and starts a celery task
  2. In the task, after some other sub-tasks, I render text as follows
       text_clip_mask = VideoClip(
            lambda t: make_frame_double_text(t)[:, :, 3] / 255.0,
            duration=render_duration,
            ismask=True,
        )
  1. in the make_frame_double_text function:
        text_segments = broken_text.split("\n")
        text_elements = []
        for i, t in enumerate(text_segments):
            x = 0 + TEXT_BOX_BORDER + 25 if i else 0 + TEXT_BOX_BORDER
            y = start_y + (i * LINE_BREAK_HEIGHT)
            text_elements.append(
                gizeh.text(
                    "  " + t,
                    fontfamily=FONT_FAMILY,
                    fontsize=SCALED_FONT_SIZE,
                    h_align="left",
                    v_align="top",
                    xy=[x, y],
                    fontslant="normal",
                    stroke=(0, 0, 0),
                    stroke_width=2,
                    fill=(1, 1, 1),
                )
            )
        for te in text_elements:
            te.draw(surface)

And this is where I get the segfault.
Here is a bit more of log if that is going to be helpful:

PIL.PngImagePlugin - DEBUG - STREAM b'IHDR' 16 13 - 2023-06-05 20:45:11,060
PIL.PngImagePlugin - DEBUG - STREAM b'pHYs' 41 9 - 2023-06-05 20:45:11,060
PIL.PngImagePlugin - DEBUG - STREAM b'PLTE' 62 12 - 2023-06-05 20:45:11,061
PIL.PngImagePlugin - DEBUG - STREAM b'IDAT' 86 6972 - 2023-06-05 20:45:11,061
PIL.PngImagePlugin - DEBUG - STREAM b'IHDR' 16 13 - 2023-06-05 20:45:11,062
PIL.PngImagePlugin - DEBUG - STREAM b'pHYs' 41 9 - 2023-06-05 20:45:11,062
PIL.PngImagePlugin - DEBUG - STREAM b'PLTE' 62 12 - 2023-06-05 20:45:11,062
PIL.PngImagePlugin - DEBUG - STREAM b'IDAT' 86 6972 - 2023-06-05 20:45:11,062
PIL.Image - DEBUG - Error closing: Operation on closed image - 2023-06-05 20:45:11,107

What has been tried and zeroed down:

I tried debugging by stepping inside gizeh, and error occurs on the first line of the (text's) draw function.

Environment

OS: macOS Monterey
Python version: 3.10.11
celery version: 5.2.7
moviepy: 1.0.3

Any help is appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions