import { makeIDGen } from "./util";
import { $ } from "zx";
const producerIndexGen = makeIDGen(0);
export abstract class Producer {
index: number;
constructor(public path: string) {
this.index = producerIndexGen.next().value;
}
async getNativeMltXml(fps: number) {
const xml = (
await $`melt ${
this.path
} -consumer xml ${`frame_rate_num=${fps}`} | htmlq producer`
).stdout;
return xml.replace("producer0", `producer${this.index}`);
}
async toXML(fps: number) {
return await this.getNativeMltXml(fps);
}
}
export class ConcreteProducer extends Producer {
video_only: VideoOnlyProducer;
audio_only: AudioOnlyProducer;
constructor(path: string) {
super(path);
this.video_only = new VideoOnlyProducer(path);
this.audio_only = new AudioOnlyProducer(path);
}
async toXML(fps: number) {
return (
await Promise.all([
super.toXML(fps),
this.video_only.toXML(fps),
this.audio_only.toXML(fps),
])
).join("\n");
}
}
class VideoOnlyProducer extends Producer {
async toXML(fps: number) {
const xml = await super.toXML(fps);
return xml.replace(
"",
` 0
1
`
);
}
}
class AudioOnlyProducer extends Producer {
async toXML(fps: number) {
const xml = await super.toXML(fps);
return xml.replace(
"",
` 1
0
`
);
}
}
export class BlackTrack extends Producer {
constructor() {
super("");
}
async toXML() {
return /* HTML */ `
2147483647
continue
black
1
color
rgb24a
0
`;
}
}