Change PCM Endianness with FFmpeg

This article explains how to change the byte order (endianness) of a raw PCM audio file using FFmpeg. Since raw PCM files do not contain header metadata, you must explicitly define the input audio properties—such as sample rate, channel count, and format—before converting the stream to your desired target endianness.

To convert a raw PCM file from little-endian to big-endian, use the following FFmpeg command:

ffmpeg -f s16le -ar 44100 -ac 2 -i input.pcm -f s16be -c:a pcm_s16be output.pcm

To convert a raw PCM file from big-endian to little-endian, reverse the format parameters:

ffmpeg -f s16be -ar 44100 -ac 2 -i input.pcm -f s16le -c:a pcm_s16le output.pcm

Command Breakdown

  • -f s16le (or -f s16be): Defines the input format. Raw PCM has no headers, so you must tell FFmpeg how to read the input file. s16le stands for signed 16-bit little-endian, while s16be stands for signed 16-bit big-endian.
  • -ar 44100: Sets the audio sample rate of the input file to 44100 Hz (adjust this value to match your source file's actual sample rate).
  • -ac 2: Sets the number of audio channels to 2 (stereo). Use 1 for mono.
  • -i input.pcm: Specifies the path to the input raw PCM file.
  • -f s16be (or -f s16le): Specifies the container format for the output file.
  • -c:a pcm_s16be (or -c:a pcm_s16le): Sets the audio codec for the output file, forcing FFmpeg to write the audio data in the requested endianness.
  • output.pcm: Specifies the path for the converted output file.