FFmpeg usually detects the input format from the file header, but there are cases where the detection fails: raw streams, network captures, or files with a missing extension. The `-f` flag before the input forces the demuxer to use a specific format, bypassing the auto-detection.

The command

ffmpeg -f s16le -ar 48000 -ac 2 -i raw_audio.pcm out.wav

What it does

The command tells FFmpeg to treat the input as raw 16-bit signed little-endian PCM, 48 kHz, stereo. The `raw_audio.pcm` filename has no extension, so auto-detection would fail. The output is a normal WAV file. The same pattern works for raw video: `ffmpeg -f rawvideo -pixel_format yuv420p -video_size 1920x1080 -framerate 30 -i raw.yuv out.mp4`.

Requirements

A muxer built into FFmpeg and codecs compatible with the muxer. The flag is a no-op if the muxer does not support the codec. The container is written as specified, regardless of the filename extension. The flag is most useful for piped inputs from a network service or a custom capture device.

Things to avoid

  • Using `-f` to force a format that does not match the file. The demuxer will read the file as the specified format, but the decoder will fail or produce garbage. Always check the file's actual format with `ffprobe` first.
  • Confusing the muxer (`-f` before the output) with the demuxer (`-f` before the input). They are different flags, used in different positions.
  • Forgetting the format-specific parameters. Raw PCM needs `-ar`, `-ac`, and the sample format; raw video needs `-pixel_format`, `-video_size`, and `-framerate`. Without them, the demuxer cannot interpret the data.
  • Relying on auto-detection for non-standard files. If the file is a custom format, auto-detection will fail, and the command will fail with 'Format ... not detected'. Use `-f` to force the demuxer.