日本語

Fixing FFmpeg “Unable to choose an output format” When the Output Name Has No Extension

​​FFmpeg​command line,shell script,Troubleshooting

If you write an output filename without an extension, such as out, FFmpeg stops with "Unable to choose an output format for 'out'" and does not create the file. Adding an extension such as .mp4 to the output name, or putting -f mp4 before the output name to specify the format, makes the error go away. You run into this error when the extension is left out, for example when copying a video without re-encoding (-c copy) or when a shell script builds filenames from variables for batch conversion.

Note

The test environment was Ubuntu 24.04.5 with FFmpeg 6.1.1 (Ubuntu package 7:6.1.1-3ubuntu5). The input was a 5-second MP4 (H.264 and AAC) made with FFmpeg's testsrc and sine sources. I did not test Windows or macOS builds, or FFmpeg 7 and later.

The command that caused the error and the messages it printed

I wrote the input in.mp4 to a file named out with no extension, without re-encoding (-c copy).

bash
ffmpeg -hide_banner -y -i in.mp4 -c copy out

After the input information was printed, these four lines appeared and FFmpeg stopped (the 0x... values change on each run).

text
[AVFormatContext @ 0x55b37237af00] Unable to choose an output format for 'out'; use a standard extension for the filename or specify the format manually.
[out#0 @ 0x55b3722aadc0] Error initializing the muxer for out: Invalid argument
Error opening output file out.
Error opening output files: Invalid argument

The exit code was 234, and no file named out was created. The first line means "the output format cannot be chosen; use a standard extension for the filename or specify the format manually." The fix is written in the message itself.

Cause: The output format is determined by the extension

The -f section of the ffmpeg documentation says that the format is detected automatically for input files, and for output files it is guessed from the file extension. So when -f is not given, the output format is determined only by the extension of the filename.

In libavformat/format.c in FFmpeg 6.1.1, the code takes the part after the last . in the filename as the extension and compares it with the list of extensions each format (muxer) declares. When -f is not given and no format matches the extension, libavformat/mux.c prints this message.

Besides names with no extension, I found other names that produce the same message.

Output name Result
out Error
out. (ends with just a dot) Error
out.xyz (extension FFmpeg does not know) Error
- (standard output) Error (shown as 'pipe:')
out.mp4 Success
OUT.MP4 (uppercase) Success

Even with an uppercase .MP4, the file was written as MP4. This is because the extension comparison ignores case (av_match_name in libavutil/avstring.c uses av_strncasecmp).

In a shell script, if the variable holding the extension is empty and the name is built like "clip_01${ext}", FFmpeg receives clip_01, which causes the same error.

text
[AVFormatContext @ 0x55dbf53bff00] Unable to choose an output format for 'clip_01'; use a standard extension for the filename or specify the format manually.

Fix 1: Add an extension to the output name

The simplest fix is to add the extension for the format you want.

bash
ffmpeg -hide_banner -y -i in.mp4 -c copy out.mp4

The file was written with exit code 0, and the output information was printed as follows. The "Unable to choose" line did not appear.

text
Output #0, mp4, to 'out.mp4':
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)

You can check which extension maps to which format with -h muxer=format_name.

bash
ffmpeg -hide_banner -h muxer=matroska | head -4
text
Muxer matroska [Matroska]:
    Common extensions: mkv.
    Mime type: video/x-matroska.
    Default video codec: h264.

If you add an extension listed on the Common extensions line (mkv for Matroska), the file is written in that format. In the test environment, writing out.mkv produced a file that ffprobe read as matroska,webm. You can see the list of format names FFmpeg can write with ffmpeg -muxers.

Fix 2: Specify the format with -f

If you cannot change the filename, specify the format with -f. Put -f before the output name.

bash
ffmpeg -hide_banner -y -i in.mp4 -c copy -f mp4 out_f

The command finished with exit code 0 and printed Output #0, mp4, to 'out_f':. The resulting out_f still has no extension, but ffprobe read it as mov,mp4,m4a,3gp,3g2,mj2, and the file command identified it as ISO Media, MP4 Base Media v1.

The value given to -f is not an extension. It is a format name listed by ffmpeg -muxers. For example, for Matroska, write -f matroska, not -f mkv. Specifying a name that is not in the list, such as -f mkv, produced a different message.

text
[AVFormatContext @ 0x56048a52eec0] Requested output format 'mkv' is not known.
Warning

When I placed -f mp4 after the output name, the format was not specified, and I got the same "Unable to choose an output format for 'out'" error. With the default log level, FFmpeg also prints a warning before this error: "Trailing option(s) found in the command: may be ignored." As described at the beginning of the ffmpeg documentation, options apply to the file written after them, so an -f placed after the output name does not apply to any file.

When writing to standard output, -f is required

If you set the output name to -, FFmpeg writes to standard output. In fftools/ffmpeg_mux_init.c in FFmpeg 6.1.1, - is replaced with pipe:. As described in the pipe protocol documentation, pipe: without a number refers to standard output when writing. Because the name has no extension, the same error about 'pipe:' appeared when -f was not given.

Adding -f matroska let the file be written with exit code 0.

bash
ffmpeg -v error -y -i in.mp4 -c copy -f matroska - > out2

On the other hand, writing to standard output with -f mp4 stopped with a different error.

text
[mp4 @ 0x55ac2ac95ec0] muxer does not support non seekable output

The pipe protocol documentation also says that some formats, such as MOV, need the output to be seekable (able to move the write position back), and that they fail with a pipe. In libavformat/movenc.c in FFmpeg 6.1.1, this error is raised for non-seekable output unless the MP4 is fragmented. In the test environment, adding -movflags frag_keyframe+empty_moov to produce a fragmented MP4 let the file be written with exit code 0, and ffprobe read it as an MP4.

bash
ffmpeg -v error -y -i in.mp4 -c copy -movflags frag_keyframe+empty_moov -f mp4 - > out3

If you want to test the processing without creating a file, write -f null -. null is a format that writes nothing, and it also finished with exit code 0 in the test environment.

​Posted by 86