# 동영상 편집기 — 개발자용 라이브러리

WebCodecs 기반 브라우저 동영상 편집: 자르기, MP4·WebM·MKV 변환, GIF 만들기, 소리 추출, 속도·크기·회전 변경, 필터, 자막. 파일은 컴퓨터를 떠나지 않으며 코덱을 다운로드하지 않습니다.

## 설치

```sh
npm install @openlibsdev/video-editor
```

```js
import VideoEditor from "https://cdn.jsdelivr.net/npm/@openlibsdev/video-editor@1.0.0/+esm";
```

## 사용법

```js
import VideoEditor from "@openlibsdev/video-editor";

const file = document.querySelector("input[type=file]").files[0];
const engine = VideoEditor.createEngine();
const info = await engine.probe(file);      // { duration, width, height, hasAudio, ... }
const job = VideoEditor.normalize({ op: "trim", start: 1, end: 3 }, info.duration);
const result = await engine.run(file, job, {
  hasAudio: info.hasAudio,
  onProgress: p => console.log(Math.round(p * 100) + "%")
});
console.log(result.name, result.blob.size);   // a new file, e.g. clip_trim.mp4
```

## API

### `VideoEditor.createEngine()`

처리 엔진을 만듭니다. 메서드는 아래를 참고하세요.

### `VideoEditor.normalize(job, duration)`

작업을 검사하고 기본값을 채웁니다: {op, start, end, format, speed, …}. 시간은 동영상 길이로 제한됩니다.

### `VideoEditor.buildJob(job, info)`

작업을 계획으로 바꿉니다: 무엇을 디코딩·변경·인코딩하는지, 결과의 이름과 유형.

### `VideoEditor.OPS`

작업: trim, convert, gif, audio, speed, resize, rotate, filter, text.

### `VideoEditor.DEFAULTS`

작업 필드 전체의 기본값.

### `VideoEditor.FORMATS`

출력 동영상 컨테이너.

### `VideoEditor.AUDIO_FORMATS`

출력 소리 형식.

### `VideoEditor.FILTERS`

이미지 필터: 회색조, 세피아, 밝게, 대비, 반전, 흐림, 선명하게, 비네트.

### `VideoEditor.VIDEO_CODECS`

컨테이너별로 우선순위에 따라 시도하는 동영상 코덱.

### `VideoEditor.AUDIO_CODECS`

컨테이너별로 우선순위에 따라 시도하는 오디오 코덱.

### `VideoEditor.applyFilter(img, name)`

ImageData 프레임에 필터를 적용합니다.

### `VideoEditor.stretchAudio(channels, sampleRate, speed)`

음높이를 바꾸지 않고 소리의 속도를 바꿉니다(WSOLA).

### `VideoEditor.timecode(sec)`

초 → “h:mm:ss.s”.

### `VideoEditor.parseTimecode(text)`

“1:02.5” 또는 “62.5” → 초.

### `VideoEditor.captionFamilies()`

자막에 쓸 수 있는 글꼴 패밀리.

### `VideoEditor.sizeText(bytes, units)`

파일 크기를 텍스트로(“12.4 MB”).

### `VideoEditor.APP`

라이브러리의 이름, 버전, 출시일: {name, version, created}.

### `VideoEditor.GIF_FPS`

GIF에 제공하는 프레임 속도.

### `VideoEditor.GIF_WIDTHS`

GIF에 제공하는 너비(픽셀).

### `VideoEditor.HEIGHTS`

크기 조정에 제공하는 프레임 높이(픽셀, 동영상은 확대하지 않음).

### `VideoEditor.MIME`

출력 확장자별 MIME 유형.

### `VideoEditor.ROTATIONS`

회전과 뒤집기: cw, ccw, 180, hflip, vflip.

### `VideoEditor.TEXT_POSITIONS`

자막 위치: 위, 가운데, 아래.

### `VideoEditor.baseName(name)`

확장자를 뺀 파일 이름. 파일 이름에 쓸 수 없는 문자는 바뀝니다.

### `VideoEditor.captionTextFontData`

자막의 텍스트와 글꼴 블록 데이터(font-forge의 것으로, 자막에 쓸 수 있는 글꼴로 한정).

### `VideoEditor.extOf(name)`

파일 이름의 확장자(소문자, 없으면 "mp4").

### `VideoEditor.findNamedColor(text, lang)`

지정한 언어의 색 이름으로 이름 있는 색을 찾습니다(“진한 파랑” → #00008b).

### `VideoEditor.fontFor(family, bold, italic)`

패밀리와 스타일에 해당하는 브라우저 글꼴 이름(먼저 불러옴).

### `VideoEditor.listNamedColors(lang)`

이름 있는 색을 지정한 언어의 이름과 함께 나열합니다.

### `VideoEditor.namedColorTexts(lang)`

지정한 언어의 색상 필드 라벨(색 선택기의 텍스트). 해당 언어가 없으면 영어.

### `VideoEditor.textFontData`

텍스트와 글꼴 블록의 데이터: 글꼴 목록, 스타일 불러오기, 글꼴 파일 추가, 언어별 블록 라벨, 기본값.

### `engine.probe(file, opts)`

파일을 읽습니다: 길이, 크기, 코덱, 소리와 영상 유무.

### `engine.run(file, job, opts)`

작업에 따라 파일을 처리하고 {blob, name, mime, ext, plan, codecs}를 반환합니다. 옵션: hasAudio, frameHeight, onProgress, onLog, signal.

### `engine.load()`

엔진을 미리 준비합니다(그렇지 않으면 첫 호출이 합니다).

### `engine.terminate()`

진행 중인 작업을 멈춥니다.

### `engine.loaded`

엔진이 준비되었는지 여부.

## 의존성

- @breezystack/lamejs 1.2.7 (LGPL-3.0)
- @imagemagick/magick-wasm 0.0.35 (Apache-2.0)
- @imagemagick/magick-wasm 0.0.35 (Apache-2.0)
- @simonwep/pickr 1.10.2 (MIT)
- @simonwep/pickr 1.10.2 (MIT)
- dejavu-fonts-ttf 2.37.3 (Bitstream Vera Fonts License (free, redistributable); DejaVu changes are public domain)
- gifenc 1.0.3 (MIT)
- imagetracerjs 1.2.6 (Unlicense)
- mediabunny 1.66.0 (MPL-2.0)

- GitHub: https://github.com/OpenLibsDev/video-editor
- npm: https://www.npmjs.com/package/@openlibsdev/video-editor
- 앱 열기: https://openlibs.dev/ko/app/video-editor/
