getGifDurationInSeconds()
Part of the @remotion/gif package
Gets the duration in seconds of a GIF.
note
Remote GIFs need to support CORS. Remotion's origin is usually You can disable CORS during renders.More info
http://localhost:3000, but it may be different if rendering on Lambda or the port is busy.
Arguments
src
A string pointing to a GIF asset
options?v4.0.460
requestInit?v4.0.460
Options that are passed to the internal fetch() call when loading the GIF. This can be used to pass credentials or headers for authenticated GIFs.
Remotion manages the internal signal option itself, so passing a signal in requestInit has no effect.
Return value
Promise<number> - the duration of the GIF in seconds, not factoring in that whether it is looped.
Example
import {getGifDurationInSeconds } from '@remotion/gif';
import gif from './cat.gif';
const MyComp : React .FC = () => {
const getDuration = useCallback (async () => {
const imported = await getGifDurationInSeconds (gif ); // 127.452
const publicFile = await getGifDurationInSeconds (staticFile ('giphy.gif')); // 2.10
const remote = await getGifDurationInSeconds ('https://media.giphy.com/media/xT0GqH01ZyKwd3aT3G/giphy.gif'); // 3.23
}, []);
useEffect (() => {
getDuration ();
}, []);
return null;
};