Recoding AVCHD
 
Support Ukraine

Recoding AVCHD

The Panasonic TZ7 has many good sides, but in one particular point it falls down hard: The way it encodes AVCHD files.

A video stream consists of individual frames that in turn can contain three types of frame data:

  1. I: Intra-coded data. This is data that is stand-alone.

  2. P: Predictive-coded data. This is data that references previous frames. "I'm just like that frame before me, with these changes."

  3. B: Bidirectional-coded data. This is data that references previous and following frames. "I'm just like that frame before me, with these changes, combined with that frame you have decoded but not shown yet, with these changes."

So a video stream can look like this, for example: IBBPBBPBBIBBPBBPBBI...

I-frames, frames containing nothing but I-coded data, are also known as keyframes and, since they can be decoded and shown without having to decode any other frames, are typically the only points that can be fast-forwarded to, or in general, the only frames from which the video clip can be random-accessed. They are also the only frames where the video stream can be cut without re-encoding parts or all of it.

So what does a TZ7 AVCHD-coded movie look like? Well: IPPPPPPPPPPP... That is, a single I-frame followed by nothing but P frames. What does that mean? Most important, it means that you can't trim the start of a clip without recoding it. Why is that a problem? Because recoding means loss of data and takes time. To add insult to injury, it is usually the start of the clip that is in most need of trimming - that's when you keep the camera running just so you don't miss something. Once that something has happened, turning off the camera is easy.

Recoding with FFmpeg

FFmpeg is pretty much the Swiss Army knife for manipulation of video files. I took a typical clip and recoded it with different parameters. The error below is the per-frame sum-of-squares of individual pixel errors introduced by the recoding. Each pixel is stored as a triplet of values [0..1), and the reference frame is subtracted from the recoded frame. In the resulting error frame, all values are component-wise squared and summed. The average error is the average of all error values across all frames (n = 100), and the standard deviation is the standard deviation for the 100 error values.

Error measures for various encoder settings. [Expand]
Codec Mbps Quality Size (MB) Average Std. Dev. Speed
TZ7 AVCHD17SH36.70.00.0-
x26448intra + lossless_ultrafast168.30.00.0Fast
x26448intra + default76.858.76.4Medium
x26448intra + normal77.760.26.4Fast
x26424max60.471.711.5Slow
x26424hq60.376.114.0Medium
x26416hq40.3135.430.8Medium
x26424intra + max43.4154.126.7Medium
x26414max35.3152.636.5Slow
x26414hq35.3161.740.2Medium
mpeg414sameq32.9243.723.4Fast
mjpeg48-b 48M53.5249.418.9Fast
mjpeg27sameq64.5275.311.1Fast
x26414intra + max26.1312.548.8Medium

Analysis

First, codecs rule. Second, bit rate rules. We can see that the h264 codec really does improve on the mpeg4 and mjpeg codecs.

2010-01-13, updated 2014-11-15