import "server-only";

import { getMediaProcessingConfig } from "@/lib/server/media-config";
import { runBinaryCommand, type CommandExecutionResult } from "@/lib/ffmpeg/run-command";

interface RunFfmpegOptions {
  timeoutMs?: number;
  cwd?: string;
}

export async function runFfmpeg(args: string[], options: RunFfmpegOptions = {}) {
  const config = getMediaProcessingConfig();
  return runBinaryCommand(config.ffmpegPath, args, options);
}

export async function runFfmpegAndExpectFile(
  args: string[],
  outputPath: string,
  options: RunFfmpegOptions = {}
): Promise<CommandExecutionResult & { outputPath: string }> {
  const result = await runFfmpeg(args, options);
  return {
    ...result,
    outputPath
  };
}
