High bit-depth Support with Avisynth
Currently, Avisynth only supports 8-bit video. Nevertheless, through various utilities, plugins, and scripts, Avisynth can be used to import, process, and export high bit-depth video. There has been some effort to update Avisynth itself to support high bit-depth, but there has been no progress as of 2012 (http://forum.doom9.org/showthread.php?t=162436).
What is Deep Color?
Deep Color refers to using more than 8 bits of data to represent each color channel. It is also referred to as high bit-depth color. Basically, deep color allows finer graduations of color, smoother gradients and more detail. Please refer to this short, easy to understand article: PCWorld: What is 10-bit Color?
Why Use Deep Color?
- Higher internal precision, using high-bit depth color, when processing an image in a filter, gives a higher quality (8-bit) output.
- If a video filter uses linear gamma internally, there can be noticeable differences in the image. A linear gamma representation is best supported with a high bit-depth. See the illustration for ResampleHQ.
- If you encode high-bit depth video, you can get better compression (reportedly up to 30%) and less banding.
- Banding is one of the most serious liabilities of 8-bit depth. Refer to the following references for an explanation of why 10-bit encodes compress better:
AviSynth+ Native Deep Color Support
Since r2290 (October 2016), supports deep color – 10, 12, 14, 16 and 32-bit (floating point) RGB & YUV color spaces. All AVS+ color spaces are listed here. Support functions include ConvertBits, ConvertStacked, Extract and CombinePlanes. Deep color support has also been added to all internal filters and many external plugins.
This feature greatly simplifies use of deep color and could make much of the information below obsolete.
See the AviSynth+ main page for more information.
Importing High Bit-depth Video into AviSynth
For importing high bit depth video AviSynth 2.6.0 or greater is strongly recommended. AviSynth 2.6 adds the additional planar color spaces (Y8,YV16,YV24, YV411) which makes it that much more compatible with all of the existing formats.
Patched FFMS2 - import DNxHD, ProRes, and other 10-bit videos in their native format (4:2:2 and 4:4:4 are also supported), output greater than 8-bits will always be in the Stack16 format.
- Source code: GitHub repository
- Discussion: Doom9 thread - Importing DNxHD to Avisynth (some of the links may be outdated; see downloads below or SAPikachu's signature for latest versions)
Updated binaries: March 15, 2015 | older versions
- ffms2-6e0d654+a9fe004-ffmbc-FFmbc-0.7.1.7z | mirror - This version uses FFmbc as a decoder; may have better support for professional video formats like ProRes, DNxHD, etc.
- ffms2-6e0d654+a9fe004-ffmpeg-1e4d049.7z | mirror - This version uses FFmpeg as a decoder; may be better for general (more common) formats.
- ffms2-6e0d654+a9fe004-libav-9a60b1f.7z | mirror - This version uses Libav as a decoder; may be better for general (more common) formats.
These versions work just like the official FFMS2, but includes the additional enable10bithack parameter and support for the additional planar colorspaces available is AviSynth 2.6.
By default enable10bithack is set to false so it will work just like the official FFMS2; to import high bit depth video set enable10bithack
=true, output will be in the Stack16 format.
See FFmpeg versus Libav for information on pros and cons and differences between the FFmpeg and Libav.
Another source filter to import regular 8-bit and high bit depth video. LSMASHSource includes these 2 fuctions to import video:
- LSMASHVideoSource - This function uses libavcodec as a video decoder and L-SMASH as a demuxer. Recommended for MP4, MOV, ISO Base Media and its derived file formats.
- LWLibavVideoSource - This function uses libavcodec as a video decoder and libavformat as a demuxer.
Can be used to import VapourSynth scripts into AviSynth. Video can be 8-bit or greater.
You can also import video or still via 16-bit PNG format pictures with the following ImageMagick command lines.
Examples shown are for Windows. Requires the 16-bit version of ImageMagick; get it here (look for downloads with Q16 in the file name)
- Convert 16-bit to Stack16 (high/low or stack16 format):
- Convert Stack16 (high/low) to 16bit:
For further explanation of these command lines, please see the thread Image Magick and stacked high bit-depth (doom9.org)
The following methods are obsolete! If you must, only use as a verification or as workaround:
- Readv210mod - Can read uncompressed v210 in .mov container as color. Needs a manual setting skip the file header.
- Sashimi - Sashimi 0.85 has different bit-depth support. Please see OtherFormats/Read_v210.avs included in the package.
- ReadV210 - Can read uncompressed v210 in .mov container as greyscale.
Alternative builds and methods of importing (also obsolete):
- ffms2mod - Can return most 10bit video in the Avisynth high bit-depth convention.
- RawSource with ffmpeg - shows an example of using ffmpeg to convert to a 16bit format which can be read by RawSource in Avisynth 2.6.
Processing High Bit-depth Video with AviSynth
Some plugins support processing internally in a higher bit-depth for better quality and return an 8-bit video. Others support full high-bit processing and can retun a special format 16 bit video.
Most developers have adopted a vertically stacked format known as Stack16, where the high bits (MSB) are stored in the upper half of a video, and the lower bits (LSB) in the lower half of the video.
This special format must be processed only with high-bit aware scripts and plugins.
- Dither - A set of scripts, original and modified plugins to process 16-bit clips. Some of the functions include 16-bit color space conversion, debanding, denoising, resizing, and dithering 16-bit to lower bit depths.
- CLExpr - OpenCl plugin for runtime calculation of expressions on 8 and 16-bit depths clips. Makes mt_lutxy and mt_lutxyz possible on 16-bit. More information here.
- SmoothAdjust - High quality YUV color adjustment plugin. SmoothAdjust can input and output 16-bits; all calculations are internally done in 32-bit float to avoid rounding errors and artifacts.
- Xaa - anti-aliasing and resizing script.
- Color Correction
- flash3kyuu_deband - Debanding filter with 8/16 bit input/output. In addition flash3kyuu_deband can be used to dither 16-bit to lower bit depths.
- SMDegrain - mvtools+mdegrain denoising with 16-bit input and output.
- DenoiseMD - 8/16-bit denoise.
- Dfttest - 8/16-bit 2D/3D frequency domain denoiser.
- KNLMeansCL - OpenCL based Non Local Means denoising with support for 16-bit input and output.
- SMDegrainMod - 8/16 bit denoising with additional features like sharpening. Original Doom10 archived page.
- TempLinearApproximate - 8/16 bit filter for temporal linear approximation between pixels . Meant mainly for denoising aid in motion compensated clips.
- xNLMeans - Implementation of the Non Local Means denoising algorithm, as described by Buades et al. Includes support for 16-bit input and output.
- HQDeringMod - Deringing script with 16-bit input and output.
- Frame Averaging
- Debicubic - This filter is designed to reverse the effects of bicubic upsampling. 8/16-bit input and output.
- Debilinear - This filter is designed to reverse the effects of bilinear upsampling. 8/16-bit input and output.
- nnedi3_resize16 - An advanced script for high quality image resizing and colorspace conversion. It supports 16-bit input and output.
- ResampleHQ - Provides gamma-aware resizing and color space conversion. Uses 32-bit linear color internally but input and output is limited to 8-bit.
- Resizers Functions Pack - Includes LinearResize(), a function to resize in linear space. 8/16-bit input/output. Original Doom10 archived page.
- Deep Color Tools - This Script provides basic functions to import 10bit video, do color adjustments, and export to 8bit. (NOT RECOMMENDED, THERE ARE BETTER ALTERNATIVES)
Codecs which support high bit-depth
- H.264 - 10-bit YUV 4:2:0/4:2:2/4:4:4 available via x264 (lossy/lossless compression supported).
- HEVC - 10-bit YUV 4:2:0/4:2:2/4:4:4 available via x265 (lossy/lossless compression supported).
- Ut Video Codec Suite - YUV 4:2:2 10bit (lossless compression).
Exporting High Bit-depth Video
You can encode out of AviSynth to 10bit x264 via
- x264-tMod - A modification to the x264 encoder to enable various enhancements, especially for the use of high-bit depth input. Supports the AviSynth high bit-depth convention, quality enhancements, bit-depth conversion, filters such as denoising and deinterlacing.
- avs4x264mod - This command-line tool will directly convert from a high bit-depth convention Avisynth script to H.264 with x264, including the 10bit profile. Please check the blog for updated versions.
Some tutorials on exporting high bit depth image sequences:
Playback of High Bit-depth Videos
- Most of the time you will only get to see dithered 8-bit video, as equipment to truly display high bit-depths is not as common at the consumer level in 2014 (list of 10-bit monitors).
- The Blu-ray standard does not support high bit-depth video nor xvYCC color space (full-range 8 bit video). On September 2014 it was announced that the up-and-coming 4k Blu-ray standard will support 10-bit video and a greater color gamut by using the Rec. 2020 color space.
- Digital theaters project up to 12-bit video; for more information read the wiki article: Digital Cinema Initiatives
Other Software and Information
- FFdshow builds with 10-bit support (deprecated)
Sample High Bit-Depth Videos
See this thread for links to examples. There are also deepcolor versions of standard test clips (used in image processing research). http://forum.doom9.org/showthread.php?t=158836&highlight=v210
todo add: piping RGB48 data from avs2yuv and export 16bit image sequences in either .tif or .exr preferably using ImageMagick: http://www.imagemagick.org/discourse-server/viewtopic.php?f=1&t=18943 or .jp2 image sequences http://www.imagemagick.org/discourse-server/viewtopic.php?f=3&t=24718
- Convert Stack16 (high/low) to 16bit: