Introduction to PCM

作者:罗上文,微信:Loken1,公众号:FFmpeg弦外之音

The raw data of video is YUV; the corresponding raw data for audio is PCM. PCM stands for Pulse Code Modulation. The term can seem abstract, so I think of PCM as the digitization of sound information.

We can decode and extract raw PCM data from juren-10s.mp4 with FFmpeg:

ffmpeg -i juren-10s.mp4 -c:a copy -vn juren-10s.aac
ffmpeg -i juren-10s.aac -ar 48000 -ac 2 -f s16le juren-10s.pcm

1-1

The audio stream is first extracted from the MP4 file and then decoded into raw PCM data. AAC is an encoded and compressed format, so it is much smaller than PCM.

The size of a PCM file is determined by its sample format and sample count.

The FFmpeg options mean:

  • -f specifies the output sample format. s16le means signed 16-bit little-endian, so each sample uses 2 bytes.
  • -ac specifies the number of output channels, here 2. These are the left and right channels: at each instant, one sample is taken from each channel.
  • -ar specifies the sample rate, here 48000, meaning 48,000 samples per second. Audio is sampled much more frequently than video: video is typically sampled 24 times per second, or 24 frames per second.

We now know these three properties, but we still need the sample count to calculate the PCM file size manually. The sample count can be estimated from the sample rate.

This audio is 10 seconds long, so it produces 48,000 samples per second. Since it has two channels:

48000 * 10 * 2 = 960000

Thus juren-10s.pcm contains approximately 960,000 samples. Each sample uses 2 bytes, so the file should be about 1,875 KB, close to the 1,880 KB shown by Windows.


To display a YUV file correctly, we must know its dimensions and sampling format (4:4:4, 4:2:2, or another format). These parameters must be set in 7yuv; incorrect settings produce shifted or corrupted images.

In other words, a YUV file does not store its dimensions or sampling format. If you forget the dimensions, you cannot display it correctly.

PCM is similar. If you forget its sample format, channel count, or sample rate, you cannot play it correctly. We can play juren-10s.pcm with:

ffplay -i -ar 48000 -ac 2 -f s16le juren-10s.pcm

copyright ffmpeg-principle.com loken 2026 all right reserved,powered by Gitbookedit time: 2026-08-16 13:06:13

results matching ""

    No results matching ""