getGifDurationInSeconds()
Part of the @remotion/gif
package
Available from v3.2.22
Gets the duration in seconds of a GIF.
note
Remote GIFs need to support CORS.
More info
Remotion's origin is usually
http://localhost:3000
, but it may be different if rendering on Lambda or the port is busy.You can disable CORS during renders.
Arguments
src
A string pointing to a GIF asset
Return value
Promise<number>
- the duration of the GIF in seconds, not factoring in that whether it is looped.
Example
tsx
import {getGifDurationInSeconds } from "@remotion/gif";importgif from "./cat.gif";constMyComp :React .FC = () => {constgetDuration =useCallback (async () => {constimported = awaitgetGifDurationInSeconds (gif ); // 127.452constpublicFile = awaitgetGifDurationInSeconds (staticFile ("giphy.gif")); // 2.10constremote = awaitgetGifDurationInSeconds ("https://media.giphy.com/media/xT0GqH01ZyKwd3aT3G/giphy.gif"); // 3.23}, []);useEffect (() => {getDuration ();}, []);return null;};
tsx
import {getGifDurationInSeconds } from "@remotion/gif";importgif from "./cat.gif";constMyComp :React .FC = () => {constgetDuration =useCallback (async () => {constimported = awaitgetGifDurationInSeconds (gif ); // 127.452constpublicFile = awaitgetGifDurationInSeconds (staticFile ("giphy.gif")); // 2.10constremote = awaitgetGifDurationInSeconds ("https://media.giphy.com/media/xT0GqH01ZyKwd3aT3G/giphy.gif"); // 3.23}, []);useEffect (() => {getDuration ();}, []);return null;};