Skip to content

Commit fee7472

Browse files
authored
Credit the libraries the converter ships (2.4.1) (#80)
The footer credited WebCodecs, which is the browser's own API rather than anyone's project, while the libraries doing the work went unnamed. Attribution here is an obligation: @ffmpeg/core is GPL-2.0-or-later (it bundles x264) and mediabunny is MPL-2.0, and both require informing recipients and pointing at the corresponding source. CREDITS.md now covers every component, linked from the footer beside Privacy.
1 parent fcafa82 commit fee7472

7 files changed

Lines changed: 240 additions & 4 deletions

File tree

‎CREDITS.md‎

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Credits and licences
2+
3+
cdg2mp4 converts karaoke files in your browser. It does that with other people's
4+
work. This page lists what that work is, who wrote it, and the terms it comes
5+
under.
6+
7+
Two of the licences below carry obligations we have to meet, not just courtesy:
8+
the ffmpeg core is GPL, and mediabunny is MPL. Both are named as such, linked to
9+
their upstream source, and shipped unmodified. Where to get that source is in
10+
each entry.
11+
12+
## The conversion
13+
14+
Whichever converter runs on your device (see the footer, or the browser
15+
console), these are the parts doing the work.
16+
17+
### Native pipeline
18+
19+
| Component | Licence | What it does |
20+
| -------------------------------------------------------------------------- | ----------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
21+
| [cdgraphics](https://github.com/bhj/cdgraphics) | ISC | Renders CD+G graphics to a canvas. By [bhj](https://github.com/bhj), also the author of [Karaoke Eternal](https://www.karaoke-eternal.com/). |
22+
| [mediabunny](https://github.com/Vanilagy/mediabunny) | **MPL-2.0** | Muxes the MP4 and drives the WebCodecs encoders. By [Vanilagy](https://github.com/Vanilagy). |
23+
| [WebCodecs](https://developer.mozilla.org/en-US/docs/Web/API/VideoEncoder) | n/a | Your browser's own H.264 encoder. Part of the browser, not something we ship. |
24+
25+
mediabunny is covered by the [Mozilla Public License 2.0](https://www.mozilla.org/en-US/MPL/2.0/).
26+
We ship it unmodified. Its source is at
27+
[github.com/Vanilagy/mediabunny](https://github.com/Vanilagy/mediabunny) and on
28+
[npm](https://www.npmjs.com/package/mediabunny); the exact version we bundle is
29+
pinned in [package.json](package.json).
30+
31+
### Fallback pipeline
32+
33+
| Component | Licence | What it does |
34+
| ----------------------------------------------------------- | -------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
35+
| [ffmpeg.wasm](https://ffmpegwasm.netlify.app/) | MIT (`@ffmpeg/ffmpeg`, `@ffmpeg/util`) | The browser wrapper around the core. |
36+
| [`@ffmpeg/core`](https://github.com/ffmpegwasm/ffmpeg.wasm) | **GPL-2.0-or-later** | FFmpeg compiled to WebAssembly, including [x264](https://www.videolan.org/developers/x264.html), which is why the whole core is GPL rather than LGPL. |
37+
38+
The core we serve from `/ffmpeg/<version>/` is the unmodified published build of
39+
`@ffmpeg/core`, gzipped so it fits the host's file size limit and decompressed
40+
in your browser. It is covered by the
41+
[GNU General Public License v2 or later](https://www.gnu.org/licenses/old-licenses/gpl-2.0.html).
42+
Its corresponding source is at
43+
[github.com/ffmpegwasm/ffmpeg.wasm](https://github.com/ffmpegwasm/ffmpeg.wasm),
44+
which builds on [FFmpeg](https://ffmpeg.org/) and
45+
[x264](https://code.videolan.org/videolan/x264); the exact version is pinned in
46+
[package.json](package.json).
47+
48+
## Everything else
49+
50+
| Component | Licence | What it does |
51+
| ---------------------------------------------------- | ------------------------- | -------------------------------------------------------- |
52+
| [fflate](https://github.com/101arrowz/fflate) | MIT | Unzips the karaoke `.zip` in the browser. |
53+
| [React](https://react.dev/) | MIT | UI. |
54+
| [Vite](https://vite.dev/) | MIT | Build. |
55+
| [Tailwind CSS](https://tailwindcss.com/) | MIT | Styling. |
56+
| [vite-plugin-pwa](https://vite-pwa-org.netlify.app/) | MIT | Offline support and installability. |
57+
| [Radix UI](https://www.radix-ui.com/) | MIT | Accessible UI primitives. |
58+
| [PostHog](https://posthog.com/) | Apache-2.0 (`posthog-js`) | Anonymous usage analytics. See [PRIVACY.md](PRIVACY.md). |
59+
60+
Fonts: [Unbounded](https://fonts.google.com/specimen/Unbounded),
61+
[Saira Semi Condensed](https://fonts.google.com/specimen/Saira+Semi+Condensed),
62+
[Hanken Grotesk](https://fonts.google.com/specimen/Hanken+Grotesk) and
63+
[Geist Mono](https://vercel.com/font), all under the
64+
[SIL Open Font License](https://openfontlicense.org/), self-hosted via
65+
[Fontsource](https://fontsource.org/).
66+
67+
## The format
68+
69+
CD+G is a 1980s CD subcode format with no official public specification. The
70+
renderers everyone uses, including this one, descend from
71+
[Jim Bumgardner's CD+G Revealed](http://jbum.com/cdg_revealed.html), which
72+
reverse-engineered and documented it.
73+
74+
## This project
75+
76+
cdg2mp4 itself is by [Karaokio](https://karaokio.com). Source at
77+
[github.com/Karaokio/cdg2mp4](https://github.com/Karaokio/cdg2mp4).
78+
79+
If we have got an attribution wrong or missed one, please
80+
[open an issue](https://github.com/Karaokio/cdg2mp4/issues) and we will fix it.

‎README.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,13 @@ test/files/ self-generated, copyright-free sample.{cdg,mp3,zip} fixtures
133133
plus sample-key.cdg (transparent background, see the spec)
134134
```
135135

136+
## Credits and licences
137+
138+
[CREDITS.md](CREDITS.md) lists every component, who wrote it, and its licence.
139+
Two carry obligations rather than courtesy: `@ffmpeg/core` is **GPL-2.0-or-later**
140+
(it bundles x264) and `mediabunny` is **MPL-2.0**. Both ship unmodified, and both
141+
are named with a link to their source, in the file and from the app's footer.
142+
136143
## Watching a conversion
137144

138145
Open the browser console. Every conversion prints a short trace: which pipeline

‎docs/blog-webcodecs.md‎

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# I deleted ffmpeg from my karaoke converter and it got 11x faster
2+
3+
My CDG to MP4 converter has run on ffmpeg.wasm since I rebuilt it. That is the real FFmpeg, compiled to WebAssembly, downloaded into your browser, doing the transcode on your own machine so your files never touch a server. It works. It is also a 31MB download and, on a three minute song, close to three minutes of waiting.
4+
5+
Worse, for some people it never worked at all.
6+
7+
## The 16 sessions that never had a chance
8+
9+
When I put analytics on the tool, I found a stubborn group of failures. Out of 136 conversion sessions, 16 never succeeded. Not "failed once and retried", never succeeded.
10+
11+
They clustered. Every Chrome 109 session on Windows: zero successes, eight failures. Every Firefox 115 session: zero out of three. Those are the last browser versions you can run on Windows 7 and 8.1, which means old PCs.
12+
13+
The cause turned out to be one line in how `@ffmpeg/core` ships. It is built with SIMD, and browsers disable WebAssembly SIMD on CPUs without SSE4.1, an instruction set Intel added in 2007. So the core fails to compile before it ever reads the user's file. No retry helps. No other browser helps. The machine cannot run it.
14+
15+
I shipped an honest error message for that, which told those users the truth and gave them an ffmpeg command to run locally. It was better than a lie. It was still a dead end.
16+
17+
## The browser already has an encoder
18+
19+
I had been ignoring the obvious. Every modern browser already ships an H.264 encoder, sitting behind an API called WebCodecs, usually hardware accelerated. It has nothing to do with WebAssembly, so the SIMD problem does not apply, and there is nothing to download because it is part of the browser you already opened.
20+
21+
So the new pipeline has no ffmpeg in it at all:
22+
23+
- `cdgraphics`, a JavaScript CD+G renderer, draws each frame to a canvas
24+
- the canvas gets scaled up with nearest-neighbour, keeping the pixel art crisp
25+
- `VideoEncoder` encodes H.264 natively
26+
- `mediabunny` muxes it into an MP4
27+
28+
ffmpeg.wasm is still there as the fallback, for Firefox before 130, Safari before 16.4, and anything where the H.264 config gets rejected. The app checks and picks. Most people will never see the wasm path again.
29+
30+
## The numbers
31+
32+
Same song, same machine, same 1080p output. A 188 second track:
33+
34+
| | time | size |
35+
|---|---|---|
36+
| WebCodecs | 15.0s | 6.1 MB |
37+
| ffmpeg.wasm | 171.6s | 4.7 MB |
38+
39+
Eleven times faster, and that is on a fast laptop where ffmpeg.wasm behaves well. On a slower machine I saw the native path take 51 seconds, which is still a different category of experience from sitting through three minutes.
40+
41+
The file is about 30% bigger. I measured that carefully and decided to keep it, because the native output is slightly *higher* quality than the old one against a lossless reference. x264 has better rate control than the browser's encoder, and matching its file size means giving up more quality than it does. I would rather ship the better picture.
42+
43+
## The bug I only found because I was chasing file size
44+
45+
At first the gap was much worse: not 30% bigger, over three times bigger. I spent a while poking at bitrates and keyframe intervals and getting nowhere, which is usually the sign that you are measuring the wrong thing.
46+
47+
I finally decoded a single frame and counted the colours in it. The source frame has 5 colours. Flat pixel art, one background, some text. ffmpeg's output had 2,317, which is normal compression noise. Mine had **31,461**.
48+
49+
That is not a compression problem. That is a rendering problem.
50+
51+
CD+G lets a title declare its background colour transparent, and I was drawing each frame onto the canvas with `drawImage`, which composites by default. So nothing a transparent pixel covered ever got erased. Every lyric line was still sitting there under the next one, three minutes of accumulated text, and the encoder was faithfully spending bits on the smear.
52+
53+
The fix is one line: set the canvas to `copy` instead of blending. Average per-pixel error against a lossless render went from 38 (out of 255) to 0.61. File size dropped 24% as a side effect.
54+
55+
I only noticed because I was chasing bytes. Nobody had complained, and I had watched the output play back without seeing it. That is a good argument for measuring things you think are fine.
56+
57+
## Fidelity, because I did not want to guess
58+
59+
The whole plan rests on a JavaScript renderer matching ffmpeg's CD+G decoder. So I rendered a real karaoke rip both ways and compared them pixel by pixel: 97% of frames came out bit for bit identical, and every frame that differed was off by less than 0.1% of its pixels, always a fraction of one 6x12 tile where a lyric highlight landed on either side of a sampling boundary.
60+
61+
Getting there taught me something about ffmpeg I did not know. Its `fps` filter rounds to nearest, so `-r 30` samples the *middle* of each frame's display interval, not the start. My first attempt sampled the start and matched 27% of frames. One packet of correction took it to 97%.
62+
63+
## What you actually see
64+
65+
Nothing, ideally. Drop a zip, get a video, faster. The footer credits whichever engine is doing the work on your device. If you open the console, the converter now narrates itself:
66+
67+
```
68+
[cdg2mp4] pipeline: webcodecs · native H.264 encoder, nothing to download
69+
[cdg2mp4] converting TRKD1502.zip at 1080p (1440x1080)
70+
[cdg2mp4] 5646 frames at 30fps · 188.2s of audio, 187.0s of graphics
71+
[cdg2mp4] done in 51.3s · 5.3 MB, 3.6x realtime
72+
```
73+
74+
And if the new pipeline ever fails on your machine, the error screen offers you the old one. One click, same files. I did not want a settings toggle asking people to choose between "WebCodecs" and "ffmpeg", because that is not a question anyone should have to answer to convert a karaoke track. But I did not want to strand anyone either.
75+
76+
The 8 Chrome 109 sessions are the ones I am watching. Those machines have WebCodecs. They will fall back to a software H.264 encoder, which is native code and does not care about SSE4.1, so it should work. Should. I do not own a 2006 PC, so I will find out from the data.
77+
78+
Go convert something and sing badly. That is what it is for.
79+
80+
[ Try it at **cdg2mp4.com** ]
81+
82+
<!--
83+
EDITOR NOTES (delete before publishing):
84+
- Numbers: 15.0s / 171.6s / 6.1 MB / 4.7 MB are same-machine (M-series laptop, Chromium 149)
85+
on TRKD1502, a 188s rip. The 51.3s / 5.3 MB figures are a real run on a different, slower
86+
machine in branded Chrome, which is why they differ. Do not mix the two into one comparison.
87+
- The 136 sessions / 16 failures / Chrome 109 / Firefox 115 numbers are from the PostHog
88+
data behind issue #78. Refresh before publishing if the window has moved.
89+
- "over three times bigger" was 15.9 MB pre-fix at the 2s keyframe default. Left vague on
90+
purpose since the keyframe interval also changed in the same stretch of work.
91+
- Link targets to add: issue #78, the #77 SIMD post if that ever got written, MDN VideoEncoder,
92+
cdgraphics and mediabunny on npm.
93+
- Suggested tags: karaoke, webcodecs, ffmpeg, browsers, side projects, CDG.
94+
-->

‎docs/feedback-and-analytics.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ the ones who convert.
8585
retry might clear. `encoder_error` and `bad_audio` come from the native pipeline.
8686
- `conversion_cancelled` { input_type, resolution, pipeline, stage, progress_pct,
8787
duration_ms }
88+
- `credits_clicked` when someone opens CREDITS.md from the footer.
8889
- `pipeline_retry_used` { from, to, resolution } when a user takes the "Try the original
8990
converter" offer after a native failure. Watch this alongside `conversion_failed`: it is
9091
the count of people the native pipeline actually let down.

‎e2e/pipeline.spec.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,24 @@ test.describe("conversion pipelines", () => {
187187
await expect(page.locator("footer")).toContainText(/powered by ffmpeg/i);
188188
});
189189

190+
// Attribution is an obligation here, not decoration: the ffmpeg core is GPL
191+
// and mediabunny is MPL, and both require telling people so and pointing at
192+
// the source. The native path also ships two libraries by name, and crediting
193+
// only the browser API would leave their authors out.
194+
test("credits the libraries it ships and links the licences", async ({ page }) => {
195+
await page.goto("/");
196+
await expect(page.getByRole("link", { name: /^credits$/i })).toHaveAttribute(
197+
"href",
198+
/CREDITS\.md$/
199+
);
200+
201+
if (await nativeAvailable(page)) {
202+
const footer = page.locator("footer");
203+
await expect(footer.getByRole("link", { name: "cdgraphics" })).toBeVisible();
204+
await expect(footer.getByRole("link", { name: "mediabunny" })).toBeVisible();
205+
}
206+
});
207+
190208
test("does not offer a converter download the native pipeline never uses", async ({ page }) => {
191209
test.skip(!(await nativeAvailable(page)), "this browser does need the wasm core");
192210
await page.goto("/");

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "cdg2mp4",
33
"private": true,
4-
"version": "2.4.0",
4+
"version": "2.4.1",
55
"type": "module",
66
"description": "Karaokio CDG-to-MP4 converter — 100% in-browser, offline, powered by WebCodecs with an ffmpeg.wasm fallback.",
77
"scripts": {

‎src/App.tsx‎

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,18 @@ export default function App() {
5858
{/* Name whatever is actually converting on this device. Most visitors
5959
never touch ffmpeg now, and crediting it to them would be wrong;
6060
the ones still on it deserve to know why theirs is the slow path.
61-
Neutral until the probe resolves, so neither name flashes. */}
61+
Neutral until the probe resolves, so neither name flashes.
62+
63+
WebCodecs is the browser's own API, so on the native path the
64+
people to credit are the ones whose libraries we actually ship:
65+
cdgraphics renders the graphics, mediabunny muxes the MP4. Full
66+
list and licences in CREDITS.md, linked below. */}
6267
<p>
6368
Runs entirely in your browser · works offline
6469
{pipeline === "webcodecs" && (
6570
<>
66-
{" · powered by "}
71+
<br />
72+
{"powered by "}
6773
<a
6874
className="text-brand-label underline"
6975
href="https://developer.mozilla.org/en-US/docs/Web/API/VideoEncoder"
@@ -72,11 +78,30 @@ export default function App() {
7278
>
7379
WebCodecs
7480
</a>
81+
{", "}
82+
<a
83+
className="text-brand-label underline"
84+
href="https://github.com/bhj/cdgraphics"
85+
target="_blank"
86+
rel="noreferrer"
87+
>
88+
cdgraphics
89+
</a>
90+
{" and "}
91+
<a
92+
className="text-brand-label underline"
93+
href="https://github.com/Vanilagy/mediabunny"
94+
target="_blank"
95+
rel="noreferrer"
96+
>
97+
mediabunny
98+
</a>
7599
</>
76100
)}
77101
{pipeline === "ffmpeg" && (
78102
<>
79-
{" · powered by "}
103+
<br />
104+
{"powered by "}
80105
<a
81106
className="text-brand-label underline"
82107
href="https://ffmpegwasm.netlify.app/"
@@ -107,6 +132,17 @@ export default function App() {
107132
>
108133
Privacy
109134
</a>
135+
{/* Not decoration: the ffmpeg core is GPL and mediabunny is MPL,
136+
and both require telling people so and pointing at the source. */}
137+
<a
138+
className="text-caption text-text-muted underline-offset-2 transition-colors hover:text-brand hover:underline"
139+
href="https://github.com/Karaokio/cdg2mp4/blob/main/CREDITS.md"
140+
target="_blank"
141+
rel="noreferrer"
142+
onClick={() => track("credits_clicked")}
143+
>
144+
Credits
145+
</a>
110146
</div>
111147
<p className="text-caption text-text-muted">
112148
built by the robots at{" "}

0 commit comments

Comments
 (0)