An H.264 encoder works in macroblocks of 16 × 16 pixels. A 1920 × 1080 picture is coded as 120 × 68 of them, 8,160 per picture, so 1080p30 needs 244,800 macroblocks per second. An FPGA encoder reaches that rate with a faster clock, with more engines, or with both. IronH264 runs on two of our boards that take different routes, and the measurements show the trade.
One engine: the clock sets the rate
On the Zybo Z7-20 the encoder is one engine with a 64-bit AXI master, fed by a Pcam 5C camera at 30 frames/s. We measured it at two encoder clocks, at QP 28.
| Encoder clock | Pictures | Picture rate | H.264 bit rate |
|---|---|---|---|
| 90 MHz | 1,800 of 1,800 | 23.50 pictures/s | 14.63 Mb/s |
| 121.85 MHz | 1,800 of 1,800 | 30.00 pictures/s | 20.45 Mb/s |
At 90 MHz the engine codes 23.50 pictures a second, which works out to about 470 clocks per macroblock for that scene. Scaling the clock to 121.85 MHz at the same cost per macroblock gives a little under 32 pictures a second, enough to keep up with the camera. The measured stream confirms it: 30.00 pictures/s, a median picture interval of 33.333 ms and a longest interval of 33.722 ms.
The bit rates differ because the slower run codes fewer pictures per second, not because the pictures are coded differently.
Two engines: when the clock has no room
The Nexys Video's Artix-7 XC7A200T-1 closes the same encoder at 90 MHz, and the routed image has +0.156 ns of setup slack, so there is little clock left to take. The second route is a second engine. The engines divide the picture into horizontal bands and code them at the same time. Two engines at 90 MHz held 1080p30 for ten minutes: 18,002 pictures, none dropped, minimum PSNR 44.28 dB at QP 28.
IronH264 supports one to four engines. The slice count has to be a multiple of the engine count, because each band is at least one slice.
What the second engine costs
More engines cost logic, and they cost a little compression. Prediction does not cross a slice boundary, so the macroblocks along each band edge code less efficiently than they would in one slice. On a 68-row picture split into two bands the effect is small. With four bands it is larger, which is a reason to prefer the faster clock when the device allows it.
The complete Nexys Video image, with the MicroBlaze V processor, DDR controller, Ethernet and two encoder engines, uses 94,557 LUTs, 89,000 flip-flops, 292.5 block RAM tiles and 84 DSPs. That is about 70% of the XC7A200T's LUTs and 80% of its block RAM.
Memory is the third limit
The clock and the engine count set what the encoder can compute. DDR sets what it can be fed. Each picture is read once as source, the previous reconstructed picture is read for motion search, and the new reconstruction is written back. On the Zybo the encoder has its own high-performance port, the camera writes on another and the display reads on a third, so the three do not queue behind each other. The specification's wording is worth repeating: picture rate depends on content, engine count, encoder clock, QP and memory service.
Sizing a design
- Start from the macroblock rate: width and height in macroblocks, times the frame rate. 720p30 is 80 × 45 × 30, or 108,000 per second, less than half of 1080p30.
- Find the encoder clock the device closes with the rest of the design in place. A Zynq-7020 reached 121.85 MHz; a −1 Artix-7 reached 90 MHz.
- If one engine at that clock falls short, add an engine before reducing the picture.
- Give the encoder its own memory port where the device has one.
The prebuilt Nexys Video bitstream on the IronH264 page runs the two-engine configuration, and show encoder on its console prints the picture counts and the drops.