mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-25 08:32:45 +00:00
fix(parsers): callers that read mediaInputFormatArgs by position get the format list again (#8806)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { execFile } from "node:child_process";
|
||||
import { promisify } from "node:util";
|
||||
import { findFfBinary, mediaInputFormatArgs } from "@hyperframes/parsers/ff-binaries";
|
||||
import { findFfBinary, mediaInputArgs } from "@hyperframes/parsers/ff-binaries";
|
||||
import { assertLiteralMediaInput } from "@hyperframes/parsers/literal-media-input";
|
||||
import {
|
||||
decodableAudioStream,
|
||||
@@ -26,7 +26,7 @@ function requiredBinary(name: "ffmpeg" | "ffprobe"): string {
|
||||
}
|
||||
|
||||
function literalInputArgs(binary: string, file: string, inputArgs: readonly string[]) {
|
||||
if (inputArgs.length === 0) return mediaInputFormatArgs(binary, file);
|
||||
if (inputArgs.length === 0) return mediaInputArgs(binary, file);
|
||||
assertLiteralMediaInput(file);
|
||||
return inputArgs;
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
import { mkdtemp, rm } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { dirname, join } from "node:path";
|
||||
import { findFfBinary, mediaInputFormatArgs } from "@hyperframes/parsers/ff-binaries";
|
||||
import { findFfBinary, mediaInputArgs } from "@hyperframes/parsers/ff-binaries";
|
||||
import { replaceFileAtomically } from "@hyperframes/core/atomic-file";
|
||||
import { setTimeout as sleep } from "node:timers/promises";
|
||||
import { downloadToFile } from "../../cloud/download.js";
|
||||
@@ -174,7 +174,7 @@ async function encoded(path: string, dir: string, signal: AbortSignal): Promise<
|
||||
await runFile(
|
||||
ffmpeg,
|
||||
[
|
||||
...["-v", "error", "-y", ...mediaInputFormatArgs(ffmpeg, path), "-i", path],
|
||||
...["-v", "error", "-y", ...mediaInputArgs(ffmpeg, path), "-i", path],
|
||||
...["-map", `0:a:${audio.audioStream}`],
|
||||
...["-vn", "-ac", "2", "-ar", "44100", "-b:a", "192k", out],
|
||||
],
|
||||
|
||||
@@ -17,7 +17,7 @@ import { spawn } from "node:child_process";
|
||||
import { randomUUID } from "node:crypto";
|
||||
import { renameSync, rmSync } from "node:fs";
|
||||
import { basename, dirname, extname, join } from "node:path";
|
||||
import { mediaInputFormatArgs } from "@hyperframes/parsers/ff-binaries";
|
||||
import { mediaInputArgs } from "@hyperframes/parsers/ff-binaries";
|
||||
import { findFFmpeg, findFFprobe, getFFmpegInstallHint } from "../browser/ffmpeg.js";
|
||||
import { runCancellableProcess } from "../utils/cancellableProcess.js";
|
||||
import { readFrames } from "./frameReader.js";
|
||||
@@ -132,7 +132,7 @@ async function decoderTransposesDimensions(inputPath: string): Promise<boolean>
|
||||
"-show_streams",
|
||||
"-print_format",
|
||||
"json",
|
||||
...mediaInputFormatArgs(ffprobePath, inputPath),
|
||||
...mediaInputArgs(ffprobePath, inputPath),
|
||||
"--",
|
||||
inputPath,
|
||||
],
|
||||
@@ -438,7 +438,7 @@ async function runPipeline(
|
||||
const decoder = spawnFfmpeg(
|
||||
ffmpegPath,
|
||||
[
|
||||
...["-loglevel", "error", ...mediaInputFormatArgs(ffmpegPath, inputPath), "-i", inputPath],
|
||||
...["-loglevel", "error", ...mediaInputArgs(ffmpegPath, inputPath), "-i", inputPath],
|
||||
...["-f", "rawvideo", "-pix_fmt", "rgb24", "-an", "-"],
|
||||
],
|
||||
"ffmpeg decoder",
|
||||
|
||||
@@ -23,7 +23,7 @@ import {
|
||||
import { gsapCdnDist } from "@hyperframes/core/gsap-cdn";
|
||||
import { defineCommand } from "../utils/defineCommand.js";
|
||||
import type { Example } from "./_examples.js";
|
||||
import { mediaInputFormatArgs } from "@hyperframes/parsers/ff-binaries";
|
||||
import { mediaInputArgs } from "@hyperframes/parsers/ff-binaries";
|
||||
import { openSettledCompositionPage, runFfmpegOnce } from "../capture/captureCompositionFrame.js";
|
||||
import { findFFmpeg } from "../browser/ffmpeg.js";
|
||||
import { c } from "../ui/colors.js";
|
||||
@@ -519,7 +519,7 @@ async function extractVideoFrameToBuffer(videoPath: string): Promise<Buffer | nu
|
||||
"error",
|
||||
"-ss",
|
||||
"0",
|
||||
...mediaInputFormatArgs(ffmpegPath, videoPath),
|
||||
...mediaInputArgs(ffmpegPath, videoPath),
|
||||
"-i",
|
||||
videoPath,
|
||||
"-frames:v",
|
||||
|
||||
@@ -51,7 +51,7 @@ import { trackInitTemplate } from "../telemetry/events.js";
|
||||
import { DEFAULT_MODEL, hasFFmpeg } from "../whisper/manager.js";
|
||||
import { TRANSCRIPT_FILE } from "../whisper/transcriptFile.js";
|
||||
import { initialModelForLanguage } from "../whisper/transcribe.js";
|
||||
import { mediaInputFormatArgs } from "@hyperframes/parsers/ff-binaries";
|
||||
import { mediaInputArgs } from "@hyperframes/parsers/ff-binaries";
|
||||
import { findFFmpeg, findFFprobe, getFFmpegInstallHint } from "../browser/ffmpeg.js";
|
||||
import { VERSION } from "../version.js";
|
||||
import {
|
||||
@@ -135,7 +135,7 @@ function probeVideo(filePath: string): VideoMeta | undefined {
|
||||
[
|
||||
"-v",
|
||||
"quiet",
|
||||
...mediaInputFormatArgs(ffprobePath, filePath),
|
||||
...mediaInputArgs(ffprobePath, filePath),
|
||||
"-print_format",
|
||||
"json",
|
||||
"-show_format",
|
||||
@@ -244,7 +244,7 @@ export function transcodeToMp4(inputPath: string, outputPath: string): Promise<b
|
||||
const child = spawn(
|
||||
ffmpegPath,
|
||||
[
|
||||
...mediaInputFormatArgs(ffmpegPath, inputPath),
|
||||
...mediaInputArgs(ffmpegPath, inputPath),
|
||||
"-i",
|
||||
inputPath,
|
||||
"-c:v",
|
||||
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
isHdrColorSpace,
|
||||
sdrCanvasColourFilters,
|
||||
} from "@hyperframes/engine";
|
||||
import { mediaInputFormatArgs } from "@hyperframes/parsers/ff-binaries";
|
||||
import { mediaInputArgs } from "@hyperframes/parsers/ff-binaries";
|
||||
import { projectFolder } from "../utils/projectRecords.js";
|
||||
import { screenshotOnceMore } from "../utils/screenshotOnceMore.js";
|
||||
import { parseTimeoutMs } from "../utils/timeoutArg.js";
|
||||
@@ -499,11 +499,7 @@ export async function probeContainingSourceFrameSeek(
|
||||
const { stdout } = await runCancellableProcess(
|
||||
ffprobe,
|
||||
[
|
||||
...[
|
||||
"-v",
|
||||
"error",
|
||||
...mediaInputFormatArgs(ffprobe, videoPath, WALKED_BY_PROJECT_VIDEO_FILE),
|
||||
],
|
||||
...["-v", "error", ...mediaInputArgs(ffprobe, videoPath, WALKED_BY_PROJECT_VIDEO_FILE)],
|
||||
...["-select_streams", "v:0", "-read_intervals", readIntervals],
|
||||
...["-show_entries", entries, "-of", "json", "--", videoPath],
|
||||
],
|
||||
@@ -633,7 +629,7 @@ async function probeSeekLanding(
|
||||
"error",
|
||||
"-copyts",
|
||||
"-noaccurate_seek",
|
||||
...mediaInputFormatArgs(ffmpeg, videoPath, WALKED_BY_PROJECT_VIDEO_FILE),
|
||||
...mediaInputArgs(ffmpeg, videoPath, WALKED_BY_PROJECT_VIDEO_FILE),
|
||||
],
|
||||
...["-ss", String(seek), "-i", videoPath],
|
||||
...["-map", "0:v:0", "-c", "copy", "-frames:v", "1", "-f", "framecrc", "-"],
|
||||
@@ -695,7 +691,7 @@ async function frameColour(
|
||||
const read = (args: string[]) =>
|
||||
runFfmpegOnce(
|
||||
ffmpegPath,
|
||||
[...mediaInputFormatArgs(ffmpegPath, videoPath, WALKED_BY_PROJECT_VIDEO_FILE), ...args],
|
||||
[...mediaInputArgs(ffmpegPath, videoPath, WALKED_BY_PROJECT_VIDEO_FILE), ...args],
|
||||
FFMPEG_EXTRACT_TIMEOUT_MS,
|
||||
);
|
||||
const probe = await read(firstFrameColourArgs(videoPath));
|
||||
@@ -750,7 +746,7 @@ export async function extractVideoFrameToBuffer(
|
||||
if (useVp9AlphaDecoder) args.push("-c:v", "libvpx-vp9");
|
||||
if (seek.seek !== undefined) args.push("-ss", String(seek.seek));
|
||||
args.push(
|
||||
...mediaInputFormatArgs(ffmpegPath, videoPath, WALKED_BY_PROJECT_VIDEO_FILE),
|
||||
...mediaInputArgs(ffmpegPath, videoPath, WALKED_BY_PROJECT_VIDEO_FILE),
|
||||
"-i",
|
||||
videoPath,
|
||||
"-map",
|
||||
@@ -817,7 +813,7 @@ export async function decodeFramesInOnePass(
|
||||
const args = ["-hide_banner", "-loglevel", "error"];
|
||||
if (useVp9AlphaDecoder) args.push("-c:v", "libvpx-vp9");
|
||||
args.push(
|
||||
...mediaInputFormatArgs(ffmpegPath, videoPath, WALKED_BY_PROJECT_VIDEO_FILE),
|
||||
...mediaInputArgs(ffmpegPath, videoPath, WALKED_BY_PROJECT_VIDEO_FILE),
|
||||
"-ss",
|
||||
String(start),
|
||||
"-i",
|
||||
|
||||
@@ -4,7 +4,7 @@ import { parseHTML } from "@hyperframes/parsers/linkedom";
|
||||
import { MEDIA_RENDER_ID_ATTR, naturalVideoSize, streamRotation } from "@hyperframes/core";
|
||||
import { isPrivateFileUnder, isStudioPrivatePath } from "@hyperframes/core/safe-path";
|
||||
import { isNotMediaPayload, type CaptureVideoMetadataHint } from "@hyperframes/engine";
|
||||
import { mediaInputFormatArgs } from "@hyperframes/parsers/ff-binaries";
|
||||
import { mediaInputArgs } from "@hyperframes/parsers/ff-binaries";
|
||||
import { findFFprobe } from "../browser/ffmpeg.js";
|
||||
import { runCancellableProcess } from "../utils/cancellableProcess.js";
|
||||
|
||||
@@ -108,7 +108,7 @@ export function probeHeldVideo(
|
||||
[
|
||||
"-v",
|
||||
"error",
|
||||
...mediaInputFormatArgs(ffprobe, path, { playlists: true }),
|
||||
...mediaInputArgs(ffprobe, path, { playlists: true }),
|
||||
"-select_streams",
|
||||
"v:0",
|
||||
"-show_entries",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// How big the face is and where, ported from hf-media's face_size: OpenCV's frontal and profile Haar cascades on
|
||||
// evenly spaced frames, graded by face height over frame height. A regenerated presenter keeps the likeness from
|
||||
// FACE_HOLDS up; below FACE_FLOOR a video model cannot carry one at all (the harness's face-size eval, 2026-10-08).
|
||||
import { mediaInputFormatArgs } from "@hyperframes/parsers/ff-binaries";
|
||||
import { mediaInputArgs } from "@hyperframes/parsers/ff-binaries";
|
||||
import {
|
||||
GUARDED_RUN_MS,
|
||||
ffmpegBin,
|
||||
@@ -56,7 +56,7 @@ export function minWindow(h: number, share: number): number {
|
||||
}
|
||||
|
||||
function decode(info: VideoInfo, args: string[]): Buffer {
|
||||
const formats = mediaInputFormatArgs(ffmpegBin(), info.path, { playlists: info.guarded });
|
||||
const formats = mediaInputArgs(ffmpegBin(), info.path, { playlists: info.guarded });
|
||||
if (!info.guarded) return runFfmpeg([...formats, ...args]);
|
||||
try {
|
||||
return runFfmpeg([...formats, ...args], undefined, undefined, GUARDED_RUN_MS);
|
||||
|
||||
@@ -5,7 +5,7 @@ import { closeSync, existsSync, mkdirSync, openSync, readSync, rmSync } from "no
|
||||
import { basename, dirname, join, resolve } from "node:path";
|
||||
import { createStagingDir } from "@hyperframes/core/atomic-file";
|
||||
import { renameWithRetry } from "@hyperframes/core/rename-retry";
|
||||
import { mediaInputFormatArgs } from "@hyperframes/parsers/ff-binaries";
|
||||
import { mediaInputArgs } from "@hyperframes/parsers/ff-binaries";
|
||||
import { assertLiteralMediaOutput } from "@hyperframes/parsers/literal-media-input";
|
||||
import { findFFmpeg, findFFprobe, getFFmpegInstallHint } from "../browser/ffmpeg.js";
|
||||
import { recordFolder } from "../utils/projectRecords.js";
|
||||
@@ -68,7 +68,7 @@ export function runFfmpeg(args: string[], input?: Buffer, cwd?: string, timeout?
|
||||
}
|
||||
|
||||
export function ffmpegInput(path: string, { playlists = false } = {}): string[] {
|
||||
return [...mediaInputFormatArgs(ffmpegBin(), path, { playlists }), "-i", path];
|
||||
return [...mediaInputArgs(ffmpegBin(), path, { playlists }), "-i", path];
|
||||
}
|
||||
|
||||
export function ffmpegToFile(args: string[], out: string, input?: Buffer): string {
|
||||
@@ -140,7 +140,7 @@ export function probeSeconds(path: string): number {
|
||||
[
|
||||
"-v",
|
||||
"error",
|
||||
...mediaInputFormatArgs(bin, path),
|
||||
...mediaInputArgs(bin, path),
|
||||
"-show_entries",
|
||||
"format=duration",
|
||||
"-of",
|
||||
@@ -219,7 +219,7 @@ function startsWithMp4Header(path: string): boolean {
|
||||
export function probeVideo(path: string, { guarded = false } = {}): VideoInfo {
|
||||
if (!existsSync(path)) throw new Fix(`no file at ${path}`, missingFileFix(path));
|
||||
const bin = ffprobeBin();
|
||||
const formats = mediaInputFormatArgs(bin, path, { playlists: guarded });
|
||||
const formats = mediaInputArgs(bin, path, { playlists: guarded });
|
||||
let json: { streams?: ProbeStream[]; format?: { duration?: string } };
|
||||
try {
|
||||
json = JSON.parse(
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
type AudioElement,
|
||||
type AudioMetadata,
|
||||
} from "@hyperframes/engine";
|
||||
import { findFfBinary, mediaInputFormatArgs } from "@hyperframes/parsers/ff-binaries";
|
||||
import { findFfBinary, mediaInputArgs } from "@hyperframes/parsers/ff-binaries";
|
||||
import { decodeAudio } from "../audio/analysis/decode.js";
|
||||
import { createProbeGate } from "../timeline/describeProject.js";
|
||||
import { findingAtRoot } from "./checkFindings.js";
|
||||
@@ -73,7 +73,7 @@ async function silentPart(
|
||||
{
|
||||
mono: true,
|
||||
sampleRate: SILENCE_SAMPLE_RATE,
|
||||
inputArgs: mediaInputFormatArgs(findFfBinary("ffmpeg") ?? "ffmpeg", path, {
|
||||
inputArgs: mediaInputArgs(findFfBinary("ffmpeg") ?? "ffmpeg", path, {
|
||||
playlists: true,
|
||||
}),
|
||||
},
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { execFileSync } from "node:child_process";
|
||||
import { mediaInputFormatArgs } from "@hyperframes/parsers/ff-binaries";
|
||||
import { mediaInputArgs } from "@hyperframes/parsers/ff-binaries";
|
||||
import { findFFmpeg, findFFprobe } from "../browser/ffmpeg.js";
|
||||
import { c } from "../ui/colors.js";
|
||||
|
||||
@@ -87,7 +87,7 @@ function probeWebmAlpha(filePath: string): WebmAlphaProbe {
|
||||
"stream=codec_name:stream_tags=alpha_mode",
|
||||
"-of",
|
||||
"json",
|
||||
...mediaInputFormatArgs(ffprobePath, filePath),
|
||||
...mediaInputArgs(ffprobePath, filePath),
|
||||
"--",
|
||||
filePath,
|
||||
],
|
||||
@@ -149,7 +149,7 @@ export function sampledAlphaIsFullyOpaque(filePath: string): boolean | undefined
|
||||
"error",
|
||||
"-c:v",
|
||||
"libvpx-vp9",
|
||||
...mediaInputFormatArgs(ffmpegPath, filePath),
|
||||
...mediaInputArgs(ffmpegPath, filePath),
|
||||
"-i",
|
||||
filePath,
|
||||
"-frames:v",
|
||||
|
||||
@@ -36,7 +36,7 @@ import { parseWhisperJson, type Word } from "./normalize.js";
|
||||
import { emitWords } from "./progress.js";
|
||||
import { probeAudio } from "../audio/analysis/decode.js";
|
||||
import { decodableAudioStream } from "@hyperframes/parsers/media-streams";
|
||||
import { mediaInputFormatArgs } from "@hyperframes/parsers/ff-binaries";
|
||||
import { mediaInputArgs } from "@hyperframes/parsers/ff-binaries";
|
||||
|
||||
export { initialModelForLanguage };
|
||||
|
||||
@@ -185,7 +185,7 @@ export function getMediaDurationSeconds(filePath: string): number | null {
|
||||
"format=duration",
|
||||
"-of",
|
||||
"default=noprint_wrappers=1:nokey=1",
|
||||
...mediaInputFormatArgs(ffprobePath, filePath),
|
||||
...mediaInputArgs(ffprobePath, filePath),
|
||||
"--",
|
||||
filePath,
|
||||
]);
|
||||
@@ -381,7 +381,7 @@ async function extractAudio(videoPath: string, signal?: AbortSignal): Promise<st
|
||||
await runFfmpeg(
|
||||
ffmpegPath,
|
||||
[
|
||||
...mediaInputFormatArgs(ffmpegPath, videoPath),
|
||||
...mediaInputArgs(ffmpegPath, videoPath),
|
||||
"-i",
|
||||
videoPath,
|
||||
"-map",
|
||||
@@ -428,7 +428,7 @@ function isWav16kMono(filePath: string): boolean {
|
||||
"-print_format",
|
||||
"json",
|
||||
"-show_streams",
|
||||
...mediaInputFormatArgs(ffprobePath, filePath),
|
||||
...mediaInputArgs(ffprobePath, filePath),
|
||||
"--",
|
||||
filePath,
|
||||
]);
|
||||
@@ -458,7 +458,7 @@ async function prepareAudio(audioPath: string, signal?: AbortSignal): Promise<st
|
||||
await runFfmpeg(
|
||||
ffmpegPath,
|
||||
[
|
||||
...mediaInputFormatArgs(ffmpegPath, audioPath),
|
||||
...mediaInputArgs(ffmpegPath, audioPath),
|
||||
"-i",
|
||||
audioPath,
|
||||
"-ar",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { execFileSync } from "node:child_process";
|
||||
import { basename, extname } from "node:path";
|
||||
import { mediaInputFormatArgs } from "@hyperframes/parsers/ff-binaries";
|
||||
import { mediaInputArgs } from "@hyperframes/parsers/ff-binaries";
|
||||
|
||||
const IMAGE_EXTENSIONS = new Set([
|
||||
".jpg",
|
||||
@@ -116,7 +116,7 @@ function probeMedia(mediaPath: string, ffprobePath: string): GradeMediaProbe {
|
||||
[
|
||||
"-v",
|
||||
"error",
|
||||
...mediaInputFormatArgs(ffprobePath, mediaPath),
|
||||
...mediaInputArgs(ffprobePath, mediaPath),
|
||||
"-select_streams",
|
||||
"v:0",
|
||||
"-show_entries",
|
||||
@@ -322,7 +322,7 @@ function readSignalStats(
|
||||
"-nostdin",
|
||||
"-v",
|
||||
"error",
|
||||
...mediaInputFormatArgs(ffmpegPath, mediaPath),
|
||||
...mediaInputArgs(ffmpegPath, mediaPath),
|
||||
...keyframeSeek,
|
||||
"-i",
|
||||
mediaPath,
|
||||
|
||||
@@ -3,7 +3,7 @@ import { redactUrlQueryStrings } from "@hyperframes/core";
|
||||
import {
|
||||
SELF_CONTAINED_FORMATS,
|
||||
assertLiteralMediaInput,
|
||||
mediaInputFormatArgs,
|
||||
mediaInputArgs,
|
||||
} from "@hyperframes/parsers/ff-binaries";
|
||||
import { resolveRestrictPageNetwork } from "../config.js";
|
||||
import { getFfmpegBinary, getFfprobeBinary } from "./ffmpegBinaries.js";
|
||||
@@ -68,7 +68,7 @@ export function urlInputArgs(
|
||||
): string[] {
|
||||
assertLiteralMediaInput(input);
|
||||
const mediaFormats = () =>
|
||||
mediaInputFormatArgs(tool === "ffprobe" ? getFfprobeBinary() : getFfmpegBinary(), input, {
|
||||
mediaInputArgs(tool === "ffprobe" ? getFfprobeBinary() : getFfmpegBinary(), input, {
|
||||
playlists: true,
|
||||
});
|
||||
const restricted = resolveRestrictPageNetwork();
|
||||
|
||||
@@ -4,7 +4,7 @@ import { join } from "node:path";
|
||||
import { rewriteAssetPath } from "@hyperframes/parsers/asset-paths";
|
||||
import { parseNumeric } from "@hyperframes/parsers/composition-contract";
|
||||
import { templateContent } from "@hyperframes/parsers/sub-composition-validity";
|
||||
import { findFfBinary, mediaInputFormatArgs } from "@hyperframes/parsers/ff-binaries";
|
||||
import { findFfBinary, mediaInputArgs } from "@hyperframes/parsers/ff-binaries";
|
||||
import {
|
||||
cleanAssetUrl,
|
||||
isRemoteOrInlineUrl,
|
||||
@@ -89,7 +89,7 @@ async function probeIsHevc(ffprobePath: string, filePath: string): Promise<boole
|
||||
const stdout = await execFileAsync(ffprobePath, [
|
||||
"-v",
|
||||
"error",
|
||||
...mediaInputFormatArgs(ffprobePath, filePath),
|
||||
...mediaInputArgs(ffprobePath, filePath),
|
||||
"-select_streams",
|
||||
"v:0",
|
||||
"-show_entries",
|
||||
@@ -247,7 +247,7 @@ async function probePlayableVideoDuration(
|
||||
await execFileAsync(ffprobePath, [
|
||||
"-v",
|
||||
"error",
|
||||
...mediaInputFormatArgs(ffprobePath, filePath),
|
||||
...mediaInputArgs(ffprobePath, filePath),
|
||||
"-select_streams",
|
||||
"v:0",
|
||||
"-show_entries",
|
||||
|
||||
@@ -8,7 +8,7 @@ vi.mock("node:child_process", () => {
|
||||
});
|
||||
vi.mock("@hyperframes/parsers/ff-binaries", () => ({
|
||||
findFfBinary: () => "/fake/bin/ffprobe",
|
||||
mediaInputFormatArgs: () => [],
|
||||
mediaInputArgs: () => [],
|
||||
}));
|
||||
|
||||
import { lintHevcPreviewCodec } from "./hevcPreviewLint.js";
|
||||
|
||||
@@ -525,7 +525,7 @@ describe("mediaInputFormatArgs", () => {
|
||||
vi.resetModules();
|
||||
vi.doUnmock("node:fs");
|
||||
vi.doUnmock("node:child_process");
|
||||
const { findFfBinary, mediaInputFormatArgs } = await importFresh();
|
||||
const { findFfBinary, mediaInputArgs } = await importFresh();
|
||||
const ffmpeg = findFfBinary("ffmpeg");
|
||||
if (!ffmpeg) return;
|
||||
const dir = mkdtempSync(join(tmpdir(), "hf-text-art-"));
|
||||
@@ -533,7 +533,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, note), "-i", note];
|
||||
const args = ["-v", "error", "-y", ...mediaInputArgs(ffmpeg, note), "-i", note];
|
||||
spawnSync(ffmpeg, [...args, "-frames:v", "1", frame]);
|
||||
expect(existsSync(frame)).toBe(false);
|
||||
});
|
||||
@@ -547,7 +547,7 @@ describe("mediaInputFormatArgs", () => {
|
||||
vi.resetModules();
|
||||
vi.doUnmock("node:fs");
|
||||
vi.doUnmock("node:child_process");
|
||||
const { findFfBinary, mediaInputFormatArgs } = await importFresh();
|
||||
const { findFfBinary, mediaInputArgs } = await importFresh();
|
||||
const ffmpeg = findFfBinary("ffmpeg");
|
||||
if (!ffmpeg) return;
|
||||
const dir = realpathSync(mkdtempSync(join(tmpdir(), "hf-playlist-input-")));
|
||||
@@ -576,7 +576,7 @@ describe("mediaInputFormatArgs", () => {
|
||||
writeFileSync(input, "ffconcat version 1.0\nfile inner.m3u8\n");
|
||||
}
|
||||
const out = join(dir, "out.wav");
|
||||
spawnSync(ffmpeg, ["-v", "error", ...mediaInputFormatArgs(ffmpeg, input), "-i", input, out]);
|
||||
spawnSync(ffmpeg, ["-v", "error", ...mediaInputArgs(ffmpeg, input), "-i", input, out]);
|
||||
expect(existsSync(out)).toBe(false);
|
||||
});
|
||||
|
||||
@@ -586,14 +586,21 @@ describe("mediaInputFormatArgs", () => {
|
||||
["concat:/project/a.mp4|/project/b.mp4", true],
|
||||
["https://cdn.example/clip.mp4", false],
|
||||
])("reads %s as a local file only: %s", async (input, local) => {
|
||||
const { _setDemuxerListingForTests, mediaInputFormatArgs } = await importFresh();
|
||||
const { _setDemuxerListingForTests, mediaInputArgs } = await importFresh();
|
||||
_setDemuxerListingForTests(" D mov,mp4,m4a QuickTime / MOV");
|
||||
const args = mediaInputFormatArgs("/ffmpeg", input);
|
||||
const args = mediaInputArgs("/ffmpeg", input);
|
||||
expect(args.slice(0, 2)).toEqual(
|
||||
local ? ["-protocol_whitelist", "file"] : ["-format_whitelist", "mov,mp4,m4a"],
|
||||
);
|
||||
});
|
||||
|
||||
it("is the one -format_whitelist pair a caller reads by position, for a local file too", async () => {
|
||||
const { _setDemuxerListingForTests, mediaInputFormatArgs } = await importFresh();
|
||||
_setDemuxerListingForTests(" D mov,mp4,m4a QuickTime / MOV");
|
||||
const [flag, formats, ...rest] = mediaInputFormatArgs("/ffmpeg", "/project/clip.mp4");
|
||||
expect([flag, formats, rest]).toEqual(["-format_whitelist", "mov,mp4,m4a", []]);
|
||||
});
|
||||
|
||||
it("reads playlists only for a caller that walked the file", async () => {
|
||||
const { _setDemuxerListingForTests, mediaInputFormatArgs } = await importFresh();
|
||||
_setDemuxerListingForTests(
|
||||
@@ -622,13 +629,11 @@ describe("mediaInputFormatArgs", () => {
|
||||
`#!/bin/sh\nif [ -e "${dir}/ran" ]; then echo ' D wav WAV'; else touch "${dir}/ran"; exit 1; fi\n`,
|
||||
);
|
||||
chmodSync(binary, 0o755);
|
||||
const local = ["-protocol_whitelist", "file"];
|
||||
expect(mediaInputFormatArgs(binary, "a.wav")).toEqual([
|
||||
...local,
|
||||
"-format_whitelist",
|
||||
SELF_CONTAINED_FORMATS,
|
||||
]);
|
||||
expect(mediaInputFormatArgs(binary, "a.wav")).toEqual([...local, "-format_whitelist", "wav"]);
|
||||
expect(mediaInputFormatArgs(binary, "a.wav")).toEqual(["-format_whitelist", "wav"]);
|
||||
});
|
||||
|
||||
it("falls back to a list the installed ffprobe reads CAF, W64, WavPack, AU and AC3 with", async () => {
|
||||
|
||||
@@ -347,14 +347,13 @@ export { assertLiteralMediaInput };
|
||||
|
||||
const PLAYLIST_DEMUXERS = new Set(["hls", "applehttp", "concat"]);
|
||||
|
||||
/** 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. Playlists only with `playlists: true`; anything but an http(s) URL reads as a local file. */
|
||||
/** The `-format_whitelist` pair for `input` (no playlists unless `playlists: true`); callers read it by position. */
|
||||
export function mediaInputFormatArgs(
|
||||
listingBinary: string,
|
||||
input: string,
|
||||
{ playlists = false }: { playlists?: boolean } = {},
|
||||
): string[] {
|
||||
assertLiteralMediaInput(input);
|
||||
const local = /^https?:\/\//i.test(input) ? [] : ["-protocol_whitelist", "file"];
|
||||
const allowed = (formats: string) =>
|
||||
playlists
|
||||
? formats
|
||||
@@ -377,10 +376,19 @@ export function mediaInputFormatArgs(
|
||||
} catch {
|
||||
formats = undefined;
|
||||
}
|
||||
if (formats === undefined) return [...local, "-format_whitelist", SELF_CONTAINED_FORMATS];
|
||||
if (formats === undefined) return ["-format_whitelist", SELF_CONTAINED_FORMATS];
|
||||
demuxerLists.set(listingBinary, formats);
|
||||
}
|
||||
return [...local, "-format_whitelist", allowed(formats)];
|
||||
return ["-format_whitelist", allowed(formats)];
|
||||
}
|
||||
|
||||
export function mediaInputArgs(
|
||||
listingBinary: string,
|
||||
input: string,
|
||||
options: { playlists?: boolean } = {},
|
||||
): string[] {
|
||||
const local = /^https?:\/\//i.test(input) ? [] : ["-protocol_whitelist", "file"];
|
||||
return [...local, ...mediaInputFormatArgs(listingBinary, input, options)];
|
||||
}
|
||||
|
||||
const OUT_TIME = /^out_time_(?:us|ms)=(\d+)$/;
|
||||
|
||||
Reference in New Issue
Block a user