Entries and playlists

This commit is contained in:
Kuba Orlik 2021-10-25 21:26:23 +02:00
parent 13cd51fa28
commit 84cd5014dc
5 changed files with 94 additions and 5 deletions

17
src/entry.ts Normal file
View File

@ -0,0 +1,17 @@
import { Producer } from "./producer";
export class Entry {
constructor(
public producer: Producer,
public in_point: string,
public out_point: string
) {}
toXML(): string {
return /* HTML */ `<entry
producer="${this.producer.id}"
in="${this.in_point}"
out="${this.out_point}"
></entry>`;
}
}

View File

@ -1,4 +1,5 @@
import { $ } from "zx";
import { Entry } from "./entry";
import Project from "./kdenlive";
describe("Kdenlive", () => {
@ -58,4 +59,48 @@ describe("Kdenlive", () => {
await $`echo ${await project.toXML()} > 20a20v-tracks.kdenlive`;
});
});
describe("clips", () => {
it("should generate a 1a1v project with one clip", async () => {
const project = new Project(30);
const producer = project.addProducer("/home/kuba/Videos/5min.mp4");
const video_track = project.addVideoTractor();
const audio_track = project.addAudioTractor();
const entry = new Entry(producer, "00:00:00.000", "00:00:01.000");
video_track.addEntry(entry);
audio_track.addEntry(entry);
await $`echo ${await project.toXML()} > 1s-clip.kdenlive`;
});
it("should generate a 1a1v project with two contingent clips", async () => {
const project = new Project(30);
const producer = project.addProducer("/home/kuba/Videos/5min.mp4");
const video_track = project.addVideoTractor();
const audio_track = project.addAudioTractor();
const entry = new Entry(producer, "00:00:00.000", "00:00:01.000");
video_track.addEntry(entry);
audio_track.addEntry(entry);
const entry2 = new Entry(producer, "00:00:01.000", "00:00:02.000");
video_track.addEntry(entry2);
audio_track.addEntry(entry2);
await $`echo ${await project.toXML()} > 2x1s-clip.kdenlive`;
});
it("should generate a 1a1v project with 20 contingent clips", async () => {
const project = new Project(30);
const producer = project.addProducer("/home/kuba/Videos/5min.mp4");
const video_track = project.addVideoTractor();
const audio_track = project.addAudioTractor();
for (let i = 0; i <= 20; i++) {
let entry = new Entry(
producer,
`00:00:${i.toString().padStart(2, "0")}.000`,
`00:00:${(i + 1).toString().padStart(2, "0")}.000`
);
video_track.addEntry(entry);
audio_track.addEntry(entry);
}
await $`echo ${await project.toXML()} > 20x1s-clip.kdenlive`;
});
});
});

View File

@ -1,23 +1,36 @@
import { Entry } from "./entry";
import { makeIDGen } from "./util";
const playlistIndexGen = makeIDGen(0);
export abstract class Playlist {
public entries: Entry[] = [];
constructor(public index = playlistIndexGen.next().value) {}
abstract toXML(): string;
addEntry(entry: Entry) {
this.entries.push(entry);
}
renderEntries() {
return this.entries.map((e) => e.toXML()).join("\n");
}
}
export class AudioPlaylist extends Playlist {
toXML() {
return /* HTML */ ` <playlist id="playlist${this.index}">
return /* HTML */ `<playlist id="playlist${this.index}">
<property name="kdenlive:audio_track">1</property>
${this.renderEntries()}
</playlist>`;
}
}
export class VideoPlaylist extends Playlist {
toXML() {
return /* HTML */ ` <playlist id="playlist${this.index}"></playlist>`;
return /* HTML */ ` <playlist id="playlist${this.index}">
${this.renderEntries()}
</playlist>`;
}
}

View File

@ -9,18 +9,22 @@ export abstract class Producer {
this.index = producerIndexGen.next().value;
}
async getNativeMltXml(fps: number) {
async getNativeMltXml(fps: number): Promise<string> {
const xml = (
await $`melt ${
this.path
} -consumer xml ${`frame_rate_num=${fps}`} | htmlq producer`
).stdout;
return xml.replace("producer0", `producer${this.index}`);
return xml.replace("producer0", this.id);
}
async toXML(fps: number) {
async toXML(fps: number): Promise<string> {
return await this.getNativeMltXml(fps);
}
get id() {
return "producer" + this.index;
}
}
export class ConcreteProducer extends Producer {
@ -87,4 +91,8 @@ export class BlackTrack extends Producer {
<property name="set.test_audio">0</property>
</producer>`;
}
get id() {
return "black_track";
}
}

View File

@ -1,3 +1,4 @@
import { Entry } from "./entry";
import { AudioPlaylist, Playlist, VideoPlaylist } from "./playlist";
import { makeIDGen } from "./util";
@ -9,6 +10,11 @@ export abstract class Tractor {
public index = trackIndexGen.next().value;
abstract toXML(): string;
addEntry(entry: Entry): this {
this.main_playlist.addEntry(entry);
return this;
}
}
export class AudioTractor extends Tractor {