Skip to content

Commit 6ee9466

Browse files
committed
fix: guess end timestamp, include resolution
1 parent f23daba commit 6ee9466

File tree

4 files changed

+58
-67
lines changed

4 files changed

+58
-67
lines changed

.github/workflows/build.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Build binaries & attach to new release
2+
3+
on:
4+
release:
5+
types: [created]
6+
7+
jobs:
8+
generate:
9+
name: Generate release-artifacts
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: read
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v5
16+
- name: Set up Bun
17+
uses: oven-sh/setup-bun@v2
18+
with:
19+
bun-version: latest
20+
- name: Install dependencies
21+
run: bun install
22+
- name: Build
23+
run: bun run build:all
24+
- name: Upload artifacts
25+
uses: AButler/upload-release-assets@v3.0
26+
with:
27+
files: "dist/*"
28+
repo-token: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/release.yml

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,21 @@
1-
name: Build binaries & attach to new release
2-
1+
name: Publish release on version change
32
on:
4-
release:
5-
types: [created]
3+
push:
4+
branches:
5+
- main
66

77
jobs:
8-
generate:
9-
name: Generate release-artifacts
8+
build:
9+
name: Release
1010
runs-on: ubuntu-latest
11-
permissions:
12-
contents: read
1311
steps:
1412
- name: Checkout
15-
uses: actions/checkout@v5
16-
- name: Set up Bun
17-
uses: oven-sh/setup-bun@v2
18-
with:
19-
bun-version: latest
20-
- name: Install dependencies
21-
run: bun install
22-
- name: Build
23-
run: bun run build:all
24-
- name: Upload artifacts
25-
uses: AButler/upload-release-assets@v3.0
13+
uses: actions/checkout@v2
2614
with:
27-
files: "dist/*"
28-
repo-token: ${{ secrets.GITHUB_TOKEN }}
15+
fetch-depth: 0
16+
- name: Release
17+
uses: justincy/github-action-npm-release@v1.2.0
18+
id: release
19+
- name: Print release output
20+
if: ${{ steps.release.outputs.released == 'true' }}
21+
run: echo Release ID ${{ steps.release.outputs.release_id }}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "sub2fab",
33
"module": "index.ts",
4-
"version": "0.1.0",
4+
"version": "0.1.1",
55
"scripts": {
66
"build": "bun build --compile --minify --sourcemap ./src/cli.ts",
77
"build:win:x64": "bun run build --target=bun-windows-x64 --outfile dist/sub2fab-win-x64.exe",

src/process.ts

Lines changed: 15 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -193,58 +193,28 @@ export const processIdx = async (
193193
await $`${paths.ffmpeg} -f lavfi -i color=size=${size}:duration=59.07:rate=${fps}:color=black@0.0,format=rgba -i ${filename}.rw.idx -filter_complex "[0:v][1:s]overlay[v]" -map "[v]" -f image2 -frame_pts true -c:s png -vsync 0 -frames:v ${idx.paragraphs.length + 1} ${path.join(dir, "fabscript", "IMAGE%03d.png")} -y`.quiet();
194194
await $`rm ${filename}.rw.idx ${filename}.rw.sub ${path.join(dir, "fabscript", "IMAGE000.png")}`;
195195

196+
const [width, height] = size.split("x");
196197
const out = path.join(dir, "fabscript", "Fab_Image_script.txt");
197198
await Bun.write(
198199
out,
199200
idx.paragraphs
200-
.map(
201-
// WARNING: using the uncropped subtitles is experimental, not sure how it performs yet
202-
(paragraph, i) =>
203-
`IMAGE${(i + 1).toString().padStart(3, "0")}.png ${secToTimestamp(paragraph.startTime / 1000, ";")} 0 0 0 0`,
204-
)
201+
.map((paragraph, i) => {
202+
// I don't know how to correctly determine subtitle duration
203+
// currently, so we're making a guess and avoiding overlaps.
204+
const nextStartTime = idx.paragraphs[i + 1]?.startTime;
205+
const maxDuration = 6000;
206+
let nextTs = secToTimestamp(
207+
(nextStartTime !== undefined
208+
? Math.min(paragraph.startTime + maxDuration, nextStartTime - 500)
209+
: paragraph.startTime + maxDuration) / 1000,
210+
";",
211+
);
212+
213+
return `IMAGE${(i + 1).toString().padStart(3, "0")}.png ${secToTimestamp(paragraph.startTime / 1000, ";")} ${nextTs} 0 0 ${width} ${height}`;
214+
})
205215
.join("\n"),
206216
);
207217

208-
// const glob = new Bun.Glob(`${filename}.frame*.png`);
209-
// for await (const file of glob.scan()) {
210-
// // TODO: crop each image - https://stackoverflow.com/a/62378527
211-
// await $`${paths.ffmpeg} -loop 1 -i ${}`
212-
// }
213-
214-
// Extract single image from PES
215-
// const file = await Bun.file("test/charliesub.sub").bytes();
216-
// const buffers: Buffer[] = [];
217-
218-
// let i = -1;
219-
// for (const para of idx.paragraphs) {
220-
// i += 1;
221-
// const start = para.filePosition;
222-
223-
// const nextPos = idx.paragraphs[i + 1]?.filePosition;
224-
// const end = nextPos === undefined ? file.length : nextPos;
225-
// const packet = file.slice(start, end);
226-
// console.log({ len: packet.length, start, end });
227-
228-
// // According to https://dvd.sourceforge.net/dvdinfo/pes-hdr.html,
229-
// // the stream with ID 0xBD (189) contains the subpictures, but in my
230-
// // testing with SubtitleEdit-generated .sub files, the only stream IDs I
231-
// // encountered were ID 0xBA (186).
232-
// const streamId = packet[3];
233-
// // if (streamId === 0xba) {
234-
// // console.log("subpicture stream");
235-
// // }
236-
// // I think this is right?
237-
// const packetLength = Number(`${packet[4] ?? ""}${packet[5] ?? ""}`);
238-
// const headerLength = packet[8];
239-
// console.log({ streamId, packetLength, headerLength });
240-
241-
// const firstByte = 5 + (headerLength ?? 0);
242-
// const rest = packet.slice(firstByte, packetLength);
243-
// if (i === 0) {
244-
// await Bun.write(`test/${para.startTime}.bmp`, rest);
245-
// }
246-
// }
247-
248218
return out;
249219
};
250220

0 commit comments

Comments
 (0)