Skip to content

Commit 5eec513

Browse files
fix(studio): the timeline takes m4v video and flac audio (#4649)
* fix(studio): the timeline takes m4v video and flac audio * fix(studio-server): check and label flac uploads as audio
1 parent 2119b18 commit 5eec513

7 files changed

Lines changed: 71 additions & 10 deletions

File tree

‎packages/studio-server/src/helpers/mediaMetadata.test.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,15 @@ describe("probeMediaMetadata", () => {
111111
expect(audioFile).not.toHaveProperty("hasAudio");
112112
});
113113

114+
it("reads a flac file as audio", async () => {
115+
const flac = await probeMediaMetadata("/tmp/music.flac", () => ({
116+
status: 0,
117+
stdout: "{}",
118+
stderr: "",
119+
}));
120+
expect(flac.kind).toBe("audio");
121+
});
122+
114123
it("ignores attached cover art and reads the real video stream", async () => {
115124
const metadata = await probeMediaMetadata("/tmp/clip.mp4", () => ({
116125
status: 0,

‎packages/studio-server/src/helpers/mediaMetadata.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ const VIDEO_EXT = new Set([
9696
".ts",
9797
]);
9898
const IMAGE_EXT = new Set([".jpg", ".jpeg", ".png", ".webp", ".avif"]);
99-
const AUDIO_EXT = new Set([".mp3", ".wav", ".ogg", ".m4a", ".aac"]);
99+
const AUDIO_EXT = new Set([".mp3", ".wav", ".ogg", ".m4a", ".aac", ".flac"]);
100100

101101
function lower(value: string | undefined): string {
102102
return value?.toLowerCase() ?? "";

‎packages/studio-server/src/helpers/mediaValidation.test.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,19 @@ describe("validateUploadedMedia", () => {
3838
).toEqual({ ok: false, reason: "no supported video stream found" });
3939
});
4040

41+
it.each(["/tmp/test.flac", "/tmp/test.m4v"])(
42+
"probes %s instead of passing it through",
43+
(path) => {
44+
expect(
45+
validateUploadedMedia(path, () => ({
46+
status: 0,
47+
stdout: JSON.stringify({ streams: [] }),
48+
stderr: "",
49+
})),
50+
).toMatchObject({ ok: false });
51+
},
52+
);
53+
4154
it("accepts audio files with an audio stream", () => {
4255
expect(
4356
validateUploadedMedia("/tmp/test.wav", () => ({

‎packages/studio-server/src/helpers/mediaValidation.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { basename, join } from "node:path";
55
import { FFPROBE_PATH_ENV, findFfBinary } from "@hyperframes/parsers/ff-binaries";
66

77
const VIDEO_EXT = /\.(mp4|webm|mov|mkv|avi|m4v|mxf|mts|m2ts|ts)$/i;
8-
const AUDIO_EXT = /\.(mp3|wav|ogg|m4a|aac)$/i;
8+
const AUDIO_EXT = /\.(mp3|wav|ogg|m4a|aac|flac)$/i;
99

1010
type FfprobeRunner = (
1111
command: string,

‎packages/studio/src/components/feedback/projectProvenance.ts‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,18 @@ import { buildProjectApiPath } from "../../utils/projectRouting";
1616
// ---------------------------------------------------------------------------
1717

1818
import type { FeedbackContext } from "./feedbackTrigger";
19+
import { isMediaFile } from "../../utils/mediaTypes";
1920

2021
/** Written by `hyperframes init`; absent in a hand-made or copied project. */
2122
const CONFIG_FILE = "hyperframes.json";
2223

2324
/** Matches the CLI's own slug gate, so a hand-edited value cannot leak text. */
2425
const SKILL_SLUG = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
2526

26-
const MEDIA_EXTENSIONS = /\.(mp4|mov|webm|m4v|mp3|wav|m4a|aac|ogg|png|jpe?g|gif|webp|svg|avif)$/i;
27-
2827
let snapshot: FeedbackContext = {};
2928

3029
function countMedia(files: string[]): number {
31-
return files.filter((f) => MEDIA_EXTENSIONS.test(f)).length;
30+
return files.filter(isMediaFile).length;
3231
}
3332

3433
/**
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { describe, expect, it } from "vitest";
2+
import { AUDIO_EXT, IMAGE_EXT, isMediaFile, MEDIA_EXT, VIDEO_EXT } from "./mediaTypes";
3+
import { getTimelineAssetKind } from "./timelineAssetDrop";
4+
5+
describe("media types", () => {
6+
it.each([
7+
["clip.m4v", "video"],
8+
["assets/Take 2.M4V", "video"],
9+
["song.flac", "audio"],
10+
["voice.FLAC", "audio"],
11+
["clip.mp4", "video"],
12+
["music.mp3", "audio"],
13+
["still.png", "image"],
14+
] as const)("the timeline takes %s as %s", (path, kind) => {
15+
expect(getTimelineAssetKind(path)).toBe(kind);
16+
expect(isMediaFile(path)).toBe(true);
17+
});
18+
19+
it("still refuses files that are not media", () => {
20+
for (const path of ["notes.pdf", "font.woff2", "grade.cube", "clip.m4v.txt", "flac"]) {
21+
expect(getTimelineAssetKind(path)).toBeNull();
22+
expect(isMediaFile(path)).toBe(false);
23+
}
24+
});
25+
26+
it("counts a file as media exactly when it is an image, video or audio file", () => {
27+
const paths = ["a.mp4", "a.m4v", "a.flac", "a.png", "a.ico", "a.woff", "a.pdf", "a.cube"];
28+
for (const path of paths) {
29+
const kinds = [IMAGE_EXT, VIDEO_EXT, AUDIO_EXT].filter((re) => re.test(path)).length;
30+
expect(MEDIA_EXT.test(path)).toBe(kinds > 0);
31+
}
32+
});
33+
});

‎packages/studio/src/utils/mediaTypes.ts‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
1-
export const IMAGE_EXT = /\.(jpg|jpeg|png|gif|webp|avif|svg|ico)$/i;
2-
export const VIDEO_EXT = /\.(mp4|webm|mov)$/i;
3-
export const AUDIO_EXT = /\.(mp3|wav|ogg|m4a|aac)$/i;
1+
const IMAGE_EXTS = ["jpg", "jpeg", "png", "gif", "webp", "avif", "svg", "ico"];
2+
const VIDEO_EXTS = ["mp4", "webm", "mov", "m4v"];
3+
const AUDIO_EXTS = ["mp3", "wav", "ogg", "m4a", "aac", "flac"];
4+
5+
function extensionPattern(extensions: readonly string[]): RegExp {
6+
return new RegExp(`\\.(${extensions.join("|")})$`, "i");
7+
}
8+
9+
export const IMAGE_EXT = extensionPattern(IMAGE_EXTS);
10+
export const VIDEO_EXT = extensionPattern(VIDEO_EXTS);
11+
export const AUDIO_EXT = extensionPattern(AUDIO_EXTS);
412
export const FONT_EXT = /\.(woff|woff2|ttf|ttc|otf|eot)$/i;
513
export const LUT_EXT = /\.cube$/i;
6-
export const MEDIA_EXT =
7-
/\.(mp4|webm|mov|mp3|wav|ogg|m4a|aac|jpg|jpeg|png|gif|webp|avif|svg|ico)$/i;
14+
export const MEDIA_EXT = extensionPattern([...VIDEO_EXTS, ...AUDIO_EXTS, ...IMAGE_EXTS]);
815

916
export function isMediaFile(path: string): boolean {
1017
return MEDIA_EXT.test(path);

0 commit comments

Comments
 (0)