Skip to content

Commit ebe69a1

Browse files
committed
verified transcripts can be copied
1 parent 4cddaac commit ebe69a1

File tree

5 files changed

+54
-3
lines changed

5 files changed

+54
-3
lines changed

src/clips/audio/audio.spec.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
*/
77

88
import { describe, expect, it, vi, beforeEach, afterEach } from 'vitest';
9+
import { captions } from '../../test/captions';
910
import { Composition } from '../../composition';
1011
import { AudioClip } from './audio';
11-
import { Timestamp } from '../../models';
12+
import { Timestamp, Transcript } from '../../models';
1213
import { AudioSource } from '../../sources';
1314

1415
import type { MockInstance } from 'vitest';
@@ -197,6 +198,7 @@ describe('Copying the AudioClip', () => {
197198
clip.duration.frames = 100;
198199
clip.muted = true;
199200
clip.volume = 0.2;
201+
clip.transcript = Transcript.fromJSON(captions);
200202

201203
const copy = clip.copy();
202204

@@ -208,6 +210,7 @@ describe('Copying the AudioClip', () => {
208210
expect(copy.muted).toBe(true);
209211
expect(copy.source).toBeInstanceOf(AudioSource);
210212
expect(copy.source.id).toBe(clip.source.id);
213+
expect(copy.transcript?.id).toBe(clip.transcript.id);
211214
});
212215

213216
it('should transfer base properties', () => {

src/clips/audio/audio.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ export class AudioClip extends MediaClip<AudioClipProps> {
8686

8787
public copy(): AudioClip {
8888
const clip = AudioClip.fromJSON(JSON.parse(JSON.stringify(this)));
89+
clip.transcript = this.transcript;
8990
clip.source = this.source;
9091

9192
return clip;

src/clips/media/media.spec.ts

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ describe('The Media Clip', () => {
285285
expect(copy.range[0].frames).toBe(10);
286286
expect(copy.range[1]).toBeInstanceOf(Timestamp);
287287
expect(copy.range[1].frames).toBe(80);
288+
expect(copy.transcript?.id).toBe(clip.transcript.id);
288289
});
289290

290291
it('should generate a caption track using a transcript', async () => {
@@ -295,7 +296,7 @@ describe('The Media Clip', () => {
295296
const composition = new Composition();
296297
await composition.add(clip);
297298

298-
const track = await clip.generateCaptions();
299+
const track = await clip.addCaptions();
299300

300301
expect(composition.tracks.length).toBe(2);
301302

@@ -420,6 +421,48 @@ describe('Split tests - the Media Clip object', () => {
420421
await expect(() => clip.split()).rejects.toThrowError();
421422
});
422423

424+
it('should split the clip in place when the track is set to stacked', async () => {
425+
const clip1 = new MediaClip({
426+
offset: new Timestamp(1000),
427+
name: 'foo',
428+
});
429+
430+
const clip2 = new MediaClip({
431+
offset: new Timestamp(500),
432+
name: 'bar',
433+
});
434+
435+
clip1.duration.millis = 3000;
436+
clip2.duration.millis = 2000;
437+
438+
const track = new MediaTrack().stacked();
439+
440+
await track.add(clip1);
441+
await track.add(clip2);
442+
443+
expect(track.clips.length).toBe(2);
444+
445+
expect(track.clips[0].name).toBe('foo');
446+
expect(track.clips[0].start.millis).toBe(0);
447+
expect(track.clips[0].stop.millis).toBe(3000);
448+
449+
expect(track.clips[1].name).toBe('bar');
450+
expect(track.clips[1].start.millis).toBe(3001);
451+
expect(track.clips[1].stop.millis).toBe(5001);
452+
453+
await clip1.split(new Timestamp(2000));
454+
455+
expect(track.clips.length).toBe(3);
456+
expect(track.clips[0].start.millis).toBe(0);
457+
expect(track.clips[0].stop.millis).toBe(2000);
458+
459+
expect(track.clips[1].start.millis).toBe(2001);
460+
expect(track.clips[1].stop.millis).toBe(3000);
461+
462+
expect(track.clips[2].start.millis).toBe(3001);
463+
expect(track.clips[2].stop.millis).toBe(5001);
464+
});
465+
423466
it('should not split the clip when no track is provided', async () => {
424467
const clip = new MediaClip({
425468
offset: new Timestamp(1000),

src/clips/video/video.spec.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ import { BlurFilter } from 'pixi.js';
1010
import { Source, VideoSource } from '../../sources';
1111
import { VideoClip } from './video';
1212
import { Composition } from '../../composition';
13-
import { Keyframe, Timestamp } from '../../models';
13+
import { Keyframe, Timestamp, Transcript } from '../../models';
1414
import { sleep } from '../../utils';
1515
import { FrameBuffer } from './buffer';
1616

1717
import type { MockInstance } from 'vitest';
18+
import { captions } from '../../test/captions';
1819

1920

2021
const file = new File([], 'video.mp4', { type: 'video/mp4' });
@@ -346,6 +347,7 @@ describe('Copying the VidoClip', () => {
346347
clip.duration.frames = 100;
347348
clip.muted = true;
348349
clip.volume = 0.2;
350+
clip.transcript = Transcript.fromJSON(captions);
349351

350352
const copy = clip.copy();
351353

@@ -358,6 +360,7 @@ describe('Copying the VidoClip', () => {
358360
expect(copy.muted).toBe(true);
359361
expect(copy.source).toBeInstanceOf(VideoSource);
360362
expect(copy.source.id).toBe(clip.source.id);
363+
expect(copy.transcript?.id).toBe(clip.transcript.id);
361364
});
362365

363366
it('should transfer visual properties', async () => {

src/clips/video/video.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ export class VideoClip extends VisualMixin(MediaClip<VideoClipProps>) {
142142
const clip = VideoClip.fromJSON(JSON.parse(JSON.stringify(this)));
143143
clip.filters = this.filters;
144144
clip.source = this.source;
145+
clip.transcript = this.transcript;
145146

146147
return clip;
147148
}

0 commit comments

Comments
 (0)