fix: refuse media paths that ffmpeg's image2 demuxer would read as a pattern (#8047)

* fix: refuse media paths that ffmpeg's image2 demuxer would read as a pattern

ffmpeg's image2 demuxer reads %d, %03d, %% and a % before a wildcard in an
input path as a pattern of other files, folders included. Every project,
private-file and received-file check approves the literal path, so a
composition could name a placeholder whose pattern reaches images outside
the project and get them back as video frames.

Every ffmpeg and ffprobe input built from a project file now goes through
assertLiteralMediaInput, which refuses such a local path before ffmpeg runs.
The engine's urlInputArgs, the parsers' mediaInputFormatArgs and the
studio-server's new mediaInputArgs all take the input path, so the CLI
snapshot and cloud offload, lint, core grade analysis and studio-server
callers are covered too. URLs and other percent signs, such as %20, are
read as before.

* build(parsers): declare the literal-media-input subpath

* build: raise the parsers packed-size budget for the literal-media-input subpath

The new subpath adds its own built entry, type file and export map rows,
about 2.7 KB packed. It is a separate module so test suites that mock
ff-binaries still run the real path check.

* test(parsers): a harmless name shaped like a pattern is refused too
This commit is contained in:
Michael Wang
2026-11-17 07:28:09 +00:00
committed by GitHub
parent 14c4e4c268
commit fe93f9cd47
24 changed files with 206 additions and 49 deletions
+9 -9
View File
@@ -36,7 +36,7 @@ import { bytesMatchExtension } from "./offloadSniff.js";
import {
AUDIO_EXTS,
CONVERTIBLE_IMAGE_EXTS,
MEDIA_INPUT_ARGS,
mediaInputArgs,
startsAsMediaPlaylist,
VIDEO_EXTS,
} from "@hyperframes/studio-server/outside-file";
@@ -246,7 +246,7 @@ async function probeVideo(path: string): Promise<VideoProbe> {
"stream=codec_name,pix_fmt,color_primaries,color_transfer,color_space:stream_tags",
"-of",
"json",
...MEDIA_INPUT_ARGS,
...mediaInputArgs(path),
"--",
path,
]);
@@ -295,13 +295,13 @@ async function segmentArgs(
segments: PlayedSegment[] | undefined,
media: "audio" | "image" | "video",
): Promise<string[]> {
if (media === "image") return [...decoder, ...MEDIA_INPUT_ARGS, "-i", sourcePath];
if (media === "image") return [...decoder, ...mediaInputArgs(sourcePath), "-i", sourcePath];
const audio = await keptAudio(sourcePath, media);
const cuts = segments?.length ? segments : [undefined];
const inputs = cuts.flatMap((s) => [
...decoder,
...seekArgs(s),
...MEDIA_INPUT_ARGS,
...mediaInputArgs(sourcePath),
"-i",
sourcePath,
]);
@@ -313,7 +313,7 @@ async function segmentArgs(
}
async function keptAudio(sourcePath: string, media: "audio" | "video"): Promise<number | null> {
const audio = (await probeAudio(sourcePath, MEDIA_INPUT_ARGS))?.audioStream ?? null;
const audio = (await probeAudio(sourcePath, mediaInputArgs(sourcePath)))?.audioStream ?? null;
if (media === "audio" && audio === null) {
throw new Error("the file has no audio track ffmpeg can decode");
}
@@ -374,7 +374,7 @@ async function durationSeconds(sourcePath: string): Promise<number | null> {
"format=duration",
"-of",
"csv=p=0",
...MEDIA_INPUT_ARGS,
...mediaInputArgs(sourcePath),
"--",
sourcePath,
]);
@@ -466,7 +466,7 @@ async function isAnimatedImage(path: string): Promise<boolean> {
"stream=nb_frames",
"-of",
"csv=p=0",
...MEDIA_INPUT_ARGS,
...mediaInputArgs(path),
"--",
path,
]);
@@ -491,7 +491,7 @@ async function trimGrid(sourcePath: string, kind: MediaKind): Promise<number | n
"stream=r_frame_rate,avg_frame_rate",
"-of",
"csv=p=0",
...MEDIA_INPUT_ARGS,
...mediaInputArgs(sourcePath),
"--",
sourcePath,
]);
@@ -517,7 +517,7 @@ async function hasVideoStream(sourcePath: string): Promise<boolean> {
"stream=codec_type",
"-of",
"csv=p=0",
...MEDIA_INPUT_ARGS,
...mediaInputArgs(sourcePath),
"--",
sourcePath,
]);
+17 -5
View File
@@ -497,7 +497,7 @@ export async function probeContainingSourceFrameSeek(
const { stdout } = await runCancellableProcess(
ffprobe,
[
...["-v", "error", ...mediaInputFormatArgs(ffprobe)],
...["-v", "error", ...mediaInputFormatArgs(ffprobe, videoPath)],
...["-select_streams", "v:0", "-read_intervals", readIntervals],
...["-show_entries", entries, "-of", "json", "--", videoPath],
],
@@ -622,7 +622,13 @@ async function probeSeekLanding(
const { stdout } = await runCancellableProcess(
ffmpeg,
[
...["-v", "error", "-copyts", "-noaccurate_seek", ...mediaInputFormatArgs(ffmpeg)],
...[
"-v",
"error",
"-copyts",
"-noaccurate_seek",
...mediaInputFormatArgs(ffmpeg, videoPath),
],
...["-ss", String(seek), "-i", videoPath],
...["-map", "0:v:0", "-c", "copy", "-frames:v", "1", "-f", "framecrc", "-"],
],
@@ -683,7 +689,7 @@ async function frameColour(
const read = (args: string[]) =>
runFfmpegOnce(
ffmpegPath,
[...mediaInputFormatArgs(ffmpegPath), ...args],
[...mediaInputFormatArgs(ffmpegPath, videoPath), ...args],
FFMPEG_EXTRACT_TIMEOUT_MS,
);
const probe = await read(firstFrameColourArgs(videoPath));
@@ -737,7 +743,7 @@ export async function extractVideoFrameToBuffer(
const args = ["-hide_banner", "-loglevel", "error"];
if (useVp9AlphaDecoder) args.push("-c:v", "libvpx-vp9");
if (seek.seek !== undefined) args.push("-ss", String(seek.seek));
args.push(...mediaInputFormatArgs(ffmpegPath), "-i", videoPath, "-map", "0:v:0");
args.push(...mediaInputFormatArgs(ffmpegPath, videoPath), "-i", videoPath, "-map", "0:v:0");
const filters = frameFilters(seek.select, displayedPixels, metadata, toneMapFilter);
if (filters.length > 0) args.push("-vf", filters.join(","));
args.push("-frames:v", "1", "-q:v", "2", "-y", outPath);
@@ -798,7 +804,13 @@ export async function decodeFramesInOnePass(
const filters = [selectFirstFrameAfterEach(byTime.map(([offset]) => offset)), ...rest];
const args = ["-hide_banner", "-loglevel", "error"];
if (useVp9AlphaDecoder) args.push("-c:v", "libvpx-vp9");
args.push(...mediaInputFormatArgs(ffmpegPath), "-ss", String(start), "-i", videoPath);
args.push(
...mediaInputFormatArgs(ffmpegPath, videoPath),
"-ss",
String(start),
"-i",
videoPath,
);
args.push("-map", "0:v:0", "-vf", filters.join(","));
args.push("-fps_mode", "passthrough", "-frames:v", String(byTime.length));
args.push("-q:v", "2", "-y", join(tmp, "%d.png"));
@@ -118,7 +118,7 @@ export function probeHeldVideo(
[
"-v",
"error",
...mediaInputFormatArgs(ffprobe),
...mediaInputFormatArgs(ffprobe, path),
"-select_streams",
"v:0",
"-show_entries",
+2 -2
View File
@@ -116,7 +116,7 @@ function probeMedia(mediaPath: string, ffprobePath: string): GradeMediaProbe {
[
"-v",
"error",
...mediaInputFormatArgs(ffprobePath),
...mediaInputFormatArgs(ffprobePath, mediaPath),
"-select_streams",
"v:0",
"-show_entries",
@@ -322,7 +322,7 @@ function readSignalStats(
"-nostdin",
"-v",
"error",
...mediaInputFormatArgs(ffmpegPath),
...mediaInputFormatArgs(ffmpegPath, mediaPath),
...keyframeSeek,
"-i",
mediaPath,
@@ -26,6 +26,13 @@ const formatsOf = (args: string[]) => args[args.indexOf("-format_whitelist") + 1
describe("urlInputArgs", () => {
afterEach(() => _setDemuxerListingForTests());
it("refuses a local path that ffmpeg would read as a pattern of other files", () => {
_setDemuxerListingForTests(LISTING);
expect(() => urlInputArgs("/job/.x%d/decoy%d.png")).toThrow(/pattern of other files/);
expect(() => urlInputArgs("/job/clip%%.mp4", { tool: "ffprobe" })).toThrow(/pattern/);
expect(formatsOf(urlInputArgs("/job/clip 100% done.mp4"))).toContain("mov");
});
const caBundles = ["/nonexistent.crt", import.meta.filename];
const verifyAndReconnect = [
"-tls_verify",
+7 -2
View File
@@ -1,6 +1,10 @@
import { existsSync } from "node:fs";
import { redactUrlQueryStrings } from "@hyperframes/core";
import { SELF_CONTAINED_FORMATS, mediaInputFormatArgs } from "@hyperframes/parsers/ff-binaries";
import {
SELF_CONTAINED_FORMATS,
assertLiteralMediaInput,
mediaInputFormatArgs,
} from "@hyperframes/parsers/ff-binaries";
import { resolveRestrictPageNetwork } from "../config.js";
import { getFfmpegBinary, getFfprobeBinary } from "./ffmpegBinaries.js";
@@ -57,8 +61,9 @@ export function urlInputArgs(
caBundles = CA_BUNDLES,
}: { tool?: "ffmpeg" | "ffprobe"; caBundles?: readonly string[] } = {},
): string[] {
assertLiteralMediaInput(input);
const mediaFormats = () =>
mediaInputFormatArgs(tool === "ffprobe" ? getFfprobeBinary() : getFfmpegBinary());
mediaInputFormatArgs(tool === "ffprobe" ? getFfprobeBinary() : getFfmpegBinary(), input);
const restricted = resolveRestrictPageNetwork();
const route = restricted ? restrictedRoute(input) : undefined;
if (route === "proxy" && !/^https:\/\//i.test(input))
+2 -2
View File
@@ -88,7 +88,7 @@ async function probeIsHevc(ffprobePath: string, filePath: string): Promise<boole
const stdout = await execFileAsync(ffprobePath, [
"-v",
"error",
...mediaInputFormatArgs(ffprobePath),
...mediaInputFormatArgs(ffprobePath, filePath),
"-select_streams",
"v:0",
"-show_entries",
@@ -245,7 +245,7 @@ async function probePlayableVideoDuration(
await execFileAsync(ffprobePath, [
"-v",
"error",
...mediaInputFormatArgs(ffprobePath),
...mediaInputFormatArgs(ffprobePath, filePath),
"-select_streams",
"v:0",
"-show_entries",
+6
View File
@@ -122,6 +122,12 @@
"types": "./dist/ffBinaries.d.ts",
"environments": ["bun", "node"]
},
"./literal-media-input": {
"source": "./src/literalMediaInput.ts",
"runtime": "./dist/literalMediaInput.js",
"types": "./dist/literalMediaInput.d.ts",
"environments": ["bun", "node"]
},
"./media-alpha": {
"source": "./src/mediaAlpha.ts",
"runtime": "./dist/mediaAlpha.js",
+10
View File
@@ -130,6 +130,12 @@
"import": "./src/ffBinaries.ts",
"types": "./src/ffBinaries.ts"
},
"./literal-media-input": {
"bun": "./src/literalMediaInput.ts",
"node": "./dist/literalMediaInput.js",
"import": "./src/literalMediaInput.ts",
"types": "./src/literalMediaInput.ts"
},
"./media-alpha": {
"bun": "./src/mediaAlpha.ts",
"node": "./dist/mediaAlpha.js",
@@ -265,6 +271,10 @@
"import": "./dist/ffBinaries.js",
"types": "./dist/ffBinaries.d.ts"
},
"./literal-media-input": {
"import": "./dist/literalMediaInput.js",
"types": "./dist/literalMediaInput.d.ts"
},
"./media-alpha": {
"import": "./dist/mediaAlpha.js",
"types": "./dist/mediaAlpha.d.ts"
+83 -5
View File
@@ -497,7 +497,12 @@ describe("mediaInputFormatArgs", () => {
" D mov,mp4,m4a QuickTime / MOV",
].join("\n"),
);
expect(formatsOf(mediaInputFormatArgs("/ffprobe"))).toEqual(["3dostr", "mov", "mp4", "m4a"]);
expect(formatsOf(mediaInputFormatArgs("/ffprobe", "clip.mp4"))).toEqual([
"3dostr",
"mov",
"mp4",
"m4a",
]);
});
it("leaves out the demuxers that draw a text file as a picture", async () => {
@@ -512,7 +517,7 @@ describe("mediaInputFormatArgs", () => {
" D xbin eXtended BINary text (XBIN)",
].join("\n"),
);
expect(formatsOf(mediaInputFormatArgs("/ffmpeg"))).toEqual(["mov", "mp4", "m4a"]);
expect(formatsOf(mediaInputFormatArgs("/ffmpeg", "clip.mp4"))).toEqual(["mov", "mp4", "m4a"]);
});
it("keeps the installed ffmpeg from decoding a text file into a frame", async () => {
@@ -527,7 +532,7 @@ describe("mediaInputFormatArgs", () => {
const note = join(dir, "note.asc");
writeFileSync(note, "API_KEY=not-a-video\nsecond line\n");
const frame = join(dir, "frame.png");
const args = ["-v", "error", "-y", ...mediaInputFormatArgs(ffmpeg), "-i", note];
const args = ["-v", "error", "-y", ...mediaInputFormatArgs(ffmpeg, note), "-i", note];
spawnSync(ffmpeg, [...args, "-frames:v", "1", frame]);
expect(existsSync(frame)).toBe(false);
});
@@ -542,7 +547,80 @@ describe("mediaInputFormatArgs", () => {
`#!/bin/sh\nif [ -e "${dir}/ran" ]; then echo ' D wav WAV'; else touch "${dir}/ran"; exit 1; fi\n`,
);
chmodSync(binary, 0o755);
expect(mediaInputFormatArgs(binary)).toEqual(["-format_whitelist", SELF_CONTAINED_FORMATS]);
expect(mediaInputFormatArgs(binary)).toEqual(["-format_whitelist", "wav"]);
expect(mediaInputFormatArgs(binary, "a.wav")).toEqual([
"-format_whitelist",
SELF_CONTAINED_FORMATS,
]);
expect(mediaInputFormatArgs(binary, "a.wav")).toEqual(["-format_whitelist", "wav"]);
});
});
describe("assertLiteralMediaInput", () => {
it("refuses a local path ffmpeg's image2 demuxer would read as a pattern of other files", async () => {
const { assertLiteralMediaInput } = await importFresh();
for (const path of [
"/job/decoy%d.png",
"/job/frame%03d.jpg",
"/job/%%/still.png",
"/job/x%*/still.png",
"/job/x%[ab]/still.png",
"/job/x%{a,b}/still.png",
"file:/job/decoy%d.png",
]) {
expect(() => assertLiteralMediaInput(path), path).toThrow(/pattern of other files/);
}
});
it("also refuses a harmless name that looks like a pattern, such as a %20 before a d", async () => {
const { assertLiteralMediaInput } = await importFresh();
expect(() => assertLiteralMediaInput("/job/My%20demo.mp4")).toThrow(
/Rename the file or folder/,
);
expect(() => assertLiteralMediaInput("/job/a%2d/clip.mp4")).toThrow(
/Rename the file or folder/,
);
});
it("reads other percent signs, and URLs, as written", async () => {
const { assertLiteralMediaInput } = await importFresh();
for (const path of [
"/job/clip 100% done.mp4",
"/job/My%20Video.mp4",
"/job/a%2D.png",
"C:\\job\\clip.mp4",
"https://cdn.example/a%2d.png",
]) {
expect(() => assertLiteralMediaInput(path), path).not.toThrow();
}
});
it("stops the installed ffmpeg from reaching images next to a placeholder", async () => {
vi.resetModules();
vi.doUnmock("node:fs");
vi.doUnmock("node:child_process");
const { findFfBinary, mediaInputFormatArgs } = await importFresh();
const ffmpeg = findFfBinary("ffmpeg");
if (!ffmpeg) return;
const dir = mkdtempSync(join(tmpdir(), "hf-image2-pattern-"));
onTestFinished(() => rmSync(dir, { recursive: true, force: true }));
const decoy = join(dir, "decoy1.png");
spawnSync(ffmpeg, [
"-v",
"error",
"-f",
"lavfi",
"-i",
"color=red:s=16x16",
"-frames:v",
"1",
decoy,
]);
if (!existsSync(decoy)) return;
const pattern = join(dir, "decoy%d.png");
const frame = join(dir, "frame.png");
// Without the check, ffmpeg opens decoy1.png through the pattern; no file is named decoy%d.png.
spawnSync(ffmpeg, ["-v", "error", "-y", "-i", pattern, "-frames:v", "1", frame]);
expect(existsSync(frame)).toBe(true);
expect(() => mediaInputFormatArgs(ffmpeg, pattern)).toThrow(/pattern of other files/);
});
});
+6 -2
View File
@@ -26,6 +26,7 @@ export {
pathEntries,
trustedPathDirs,
} from "./trustedExecutable.js";
import { assertLiteralMediaInput } from "./literalMediaInput.js";
export const FFMPEG_PATH_ENV = "HYPERFRAMES_FFMPEG_PATH";
export const FFPROBE_PATH_ENV = "HYPERFRAMES_FFPROBE_PATH";
@@ -294,8 +295,11 @@ export function _setDemuxerListingForTests(listing?: string): void {
demuxerLists.clear();
}
/** Every demuxer `listingBinary` reports that opens nothing by itself and is not text art; one that cannot be asked gets the self-contained list, and is asked again. */
export function mediaInputFormatArgs(listingBinary: string): string[] {
export { assertLiteralMediaInput };
/** Every demuxer `listingBinary` reports that opens nothing by itself and is not text art, for reading `input`; one that cannot be asked gets the self-contained list, and is asked again. */
export function mediaInputFormatArgs(listingBinary: string, input: string): string[] {
assertLiteralMediaInput(input);
let formats = demuxerLists.get(listingBinary);
if (formats === undefined) {
try {
+12
View File
@@ -0,0 +1,12 @@
const PATTERN_IMAGE2_EXPANDS = /%(?:\d*d|[%*?[\]{}])/;
const URL_SCHEME = /^[a-z][a-z0-9+.-]+:/i;
/** ffmpeg's image2 demuxer would open other files, folders included, than the one a project check approved. */
export function assertLiteralMediaInput(input: string): void {
const local = !URL_SCHEME.test(input) || /^file:/i.test(input);
if (!local || !PATTERN_IMAGE2_EXPANDS.test(input)) return;
throw new Error(
`[FFmpeg] refused media path "${input.split(/[\\/]/).pop()}": a "%" followed by a number and "d", ` +
'another "%" or a wildcard would make ffmpeg read it as a pattern of other files. Rename the file or folder.',
);
}
+1
View File
@@ -22,6 +22,7 @@ export default defineConfig({
colorGradingContract: "src/colorGradingContract.ts",
subCompositionValidity: "src/subCompositionValidity.ts",
ffBinaries: "src/ffBinaries.ts",
literalMediaInput: "src/literalMediaInput.ts",
mediaAlpha: "src/mediaAlpha.ts",
mediaStreams: "src/mediaStreams.ts",
assetResolution: "src/assetResolution.ts",
@@ -3,7 +3,7 @@ import { ensureHfIds } from "@hyperframes/parsers/hf-ids";
import { readMediaOffsetSeconds } from "@hyperframes/parsers/media-duration";
import { resolveRateSpec, sourceTimeAt } from "@hyperframes/core/speed-ramp";
import { MEDIA_LINK_ATTR as LINK_ATTR, relinkSplitHalves } from "@hyperframes/core/media-link";
import { MEDIA_INPUT_ARGS } from "./mediaExtensions.js";
import { mediaInputArgs } from "./mediaExtensions.js";
import {
findTargetElement,
isHTMLElement,
@@ -46,7 +46,7 @@ export function freezeExtractArgs(src: string, mediaTime: number, output: string
"-y",
"-ss",
String(round3(mediaTime)),
...MEDIA_INPUT_ARGS,
...mediaInputArgs(src),
"-i",
src,
"-frames:v",
@@ -8,7 +8,7 @@ import { findFfBinary } from "@hyperframes/parsers/ff-binaries";
import { readMediaOffsetSeconds } from "@hyperframes/parsers/media-duration";
import { requestedProjectPath } from "./requestSubPath.js";
import { probeAudioTrack } from "./mediaMetadata.js";
import { MEDIA_INPUT_ARGS } from "./mediaExtensions.js";
import { mediaInputArgs } from "./mediaExtensions.js";
const execFileAsync = promisify(execFile);
@@ -455,7 +455,7 @@ export function loudnessMeasureArgs(file: string, tag: MeasuredWindow, stream: n
const sourceSpan = tag.duration === null ? null : tag.duration * (tag.playbackRate ?? 1);
if (sourceSpan !== null && sourceSpan > 0) args.push("-t", String(sourceSpan));
args.push(
...MEDIA_INPUT_ARGS,
...mediaInputArgs(file),
"-i",
file,
"-map",
@@ -4,7 +4,7 @@ import { tmpdir } from "node:os";
import { join } from "node:path";
import { afterAll, describe, expect, it } from "vitest";
import { findFfBinary } from "@hyperframes/parsers/ff-binaries";
import { MEDIA_INPUT_ARGS } from "./mediaExtensions.js";
import { MEDIA_INPUT_ARGS, mediaInputArgs } from "./mediaExtensions.js";
const ffmpeg = findFfBinary("ffmpeg");
const ffprobe = findFfBinary("ffprobe");
@@ -66,3 +66,10 @@ describe.skipIf(!ffmpeg || !ffprobe)("MEDIA_INPUT_ARGS with a real ffprobe", ()
expect(result.stderr).toMatch(/not on whitelist/);
});
});
describe("mediaInputArgs", () => {
it("refuses a path ffmpeg would read as a pattern of other files", () => {
expect(() => mediaInputArgs(join(dir, "decoy%d.png"))).toThrow(/pattern of other files/);
expect(mediaInputArgs(join(dir, "clip 100% done.mp4"))).toEqual(MEDIA_INPUT_ARGS);
});
});
@@ -1,3 +1,5 @@
import { assertLiteralMediaInput } from "@hyperframes/parsers/literal-media-input";
export const VIDEO_EXTS = new Set([
".mp4",
".m4v",
@@ -38,6 +40,11 @@ export const MEDIA_INPUT_ARGS: readonly string[] = [
"mov,matroska,mxf,avi,mpeg,mpegts,mpegvideo,flv,asf,ogg,wav,mp3,aac,flac,aiff,gif,image2,png_pipe,jpeg_pipe,webp_pipe,bmp_pipe,tiff_pipe",
];
export function mediaInputArgs(input: string): readonly string[] {
assertLiteralMediaInput(input);
return MEDIA_INPUT_ARGS;
}
const PLAYLIST_START = /^(?:\xEF\xBB\xBF)?\s*(?:#EXTM3U|ffconcat)/;
const MARKUP_START = /^(?:\xEF\xBB\xBF)?\s*</;
export const isControlByte = (byte: number) => byte < 0x09 || (byte > 0x0d && byte < 0x20);
@@ -11,7 +11,7 @@ import {
type ToneMapFrameColour,
} from "@hyperframes/core";
import { findFfBinary } from "@hyperframes/parsers/ff-binaries";
import { MEDIA_INPUT_ARGS, NOT_MEDIA, startsAsMediaPlaylist } from "./mediaExtensions.js";
import { mediaInputArgs, NOT_MEDIA, startsAsMediaPlaylist } from "./mediaExtensions.js";
import { videoStreamHasAlpha } from "@hyperframes/parsers/media-alpha";
import { decodableAudioStream, type FfprobeStreamCodec } from "@hyperframes/parsers/media-streams";
@@ -204,7 +204,7 @@ export async function probeFirstFrameColour(
if (!ffmpegPath) return {};
const result = await runner(
ffmpegPath,
[...MEDIA_INPUT_ARGS, ...firstFrameColourArgs(filePath)],
[...mediaInputArgs(filePath), ...firstFrameColourArgs(filePath)],
{
timeout: 15_000,
maxBuffer: 1024 * 1024,
@@ -214,7 +214,7 @@ export async function probeFirstFrameColour(
if (result.status !== 0 || !readsKeyframeTransfers(first)) return first;
const keyframes = await runner(
ffmpegPath,
[...MEDIA_INPUT_ARGS, ...keyframeTransferArgs(filePath, codec)],
[...mediaInputArgs(filePath), ...keyframeTransferArgs(filePath, codec)],
{
timeout: 30_000,
maxBuffer: 8 * 1024 * 1024,
@@ -332,7 +332,7 @@ export async function probeAudioTrack(
"stream=codec_type,codec_name,channels",
"-of",
"json",
...MEDIA_INPUT_ARGS,
...mediaInputArgs(filePath),
"--",
filePath,
],
@@ -375,7 +375,7 @@ export async function probeMediaMetadata(
"stream=codec_type,codec_name,profile,pix_fmt,color_space,color_transfer,color_primaries,bits_per_raw_sample,width,height,bit_rate,r_frame_rate,avg_frame_rate:stream_disposition:stream_tags=alpha_mode:format=duration,bit_rate",
"-of",
"json",
...MEDIA_INPUT_ARGS,
...mediaInputArgs(filePath),
"--",
filePath,
],
@@ -4,7 +4,7 @@ import { tmpdir } from "node:os";
import { basename, join } from "node:path";
import { FFPROBE_PATH_ENV, findFfBinary } from "@hyperframes/parsers/ff-binaries";
import { decodableAudioStream, type FfprobeStreamCodec } from "@hyperframes/parsers/media-streams";
import { MEDIA_INPUT_ARGS } from "./mediaExtensions.js";
import { mediaInputArgs } from "./mediaExtensions.js";
const VIDEO_EXT = /\.(mp4|webm|mov|mkv|avi|m4v|mxf|mts|m2ts|ts)$/i;
const AUDIO_EXT = /\.(mp3|wav|ogg|m4a|aac|flac)$/i;
@@ -47,7 +47,7 @@ export function validateUploadedMedia(
"stream=codec_type,codec_name",
"-of",
"json",
...MEDIA_INPUT_ARGS,
...mediaInputArgs(filePath),
"--",
filePath,
],
@@ -7,12 +7,20 @@ import {
CONVERTIBLE_IMAGE_EXTS,
isControlByte,
MEDIA_INPUT_ARGS,
mediaInputArgs,
startsAsMediaPlaylist,
VIDEO_EXTS,
} from "./mediaExtensions.js";
import { realFilePath } from "./safePath.js";
export { AUDIO_EXTS, CONVERTIBLE_IMAGE_EXTS, MEDIA_INPUT_ARGS, startsAsMediaPlaylist, VIDEO_EXTS };
export {
AUDIO_EXTS,
CONVERTIBLE_IMAGE_EXTS,
MEDIA_INPUT_ARGS,
mediaInputArgs,
startsAsMediaPlaylist,
VIDEO_EXTS,
};
const COPIED_TYPE = /^(?:image|video|audio|font)\/|^text\/(?:css|javascript);/;
@@ -1,7 +1,7 @@
import { spawn } from "node:child_process";
import { requireFfBinary } from "@hyperframes/parsers/ff-binaries";
import { probeAudioTrack } from "./mediaMetadata.js";
import { MEDIA_INPUT_ARGS } from "./mediaExtensions.js";
import { mediaInputArgs } from "./mediaExtensions.js";
export const PEAK_BIN_SECONDS = 0.05;
const PEAK_SAMPLE_RATE = 48_000;
@@ -73,7 +73,7 @@ export async function decodePeakMap(mediaPath: string, signal?: AbortSignal): Pr
[
"-v",
"error",
...MEDIA_INPUT_ARGS,
...mediaInputArgs(mediaPath),
"-i",
mediaPath,
"-map",
@@ -15,7 +15,7 @@ import { hdrToSdrToneMapFilter, type PreviewProxyBox } from "@hyperframes/core";
import { findFfBinary } from "@hyperframes/parsers/ff-binaries";
import { alphaDecoderFor } from "@hyperframes/parsers/media-alpha";
import { ffmpegHasHdrFilters } from "./hdrFilters.js";
import { MEDIA_INPUT_ARGS, NOT_MEDIA } from "./mediaExtensions.js";
import { mediaInputArgs, NOT_MEDIA } from "./mediaExtensions.js";
import { probeFirstFrameColour, probeMediaMetadata } from "./mediaMetadata.js";
import { cleanupProxyCache } from "./proxyCache.js";
import {
@@ -776,7 +776,7 @@ async function runFfmpeg(
"-nostats",
...(range ? ["-ss", String(range.startSeconds)] : []),
...decoderArgs,
...MEDIA_INPUT_ARGS,
...mediaInputArgs(sourcePath),
"-i",
sourcePath,
...streamArgs,
@@ -1249,7 +1249,7 @@ async function makeStill(
"-y",
"-ss",
String(at),
...MEDIA_INPUT_ARGS,
...mediaInputArgs(source.sourcePath),
"-i",
source.sourcePath,
"-map",
@@ -15,7 +15,7 @@ import { requireFfBinary } from "@hyperframes/parsers/ff-binaries";
import { probeAudioTrack } from "./mediaMetadata.js";
import { createStagingDir } from "@hyperframes/core/atomic-file";
import { isProjectCacheFile, readProjectCacheFile } from "./safePath.js";
import { MEDIA_INPUT_ARGS } from "./mediaExtensions.js";
import { mediaInputArgs } from "./mediaExtensions.js";
const SAMPLE_RATE = 4000;
const PEAK_COUNT = 4000;
@@ -118,7 +118,7 @@ export async function decodeAudioPeaks(audioPath: string, signal?: AbortSignal):
const proc = spawn(
ffmpeg,
[
...MEDIA_INPUT_ARGS,
...mediaInputArgs(audioPath),
"-i",
audioPath,
"-map",
+1 -1
View File
@@ -28,7 +28,7 @@
"unpacked": 737342
},
"@hyperframes/parsers": {
"packed": 212000,
"packed": 215500,
"unpacked": 915000
},
"@hyperframes/player": {