Skip to main content

getGifDurationInSeconds()

属于 @remotion/gif

从 v3.2.22 版本开始可用

获取 GIF 的持续时间(秒)。

note

远程 GIF 需要支持 CORS

更多信息
  • Remotion 的源通常是 http://localhost:3000,但如果在 Lambda 上渲染或端口繁忙,则可能会有所不同。

  • 您可以在渲染期间 禁用 CORS

参数

src

指向 GIF 资源的字符串

返回值

Promise<number> - GIF 的持续时间(秒),不考虑是否循环播放。

示例

tsx
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;
};
tsx
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;
};

另请参阅