Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: conversion speedup, animation size limit warn added #68

Merged
merged 1 commit into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/swift-mugs-impress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@releaseband/vite-plugin-meta": patch
---

conversion speedup, animation size limit warn added
7 changes: 6 additions & 1 deletion src/MetaPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import path from 'node:path';
import { stat } from 'node:fs/promises';
import {
checkDir,
convertImage,
Expand All @@ -14,7 +15,7 @@ import {
writeConfig,
convertVideo,
} from './processes';
import { Ext, MetaPluginOption, Names, VideoCodecs } from './types';
import { Ext, MAX_ANIMATION_SIZE, MetaPluginOption, Names, VideoCodecs } from './types';
import { createSoundsConfig, createTexturesConfig, createVideoConfig, getBasePath, replaceRoot } from './helpers';
import { fileLog } from './utils';

Expand Down Expand Up @@ -161,6 +162,10 @@ export default class MetaPlugin {
try {
const { nb_frames } = await getFileInfo(animationPath);
const fileHash = await makeHash(animationPath);
const stats = await stat(animationPath);
if (stats.size > MAX_ANIMATION_SIZE) {
console.warn(`animation ${animationPath} exceeds size limit ${stats.size} > ${MAX_ANIMATION_SIZE}`);
}
if (this.option.convertLog) console.log(animationPath, this.filesHash[animationPath], fileHash);
if (this.filesHash[animationPath] === fileHash) return;
if (this.option.fileChangeLog) fileLog(`file conversion "${animationPath}" started`);
Expand Down
4 changes: 2 additions & 2 deletions src/processes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ export async function convertAnimation(animationPath: string, storageDir: string
try {
await Promise.all([
copyFile(animationPath, newPath),
ffmpeg('-i', animationPath, '-y', '-loop', '0', newPath.replace(ext, Ext.webp)),
ffmpeg('-i', animationPath, '-y', '-c:v', 'libaom-av1', newPath.replace(ext, Ext.avif)),
ffmpeg('-i', animationPath, '-y', '-loop', '0', '-cpu-used 8', newPath.replace(ext, Ext.webp)),
mikhailgilev marked this conversation as resolved.
Show resolved Hide resolved
ffmpeg('-i', animationPath, '-y', '-c:v', 'libaom-av1', '-cpu-used 8', newPath.replace(ext, Ext.avif)),
]);
} catch (err) {
throw new Error(`${convertAnimation.name} ${animationPath} file error:\n${String(err)}`);
Expand Down
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export const MAX_ANIMATION_SIZE = 10_000_000;

export const enum Names {
metaConfigName = 'meta.json',
hashConfigName = 'files-hash.json',
Expand Down