{"record":{"id":"27e1f375f1a22c4e","repo":"MiniMax-AI/skills","slug":"error-o-output-only-works-with-a-single-input","errorCode":null,"errorMessage":"ERROR: -o/--output only works with a single input file","messagePattern":"ERROR: -o/--output only works with a single input file","errorType":"exception","errorClass":"SystemExit","httpStatus":null,"severity":"warning","filePath":"skills/gif-sticker-maker/scripts/convert_mp4_to_gif.py","lineNumber":69,"sourceCode":"    finally:\n        if os.path.exists(palette):\n            os.remove(palette)\n\n    size = os.path.getsize(output_path)\n    print(f\"OK: {size:,} bytes -> {output_path}\")\n    return True\n\n\ndef main():\n    p = argparse.ArgumentParser(description=\"Batch MP4 → GIF converter (ffmpeg two-pass palette)\")\n    p.add_argument(\"inputs\", nargs=\"+\", help=\"MP4 file(s) to convert\")\n    p.add_argument(\"-o\", \"--output\", default=None, help=\"Output path (only for single file input)\")\n    p.add_argument(\"--fps\", type=int, default=15, help=\"GIF frame rate (default: 15)\")\n    p.add_argument(\"--width\", type=int, default=360, help=\"GIF width in pixels, height auto-scaled (default: 360)\")\n    args = p.parse_args()\n\n    if args.output and len(args.inputs) > 1:\n        raise SystemExit(\"ERROR: -o/--output only works with a single input file\")\n\n    check_ffmpeg()\n\n    ok, fail = 0, 0\n    for mp4 in args.inputs:\n        if args.output:\n            gif_path = args.output\n        else:\n            gif_path = os.path.splitext(mp4)[0] + \".gif\"\n\n        if mp4_to_gif(mp4, gif_path, fps=args.fps, width=args.width):\n            ok += 1\n        else:\n            fail += 1\n\n    print(f\"\\nDone: {ok} converted, {fail} failed\")\n\n","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/MiniMax-AI/skills/blob/60aaae52bb2af8162732751a4332f62a5fef518b/skills/gif-sticker-maker/scripts/convert_mp4_to_gif.py#L51-L87","documentation":"Argument-validation guard in main(): the user passed -o/--output (a single destination path) together with more than one input file. The script derives per-input output names when batching, so an explicit -o is only meaningful for exactly one input; it refuses rather than silently overwriting one file for all inputs.","triggerScenarios":"Invoking the converter with multiple inputs and -o, e.g. `convert_mp4_to_gif.py a.mp4 b.mp4 -o out.gif` — there is no unambiguous single output for two inputs.","commonSituations":"Glob expansion (`*.mp4 -o out.gif`) producing multiple files while a single -o was intended; copy-pasting a single-file example then adding more inputs; scripting a batch but leaving a stale -o flag.","solutions":["Drop -o for batch runs so each input gets a sibling .gif (input.mp4 -> input.gif): `convert_mp4_to_gif.py a.mp4 b.mp4`.","If you need custom names for many files, loop and call the converter once per file with its own -o.","If you truly want one output, pass exactly one input with -o: `convert_mp4_to_gif.py single.mp4 -o out.gif`."],"exampleFix":"// before\n$ python convert_mp4_to_gif.py *.mp4 -o out.gif\nERROR: -o/--output only works with a single input file\n\n// after (batch, auto-named)\n$ python convert_mp4_to_gif.py *.mp4\n// after (single, custom name)\n$ python convert_mp4_to_gif.py single.mp4 -o out.gif","handlingStrategy":"validation","validationCode":"def plan_outputs(inputs, output=None):\n    \"\"\"Return a list of (input, output) pairs, enforcing the single-output rule.\"\"\"\n    if output and len(inputs) > 1:\n        raise ValueError(\"-o/--output is only valid with exactly one input file\")\n    return [(i, output if output else os.path.splitext(i)[0] + \".gif\") for i in inputs]","typeGuard":"def is_single_output_safe(inputs: list, output) -> bool:\n    \"\"\"True when -o may be used: exactly one input, or no -o at all.\"\"\"\n    return output is None or len(inputs) == 1","tryCatchPattern":"import subprocess, sys\nr = subprocess.run([sys.executable, \"convert_mp4_to_gif.py\", *inputs, \"-o\", out], capture_output=True, text=True)\nif r.returncode != 0 and \"only works with a single input file\" in (r.stderr or r.stdout or \"\"):\n    # drop -o and let each input get an auto-named .gif\n    subprocess.run([sys.executable, \"convert_mp4_to_gif.py\", *inputs], check=True)\nelse:\n    r.check_returncode()","preventionTips":["For batch/glob runs, omit -o so each input becomes a sibling .gif.","When you need custom names for several files, loop one invocation per file with its own -o.","Validate `len(inputs) == 1 or output is None` in any wrapper before forwarding args.","Beware shell glob expansion (`*.mp4`) silently turning a single-input command into a batch."],"tags":["cli","arguments","validation","python","gif"],"backgroundTag":null,"analyzedSha":"60aaae52bb2af8162732751a4332f62a5fef518b","analyzedAt":"2026-08-13T17:32:34.717Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}