Back to Remotion

Flickering when using background-image or mask-image

packages/docs/docs/troubleshooting/background-image.mdx

4.0.4601.9 KB
Original Source

The following code is discouraged in Remotion:

tsx
const src = "abc";
// ---cut---
const myMarkup = (
  <div
    style={{
      backgroundImage: `url(${src})`,
    }}
  >
    <p>Hello World</p>
  </div>
);

Problem

Remotion has no way of knowing when the image is finished loading because it is impossible to determine so when loading an image through background-image, mask-image, or other CSS properties. This will lead to Remotion not waiting for the image to be loaded during rendering and cause visible flickers.

Solution

Use the `` tag instead and place it in an <AbsoluteFill>:

tsx
const src = "abc";
// ---cut---
import { AbsoluteFill, Img } from "remotion";

const myMarkup = (
  <AbsoluteFill>
    <AbsoluteFill>
      
    </AbsoluteFill>
    <AbsoluteFill>
      <p>Hello World</p>
    </AbsoluteFill>
  </AbsoluteFill>
);

The next will be placed on top of the image and will not flicker.

Workaround

If you cannot use an [](/docs/img) tag, for example because you need to use `mask-image()`, render an adjacent tag that renders the same src and place it outside the viewport:

tsx
const src = "abc";
// ---cut---
import { Img } from "remotion";

const myMarkup = (
  <>
    
    <div
      style={{
        maskImage: `url(${src})`,
      }}
    >
      <p>Hello World</p>
    </div>
  </>
);

The hidden `` tag ensures the image will download completely which allows the background-image will fully render.

See also