Chapters

Media Compression Mechanics: Audio, Image, and Video — Part 2

media-compression
data
audio-video
Listen
Uses your device's voice. Tap ▶ beside any paragraph to hear just that one.
  • Podcast audio coming soon
  • Character narration audio coming soon
Lecture
Video lecture coming soon. The slides are the lecture for now.
Ask AI
Pick a prompt. We copy it for you and open an AI service; paste it there. Nothing is sent to IoTClass.

This is part 2 of 2. Begin with Part 1.

3.1 Under the Hood: Predict Motion, Then Code the Error

Video adds a second source of redundancy: a block in the current frame often resembles a shifted block in a reference frame. A block matcher searches a bounded window for the candidate that minimizes a distortion measure. With sum of absolute differences (SAD):

SAD⁡(Δx,Δy)=∑i=0N−1∑j=0N−1∣T(i,j)−R(i+Δx,j+Δy)∣.\operatorname{SAD}(\Delta x,\Delta y)=\sum_{i=0}^{N-1}\sum_{j=0}^{N-1}\left|T(i,j)-R(i+\Delta x,j+\Delta y)\right|.

TT is the target block and RR is the reference frame indexed relative to the target block’s origin. For a target block at frame position (x0,y0)(x_0,y_0), R(i+Δx,j+Δy)R(i+\Delta x,j+\Delta y) reads the reference sample at frame coordinates (x0+i+Δx,y0+j+Δy)(x_0+i+\Delta x,y_0+j+\Delta y). The selected displacement (Δx,Δy)(\Delta x,\Delta y) becomes a motion vector. Copying the matching reference block into the target position gives a prediction PP; subtracting it from the target gives the residual:

E(i,j)=T(i,j)−P(i,j).E(i,j)=T(i,j)-P(i,j).

Suppose an IoT camera has a 2×22\times2 target patch T=[100102104106]T=\begin{bmatrix}100&102\\104&106\end{bmatrix} digital levels and tests two non-overlapping reference candidates. At displacement (0,0)(0,0) pixels, P0=[959799101]P_0=\begin{bmatrix}95&97\\99&101\end{bmatrix} levels, so SAD is 5+5+5+5=205+5+5+5=20 levels summed over four samples. At (2,0)(2,0) pixels, P1=[100101105106]P_1=\begin{bmatrix}100&101\\105&106\end{bmatrix} levels, so SAD is 0+1+1+0=20+1+1+0=2 levels summed over four samples. Among these candidates, select (2,0)(2,0) pixels because 2<202<20. Subtract each predicted sample: E=[100−100102−101104−105106−106]=[01−10]E=\begin{bmatrix}100-100&102-101\\104-105&106-106\end{bmatrix}=\begin{bmatrix}0&1\\-1&0\end{bmatrix} levels. Check before lossy residual quantization: P1+E=[100+0101+1105−1106+0]=[100102104106]=TP_1+E=\begin{bmatrix}100+0&101+1\\105-1&106+0\end{bmatrix}=\begin{bmatrix}100&102\\104&106\end{bmatrix}=T levels.

If the prediction is good, EE has smaller magnitudes and less structure than TT. The encoder sends motion information plus a transformed, quantized, and entropy-coded residual. The decoder applies the same motion vector to its reference frame, decodes the residual, and adds the two. Prediction has changed what the transform must describe; it has not replaced the transform.

A target block is compared with three reference candidates. Candidate A has the lowest SAD. Its prediction plus the signed residual reconstructs the target in this example.
Figure 3.1: Motion search and reconstruction using the worked example below.

Follow Figure 3.1 from the target block to the three candidate blocks in the reference window. For each candidate, subtract its samples from the matching target samples, take absolute values, and add them. A has the smallest sum, so its displacement supplies the motion vector and its samples supply the prediction. Keep the signs when forming the residual. A negative entry means the prediction was too high. In reconstruction, the decoder fetches the same prediction and adds the decoded residual. The panels show exact recovery if the decoded residual equals the original. Quantization can change residual samples, so a decoded block may differ from the target.

3.1.1 A Worked Decision: When the Residual Stops Being Cheap

A production encoder compares candidate modes; “inter” is not automatically cheaper merely because a previous frame exists.

  1. Data Dora compares one target image block with its best reference block from an earlier frame.

    Compare a target block with its best earlier-frame prediction.

  2. Dora subtracts them into a sparse difference grid with five small nonzero cells.

    Count how many difference samples remain and how large they are.

  3. Dora compares measured predicted-block and self-contained-block cost, choosing only the cheaper candidate without a universal winner badge.

    Choose the cheaper tested mode; an earlier frame does not guarantee a saving.

Suppose a 4×44\times4 target block differs from its best reference candidate by these signed sample values:

The first panel compares a target block with its best candidate from an earlier frame. The second shows their difference: only five of sixteen residual samples are non-zero, and every magnitude is one. The matrix below gives the signed values. This prediction is a strong transform input. The last panel compares the cost of the predicted block with an intra-coded block. If a scene cut makes most residual magnitudes large, the motion vector plus residual can cost more than intra coding.

