From Derivative
Jump to: navigation, search

The Hap and Hap Q codecs are supported in the Movie File In TOP, and the Movie File Out TOP encodes to both codecs as well. It is also used in the video-over-IP operators Touch Out TOP and Touch In TOP.

Hap is a video codec that performs decompression using a computer's graphics hardware, substantially reducing the CPU usage necessary to play video. It allows for playback of higher resolution and/or frame rate videos than any other codec we know of. It also allows for playback many more streams of lower resolution video than other codecs, assuming you have the drive speed for it.

There are three different Hap codecs: Hap, Hap Alpha, and Hap Q.

  • Hap has the lowest data-rate and low image quality.
  • Hap Alpha has identical image quality to Hap, and supports an Alpha channel. The size of a Hap Alpha file will be twice the size of a Hap file.
  • Hap Q has much improved image quality, but no alpha channel. The size of a Hap Q file will be approximately twice the size of a Hap file.
  • Hap Q Alpha has identical image quality as Hap Q, but also includes an Alpha channel.

Hap Q image quality is very high and is a great choice for projects playing very high resolution video. Since the files have a high data rate the main bottleneck you will often hit is SSD read speed.

Compression Ratio and Data Rates

The Hap codec is a two stage compression. The first stage is the texture compression that is a constant compression. The second stage is a CPU compression that is variable depending on the content. On noisy/busy content the CPU stage may offer no compression at all.

Data rates of Hap video is guaranteed to not be worse than:

  • Hap = 0.5 bytes per pixel/4-bits per pixel. 6:1 compression compared to uncompressed RGB video.
  • Hap Alpha = 1 byte per pixel/8-bits per pixel. 4:1 compression compared to uncompressed RGBA video.
  • Hap Q = 1 byte per pixel/8-bits per pixel. 3:1 compression compared to uncompressed RGB video.
  • Hap Q Alpha 1.5 bytes per pixel/12-bits per pixel. 2.6:1 compression compared to uncompressed RGBA video.

So for a 4096x2160@60hz video, that is 530,841,600 pixels per second. The worst case data rate will be:

  • Hap = 265,420,800 Bytes/second
  • Hap Alpha = 530,841,600 Bytes/second
  • Hap Q = 530,841,600 Bytes/second
  • Hap Q Alpha = 796,262,400 Bytes/second.

TouchDesigner supports the decoding and encoding of all forms of the codec.

The QuickTime plugin (not required for HAP support in TouchDesigner, but useful for external encoding or testing) can be found here.

Its specification and sample code can be found at the github location: Hap video codec

Working with High Resolution or High FPS Video

Hap Q is the best codec choice when ultra high resolution or FPS video is required. However the videos must be encoded properly to allow for multi-threaded CPU decoding. This is called 'Chunked' encoding in the Hap standard. The Movie File Out TOP always encodes using chunked encoding. Chunked encoding can also be done using the latest version of FFmpeg. This can be done using the -chunks option. For example

 ffmpeg -i source.mov -c:v hap -format hap_q -chunks 12 dest.mov

Each chunk can utilize a different CPU to be decoded, so chunks equal or greater than the number of CPUs cores on the system (not including hyper-threading cores), will be best. Having more chunks than CPUs core should not affect performance, but ideally the number of chunks is kept within a reasonable amount. When TouchDesigner encodes it uses 12 chunks.

Note: The QuickTime plugin does not currently encode using chunked encoding.

The width and height of an image in pixels. Most TOPs, like the Movie File In TOP can set the image resolution. See Aspect Ratio for the width/height ratio of an image, taking into account non-square pixels.

An Operator Family that creates, composites and modifies images, and reads/writes images and movies to/from files and the network. TOPs run on the graphics card's GPU.