Skip to content

Commit 5c4c275

Browse files
committed
feat: Combinator.ouput support maxTime
1 parent c563646 commit 5c4c275

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

.changeset/yummy-snakes-notice.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@webav/av-cliper': patch
3+
---
4+
5+
feat: Combinator.ouput support maxTime

packages/av-cliper/src/combinator.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { Log, EventTool, file2stream, recodemux } from '@webav/internal-utils';
2-
import { OffscreenSprite } from './sprite/offscreen-sprite';
1+
import { EventTool, file2stream, Log, recodemux } from '@webav/internal-utils';
32
import { sleep } from './av-utils';
43
import { DEFAULT_AUDIO_CONF } from './clips';
4+
import { OffscreenSprite } from './sprite/offscreen-sprite';
55

66
export interface ICombinatorOpts {
77
width?: number;
@@ -207,18 +207,20 @@ export class Combinator {
207207

208208
/**
209209
* 输出视频文件二进制流
210+
* @param opts.maxTime 允许输出视频的最大时长,超过时长的素材内容会被忽略
210211
*/
211-
output(): ReadableStream<Uint8Array> {
212+
output(opts: { maxTime?: number } = {}): ReadableStream<Uint8Array> {
212213
if (this.#sprites.length === 0) throw Error('No sprite added');
213214

214215
const mainSpr = this.#sprites.find((it) => it.main);
215216
// 最大时间,优先取 main sprite,不存在则取最大值
216217
const maxTime =
217-
mainSpr != null
218+
opts.maxTime ??
219+
(mainSpr != null
218220
? mainSpr.time.offset + mainSpr.time.duration
219221
: Math.max(
220222
...this.#sprites.map((it) => it.time.offset + it.time.duration),
221-
);
223+
));
222224
if (maxTime === Infinity) {
223225
throw Error(
224226
'Unable to determine the end time, please specify a main sprite, or limit the duration of ImgClip, AudioCli',

0 commit comments

Comments
 (0)