E=[00100−1100000100−1].E= \begin{bmatrix} 0&0&1&0\\ 0&-1&1&0\\ 0&0&0&0\\ 1&0&0&-1 \end{bmatrix}.
  1. Take reference candidates A, B, and C at displacements (0,0)(0,0), (4,0)(4,0), and (−4,0)(-4,0) from the target position. Start with target TT and candidate A.

    T=[1234134423432332],A=[1224143423431333].T=\begin{bmatrix}1&2&3&4\\1&3&4&4\\2&3&4&3\\2&3&3&2\end{bmatrix},\qquad A=\begin{bmatrix}1&2&2&4\\1&4&3&4\\2&3&4&3\\1&3&3&3\end{bmatrix}.

  2. Subtract A from TT sample by sample. This gives the residual matrix above. Five absolute differences are 1 and the rest are 0, so SAD⁡A=5\operatorname{SAD}_A=5. The mean absolute error is 5/16=0.31255/16=0.3125.

  3. Candidate B has the same samples as A except that row 1, column 1 and row 3, column 2 are each one greater. Both positions matched the target for A. Each change adds 1 to the sum, so SAD⁡B=5+1+1=7\operatorname{SAD}_B=5+1+1=7.

  4. Candidate C has the same samples as B except that row 3, column 1 is one greater. That position also matched for B, so SAD⁡C=7+1=8\operatorname{SAD}_C=7+1=8. A wins the SAD search because 5<7<85<7<8.

Data Encoding and Codecs owns the higher-level I/P/B-frame and GOP policy decision. This chapter supplies the lower mechanism: references produce predictions, predictions produce residuals, and residuals still traverse transform, quantization, and lossless packing. Real-Time Protocol Workflows owns the RTP/RTCP hand-off shown at the source diagram’s boundary; it is not re-taught here.

SAD ranks predictions during the search. To compare coded choices, an encoder can score each decoded reconstruction with J=D+λRJ=D+\lambda R. Here DD is the sum of squared differences between original and reconstructed samples, RR is the total number of bits for the choice (including mode, motion information, and residual), and λ\lambda is the distortion cost assigned to each additional bit. Choose the lower JJ.

  1. Reuse candidates A and B. For this example, suppose both coded choices decode to an all-zero residual. The reconstructed block for each choice is then its prediction. A has five errors of magnitude 1, so DA=5×12=5D_A=5\times1^2=5. B has seven, so DB=7×12=7D_B=7\times1^2=7.
  2. Suppose the coded totals are RA=8R_A=8 bits and RB=5R_B=5 bits, including any difference in motion-vector coding cost. Set λ=1\lambda=1 distortion unit per bit. Then JA=5+1×8=13J_A=5+1\times8=13 and JB=7+1×5=12J_B=7+1\times5=12.
  3. B wins this comparison. It has 2 more units of distortion and saves 3 bits. The coded totals are illustrative. Real totals and decoded residuals depend on the coding choices.

3.1.2 Read Source Rate Ranges as Evidence, Not Targets

The source’s final retained slide compares raw rates with example compressed ranges. These are lecture-era examples, not current codec recommendations. Their value is the scale of the mechanism’s payoff and the reminder that content and encoder settings control the result.

Media
Raw example
Source compressed range
Derived reduction
Wideband audio
224 kbps
8-12 kbps
about 19-28 times
CD audio
1.41 Mbps
64-256 kbps
about 5.5-22 times
Still image
3.14 MB
Rejected: slide prints 30-300 MB
No honest ratio from an internally inconsistent unit
720p raw video
530 Mbps
0.768-1.536 Mbps
about 345-690 times

Do not silently repair source data. The still-image row's printed compressed range is larger than its raw image and is labelled MBytes, so it fails its own compression claim. It may have intended kBytes, but this chapter does not guess. A product record should instead measure the actual images, encoder, quality setting, and decoder path.

3.2 Summary

Psychoacoustic masking raises the hearing threshold in a way that depends on the sound. An audio coder can place some error below that threshold, where it is less audible. For images, an 8×88\times8 DCT turns a block into one DC and 63 AC spatial-frequency coefficients. Quantization creates high-frequency zeros. JPEG zig-zag order groups those zeros for run-length and entropy coding. For video, motion estimation selects a shift in a reference frame. Motion compensation builds a predicted block, and the residual keeps what the prediction missed.

Each saving has a cost. Error can exceed a perceptual threshold, and quantization discards detail. A poor motion predictor can cost more than an intra-coded block. Compression ranges depend on the content and settings used to measure them; they are not fixed traits of a codec. If source units contradict a claimed reduction, reject the comparison instead of guessing a correction.

3.3 Key Takeaway

A perceptual threshold can hide some audio error. A transform can concentrate image energy, and a reference frame can predict video content. For each saving, state the mechanism, the error it adds, and the evidence that the intended receiver can still use the result.

3.4 See Also

Use Data Encoding and Codecs to step outward from transform and prediction mechanics to containers, GOP structure, and codec selection. Choose Voice Compression and Digital Telephony when the open question is speech coding, latency, header budget, or measured call quality. Audio Features for Machine Learning follows a different branch: its time-frequency representation supports classification rather than reconstructable playback. Finally, VoIP Client Architecture places these media operations inside the signaling, processing, packet, and device responsibilities of a complete calling product.

Together, these routes separate three questions that should not be collapsed: how a representation saves bits, how the resulting payload behaves on a real-time path, and which product component owns each failure and item of evidence.

Hi, I’m Broker Bex. What do you need?

Find help

Let’s find what you need

Find a lesson or return to your module guide.

Give feedback

Help improve this chapter

Tell us what helped or what needs fixing.

Tips

Try a small next step

A few ways to get more from this chapter.

Ask AI

Continue the conversation

Take the conversation further with your preferred assistant.

AI help is available in supported modules when enabled in Settings.

No live person answers on independent study. Feedback does not promise a personal reply.

For welfare or safety concerns, follow your school’s procedures outside IoTClass.