Skip to content

Commit 48d7dd3

Browse files
committed
fix(xml): attempting to fix xml issues
getting final xml to look more like original one produced by renderV1 limitations: * in/out tags are missing (I don't know what they do) * resolution is still missing if it is passed in as null from electron
1 parent 551f90f commit 48d7dd3

1 file changed

Lines changed: 62 additions & 31 deletions

File tree

src/XML/helpersXML.ts

Lines changed: 62 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,35 @@ export class xmlBuilder extends baseXMLBUilder {
55
private clipitemIDs: string[] = [];
66
private timeBase: number = -1;
77
private duration: string = "";
8-
public buildContext(name: string, frameRate: number, duration: number, l: () => void) {
8+
private registeredFile: boolean = false;
9+
private width: number | null = -1;
10+
private height: number | null = -1;
11+
public buildContext(name: string, width: number | null, height: number | null, frameRate: number, duration: number, l: () => void) {
12+
this.width = width;
13+
this.height = height;
914
this.timeBase = frameRate;
1015
this.duration = (frameRate * duration).toFixed(0);
11-
this._data.push("<?xml version=\"1.0\"?>");
1216
this.putTag("xmeml", {version: this.conf.version}, () => {
1317
this.putTag("project", {}, () => {
1418
this.putTag("name", {}, name);
1519
this.putTag("children", {}, () => {
1620
this.putTag("sequence", {id: this.conf.sequenceID}, () => {
1721
this.putTag("name", {}, name);
18-
this.putTag("duration", {}, this.duration);
22+
this.putTag("duration", {}, this.duration); // FIXME: Duration is only up to the end of the last cut
1923
this.putTag("rate", {}, () => {
2024
this.putTag("timebase", {}, this.timeBase.toString());
21-
this.putTag("ntsc", {}, this.putBool(this.conf.ntsc));
25+
this.putTag("ntsc", {}, this.putBool(this.conf.ntsc)); // FIXME: ???
2226
});
2327
this.putTag("media", {}, () => {
2428
this.putTag("video", {}, () => {
2529
this.putTag("track", {}, l);
30+
this.putTag("format", {}, () => {
31+
this.putTag("samplecharacteristics", {}, () => {
32+
this.height && this.putTag("height", {}, this.height.toString());
33+
this.width && this.putTag("width", {}, this.width.toString())
34+
this.putTag("pixelaspectratio", {}, this.conf.pixelAspectRatio);
35+
})
36+
});
2637
});
2738
this.putTag("audio", {}, () => {
2839
this.putTag("track", {}, () => {
@@ -33,51 +44,44 @@ export class xmlBuilder extends baseXMLBUilder {
3344

3445
});
3546
});
47+
this.putTag("timecode", {}, () => {
48+
this.putTag("rate", {}, () => {
49+
this.putTag("timebase", {}, this.timeBase.toString());
50+
this.putTag("ntsc", {}, this.putBool(this.conf.ntsc));
51+
});
52+
this.putTag("string", {}, this.conf.zeroTimecode); // why???
53+
this.putTag("frame", {}, this.conf.zeroFrame);
54+
this.putTag("displayformat", {}, this.conf.displayFormat);
55+
});
3656
});
3757
});
3858
});
3959
});
4060
}
4161

42-
public putClipitem(filePath: string, start: number, end: number, height: number, width: number) {
62+
public putClipitem(filePath: string, start: number, end: number) {
4363
const rate = () => {
4464
this.putTag("timebase", {}, this.timeBase.toString());
4565
this.putTag("ntsc", {}, this.putBool(this.conf.ntsc));
4666
};
47-
48-
49-
this.putTag("clipitem", {
50-
frameBlend: this.putBool(this.conf.frameBlend),
51-
id: this.genID(),
52-
}, () => {
67+
this.putTag("clipitem", {frameBlend: this.putBool(this.conf.frameBlend), id: this.genID(), }, () => {
5368
this.putTag("media", {}, () => {
5469
this.putTag("video", {}, () => {
5570
this.putTag("samplecharacteristics", {}, () => {
56-
this.putTag("height", {}, height.toString());
57-
this.putTag("width", {}, width.toString());
58-
});
59-
});
60-
});
61-
this.putTag("file", {id: this.conf.fileID}, () => {
62-
this.putTag("pathurl", {}, filePath);
63-
this.putTag("name", {}, path.basename(filePath));
64-
this.putTag("rate", {}, rate);
65-
this.putTag("duration", {}, this.duration);
66-
this.putTag("timecode", {}, () => {
67-
this.putTag("rate", {}, rate);
68-
this.putTag("string", {}, this.conf.zeroTimecode); // why???
69-
this.putTag("frame", {}, this.conf.zeroFrame);
70-
this.putTag("displayformat", {}, this.conf.displayFormat);
71-
this.putTag("media", {}, () => {
72-
this.putTag("video", {});
73-
this.putTag("audio", {});
71+
this.height && this.putTag("height", {}, this.height.toString());
72+
this.width && this.putTag("width", {}, this.width.toString())
7473
});
7574
});
7675
});
76+
this.putTag("file", {id: this.conf.fileID}, this.genFile(filePath, rate));
7777
this.putTag("name", {}, filePath);
7878
this.putTag("rate", {}, rate);
79-
this.putTag("start", {}, (start * this.timeBase).toFixed());
80-
this.putTag("end", {}, (end * this.timeBase).toFixed());
79+
this.putTag("rate", {}, rate); // XXX: no idea. Original did this and original works so ¯\_(ツ)_/¯
80+
const startF = start * this.timeBase;
81+
const endF = end * this.timeBase;
82+
this.putTag("duration", {}, (endF - startF).toFixed());
83+
this.putTag("start", {}, startF.toFixed());
84+
this.putTag("end", {}, endF.toFixed());
8185
});
8286
}
8387

@@ -91,6 +95,32 @@ export class xmlBuilder extends baseXMLBUilder {
9195
return id;
9296
}
9397

98+
private genFile(filePath: string, rate: () => void): (() => void) | undefined {
99+
/*
100+
XXX: this looks weird, but it is being passed to a function with an optional parameter,
101+
so it's expecting another function or undefined.
102+
*/
103+
if (!this.registeredFile) {
104+
this.registeredFile = true;
105+
return () => {
106+
this.putTag("pathurl", {}, filePath);
107+
this.putTag("name", {}, path.basename(filePath));
108+
this.putTag("rate", {}, rate);
109+
this.putTag("duration", {}, this.duration);
110+
this.putTag("timecode", {}, () => {
111+
this.putTag("rate", {}, rate);
112+
this.putTag("string", {}, this.conf.zeroTimecode); // why???
113+
this.putTag("frame", {}, this.conf.zeroFrame);
114+
this.putTag("displayformat", {}, this.conf.displayFormat);
115+
});
116+
this.putTag("media", {}, () => {
117+
this.putTag("video", {});
118+
this.putTag("audio", {});
119+
});
120+
};
121+
}
122+
}
123+
94124

95125
private conf = {
96126
version: "4",
@@ -101,6 +131,7 @@ export class xmlBuilder extends baseXMLBUilder {
101131
zeroTimecode: "00:00:00:00",
102132
zeroFrame: "0",
103133
displayFormat: "NDF",
134+
pixelAspectRatio: 1.0.toFixed(1)
104135
} as const;
105136

106137
}

0 commit comments

Comments
 (0)