# ffcate

> FFCate is a lightweight and flexible short video production library

Latest version **1.0.3** (published 2021-02-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install ffcate
pnpm add ffcate
yarn add ffcate
bun add ffcate
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2021-02-01 |
| First published | 2021-02-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 50.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | ajiemath |
| Keywords | video, nodejs, video_production |

## Links

- npm: https://www.npmjs.com/package/ffcate
- Repository: https://github.com/tnfe/FFCate
- Homepage: https://tnfe.github.io/FFCate
- Issues: https://github.com/tnfe/FFCate/issues
- npm.io page: https://npm.io/package/ffcate

## Dependencies (4)

- [lodash](https://npm.io/package/lodash.md) ^4.17.20
- [is-base64](https://npm.io/package/is-base64.md) ^1.1.0
- [eventemitter3](https://npm.io/package/eventemitter3.md) ^4.0.7
- [fontfaceobserver](https://npm.io/package/fontfaceobserver.md) ^2.1.0

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 1.0.3 (latest) — 2021-02-01
- 1.0.2 — 2021-02-01
- 1.0.1 — 2021-02-01

## README

<p align="center">
  <img src="https://git.code.oa.com/yajieliu/FFCate/raw/1e2cbf106149363ce5b1523c5137c3a8df92179d/examples/assets/imgs/logo/FFCate.png
" />
</p>

<div align="center">
<a href="https://www.npmjs.com/ffcate" target="_blank"><img src="https://img.shields.io/npm/v/ffcate.svg" alt="NPM Version" /></a>
<a href="https://www.npmjs.com/ffcate" target="_blank"><img src="https://img.shields.io/npm/l/ffcate.svg" alt="Package License" /></a>
<a href="https://travis-ci.org/github/tnfe/FFCate" target="_blank"><img src="https://travis-ci.org/tnfe/FFCate.svg?branch=master" alt="Travis CI" /></a>
<a href="https://github.com/prettier/prettier" target="_blank"><img src="https://img.shields.io/badge/code_style-prettier-ff69b4.svg" alt="Code Style"></a>
<a href="https://github.com/tnfe/FFCate/pulls" target="_blank"><img src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg" alt="PRs"/></a>
<a href="https://nodejs.org" target="_blank"><img src="https://img.shields.io/badge/node-%3E%3D%208.0.0-brightgreen.svg" alt="Node Version" /></a>
</div>

## Overview

`FFCate`是一个基于<a href="http://nodejs.org" target="_blank">FFCreatorLite</a>和 WebAssembly 的在线音视频合成工具。您可以在 web 端使用图片和音乐快速合成想要的视频短片。

`FFCate`兼容大多数的现代浏览器，并且在移动端浏览器下也可以正常运行。目前它支持图片、声音、文字、视频等几种元素，并且可以设置多种动画，`FFCate`支持`animate.css`70%的动画效果，您可以快速使用这些效果。

<img src="https://git.code.oa.com/yajieliu/FFCate/raw/515de1230331451cbf45fc935856ad865c54f172/examples/assets/imgs/logo/wasm.png" />

`FFCate`是`node.js`短视频合成库`FFCreatorLite`(FFCreator 的 Lite 版本)的一个 WebAssembly 实践。目前它尚处于实验阶段并有待继续完善，欢迎您来和我一起共建。

#### 关于`FFCreatorLite`的介绍请查看[这里](https://tnfe.github.io/FFCreator/#/guide/lite)

## 使用

#### 安装 npm package

```javascript
npm install ffcate --save
```

Note: To run the preceding commands, Node.js and npm must be installed.

#### 在你的项目中引用

```javascript
import {FFScene, FFImage, FFText, FFCate} from 'ffcate';

// create cate instance
const cate = new FFCate({
  width: 600,
  height: 400,
  log: true,
  wasm: './wasm/ffmpeg-worker-mp4.js',
});

// create FFScene
const scene = new FFScene();
scene.setBgColor('#ff0000');

// create scene bg
const bg = new FFImage({path: 'xxx.jpg'});
scene.addChild(bg);

// create ffimage
const img = new FFImage({path: 'xxx.png', x: 300, y: 60});
img.addEffect('moveInRight', 1.5, 1.2);
scene.addChild(img);

const text = new FFText({text: 'hello world 你好！', x: 220, y: 30, fontSize: 36});
text.setFont(font);
text.setColor('#ff00cc');
text.setBackgroundColor('#0022cc');
text.addEffect('fadeIn', 1, 1);
text.setBorder(3);
scene.addChild(text);

scene.setDuration(8);
cate.addChild(scene);
cate.start();

// add event listener
```

#### 添加事件侦听

```javascript
cate.on('start', () => {
  console.log(`[FFCate] start`);
});

cate.on('error', e => {
  console.log(`[FFCate] error:: \n ${e}`);
});

cate.on('progress', progress => {
  const loading = document.querySelector('.loading');
  console.log(`[FFCate] progress:: ${(progress * 100) >> 0}%`);
  loading.style.width = `${progress * 100}%`;
});

cate.on('complete', ({url}) => {
  const video = document.querySelector('#video');
  video.src = url;
  console.log(`[FFCate] complete`);
});
```

#### 设置 wasm 文件

```javascript
wasm: './wasm/ffmpeg-worker-mp4.js',
```

## 方案对比

限于浏览器的支持，纯前端合成视频并不是一项简单的工作。尽管`MediaRecorder`API 可以将 canvas 动画录制为视频，而且合成速度非常快、性能很高是一种不错的方案，但是目前阶段`MediaRecorder`还存在不少的问题。

首先除 chrome、firefox 其他浏览器并不支持`MediaRecorder`API，同时 chrome 下`MediaRecorder`仅能输出 webm 格式流。并且这个方案也不支持同时合并声音。所以该方案有待浏览器厂商的后续支持。

`FFCate`使用WebAssembly技术，体积很小并且合成速度也较快（视情况是否开启pthreads支持）。目前正处于实验阶段，后续会陆续支持更多的动画特性。

## 关于 FFCreatorLite

<img src="https://tnfe.github.io/FFCreator/_media/logo/logo2.png" />

`FFCate`是基于[`FFCreatorLite`](https://github.com/tnfe/FFCreatorLite)版开发的，具体的使用方法可以查看`FFCreatorLite`文档。这里要注意 Lite 版本和`FFCreator`的区别，[`FFCreator`](https://github.com/tnfe/FFCreator)具有更加灵活和丰富的动画支持，支持近百种炫酷的场景切换动画，同时支持字幕、虚拟主播等多种元素。限于一些技术限制，暂时还没有办法把`FFCreator`的功能移植到 WebAssembly 上，这方面的尝试正在探索中。

## 关于 ffmpeg.wasm

该项目已经默认给您提供了一个`ffmpeg.wasm`文件（./wasm 目录下）。因为 WebAssembly 使用`SharedArrayBuffer`来支持 Pthreads(https://emscripten.org/docs/porting/pthreads.html)，由于`SharedArrayBuffer`的浏览器兼容性并不好，所以默认的`ffmpeg-*.wasm`文件关闭了 Pthreads。这样也导致了视频合成速度比开启多线程慢了很多（对比[ffmpeg.wasm](https://github.com/ffmpegwasm/ffmpeg.wasm)版本）。

您可以根据自己的实际情况定制自己的`ffmpeg.wasm`文件，您可以使用[https://github.com/wood9/ffmpeg.js](https://github.com/wood9/ffmpeg.js)并修改`./Makefile`内相关参数来制作。这里推荐使用 docker 模式来制作 wasm，大概需要 10 几分钟左右。

## 贡献代码

非常欢迎您加入我们一起开发`FFCate`，如果想要贡献代码请先阅读[这里](./CONTRIBUTING.md)。

## License

[MIT](./LICENSE)

---
_Source: https://npm.io/package/ffcate · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
