Rough Guide to converting 8bit video source to 16bit Scene Referred Linear Openexr, alternatively 16bit .tif image sequences or 10bit Lossless h264.
By the way, this is not just 8bit in a 16bit file, type of conversion, shoe box in a steamer trunk analogy and the usual “no point all you get is bigger file sizes”, this method generates additional data.
It works by denoising the source and with the LSB (Least Significant Bit) data of each frame and stacks it with the MSB (Most Significant Bit), the extra data bolstering each image frame and giving more data to grade with and option to dither with an encoder friendly dithering method to reduce the risk of banding.
http://en.wikipedia.org/wiki/Bit_plane
Here’s a link to a 8bit & 16bit version of the same frame from a Canon MOV 1920×1088 source.
Welcome comments if you can see a degrading of the image by stacking LSB/MSB .
Please test them with a grade and as you manipulate them check the histograms for combing, compare the performance of the 8bit against the 16bit, whether you feel there’s any point in generating bigger files for the added ‘gradeability’ is your choice, but hard disk space is cheap.
Direct import of the MOV into Blenders 32bit float Compositing Nodes and float data in the VSE fared no better than the 8bit source in the samples above where as the 16bit stood up to more processing. 32bit float processing of 8bit sources in Blender is not enough to prevent combing of the 8bit source.
The process set out below assumes the video sources are encoded based on a Rec601 or Rec709 transfer curve, the process outlined below uses an inverse Rec601/Rec709 curve to linearise the source rather than using the inverse of a typical sRGB 0.45. Which does not create a true scene linear output for video sources they weren’t gamma encoded with sRGB curve to start with but a Rec601/709.
So there should be no squeezing of shadow detail by inverting the wrong gamma curve.
‘Scene’ referred linear rather than treating as a ‘Display’ referred source. This is nothing to do with ‘crushing blacks’ from an incorrect color space conversion to RGB by scaling luma.
Prerequisites:
Avisynth 2.5.x (2.5.8 currently)
http://sourceforge.net/projects/avisynth2/files/
FFmpegSource2 plugin (Don’t use 2.16 it’s buggy for full range luma sources)
AVS2yuv.exe
http://akuvian.org/src/avisynth/avs2yuv/
Imagemagick Q16 or hdri compiled options.
If your on Linux doing all this with Wine then then AVS2yuv will happily pipe data to a Linux build of Imagemagick.
x264 10bit [JEEB Patched]
Grab the 32bit or 64bit 10bit build from top of thread.
AVSPmod, Virtualdub or Favourite Text Editor.
(You may have problems with AVSPmod 2.2.0 version, try 2.1.8 if thats the case.)
Dither Plugin
http://ldesoras.free.fr/src/dither-1.13.3.zip
dfttest Plugin
http://web.missouri.edu/~kes25c/dfttestv18.zip
Masktools2 version a48 or above
http://manao4.free.fr/masktools-v2.0a48.zip
Process:
Install Avisynth.
Copy various plugin zips to Avisynths plugins folder in Program Files\Avisynth 2.5\ unzip them to folders, then copy out the .dll’s and .avsi’s directly into Avisynths plugins folder, this simplifies paths to various plugins when writing scripts.
Install Imagemagick Q16 / hdri. Open a console or cmd and type identify -version. Hopefully you’ll see something similar to:
Version: ImageMagick 6.7.0-8 2011-06-26 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2011 ImageMagick Studio LLC
Features: OpenMP HDRI
To get up and running create a folder and put x264.exe, AVS2yuv.exe and your test movie file into it.
Everything that follows assumes Canon HDSLR h264AVC 1920×1088 source. Edit scripts to suit source if it differs. If you’re importing 4:3 PAR sources you may wish to resize to 1:1 PAR within the scripts below. For HDV 1440×1080 source add the line:
Dither_resize16 (1920, 1080, 0, 0, 1440, 1080, "spline36", cplace="mpeg2")
after Dither_Convert_8_to_16 () and ensure that when using the AVS2yuv command lines that you amend –input-res and/or -size accordingly. ie: 1920×1080
Open AVSPmod or your favourite text editor and create to .avs scripts suitably named. Strongly suggest AVSPmod, or Virtualdub.
This script for RGB output to go to Imagemagick for image sequences:
LoadPlugin("c:\Program Files\AviSynth 2.5\plugins\ffms2.dll")
LoadPlugin("c:\Program Files\AviSynth 2.5\plugins\mt_masktools-25.dll")
FFmpegSource2("MVI_0000.MOV")
Dither_convert_8_to_16 ()
#Dither_convert_yuv_to_rgb(matrix="601", tv_range=false, cplace="MPEG2", chromak="bicubic", lsb_in=true, output="rgb48y")
#Dither_y_gamma_to_linear (tv_range_in=false, tv_range_out=false, curve="709")
#Dither_convey_rgb48_on_yv12 (SelectEvery (3, 0),SelectEvery (3, 1),SelectEvery (3, 2) )
DitherPost()
And 2nd script to go to 10bit Lossless x264:
LoadPlugin("c:\Program Files\AviSynth 2.5\plugins\ffms2.dll")
LoadPlugin("c:\Program Files\AviSynth 2.5\plugins\mt_masktools-25.dll")
FFmpegSource2("MVI_0000.MOV")
Dither_convert_8_to_16 ()
#Dither_convey_yuv4xxp16_on_yvxx()
DitherPost()
Open and preview your first script in AVSPmod or Virtualdub to test that the basics are in place. You should simply see the first frame of your video. Then do the same with your second script and test that.
You may get an error message about certain plugins having ‘_’ underscores rather than ‘-’ hyphens, but really just make sure your Avisynth plugins name and the names and locations in the script pointing to them match.
If all is working, we can move onto AVS2yuv.
Unfortunately neither Virtualdub or AVSPmod can export 16bit data from within Avisynth, luckily AVS2yuv or AVS2pipe (which includes audio) can pipe the 16bit data to an external application like Imagemagick and a 10bit build of x264.
So to get the 10bit or 16bit data out we first have to unhash the #Dither… lines from our scripts and resave them. You’ll need to add a hash in front of the DitherPost() entry. DitherPost() takes the 16bit data back to 8bit. We needed that line active so we could preview in Virtualdub or AVSPmod.
Once the scripts are tweaked test them out by opening a console, cd’ing to the folder you created holding the scripts, source file, encoder etc and enter this (assumes Linux, if on Windows remove the wine bit) into the console for linear .exr’s:
wine ./avs2yuv.exe -raw "script_Lin_RGB.avs" -o - | convert -depth 16 -size 1920x1088 -set colorspace RGB -colorspace RGB rgb:- "output_%06d.exr"
If you get out of memory errors try this on the CLI:
identify -list resource
Which will show you how much resources Imagemagick considers available. For example you may have 3GB memory and 6GB map. Imagemagick can be limited to use only so much RAM and the rest of the video data cached in /tmp (on Linux)
To limit resources available to Imagemagick add -limit memory 1GiB -limit map 2GiB in between:
convert and -depth
Change the GiB or MiB values above to fall within the resources listed by Imagemagick for your hardware.
For 10bit Lossless h264:
wine ./avs2yuv.exe -raw "script_YCC.avs" -o - | ./x264-64-10bit.exe - --demuxer raw --input-depth 16 --input-res 1920x1088 --fps 25 --fullrange on --preset ultrafast --qp 0 --output "10bitOutput.mp4"
Obviously adjust input-res to suit your source. Assuming 1920×1088. You might prefer .avi or .mkv as your output container rather than mp4.
If you prefer sRGB gamma 16bit .tif’s then hash out the Dither-y-gamma…… line from the RGB script and change the Imagemagick line to .tif rather than .exr or if you would prefer linear light .tif’s or .pngs for example you can embed an icc profile into your file with imagemagick by adding -profile NameOfYourICC.icc to the Imagemagick route on the CLI. I add the -profile whatever.icc before the -set colorspace stuff.
If you need a linear light sRGB ICC profile for any color managed application (that uses ICC’s) including After Effects 7.0 upwards then you can get them here on Stu Maschwitz awesome blog: http://prolost.com/blog/2006/2/7/linear-color-workflow-in-ae7-part-1.html and direct link to icc zip file here: LinearProfiles.zip
Just unzip and drop the ICC you want to use into the same location as the avs script & source video files. Make sure the filename in the CLI call is the same as the ICC file name. I always take an additional step of removing any spaces from the file name and/or replacing the spaces with underscores as this is the CLI and spaces can trip it all up.
I intend making this process a bit easier via AVSPmod python macros, but for now to get up and running.
This is really the basics, there are many functions available within Avisynth to include in our scripts, many now at 16bit precision including gamma aware resizing, noise reduction, color correction, adding grain as well as hundreds of 8bit functions including sharpening, optical flow based slow motion, deinterlacing, upsampling, the list goes on.
Let me know how you get on and if there’s anything specific you’re after. I’m going to look at batch conversion python script for AVSPmod next.

Wow!! this is amazing..
thanx for your work..
Thanks, very little of it is my work, I must add full credit to the very knowledgable regulars over at doom9 and will add full credits to this blog post.
I just applied their hard work to a certain task. With a couple of feature requests very kindly carried out by them.
Hope you find it useful.
Getting these type of errors while doing conversion to tiff:
before it was showing that fftw3.dll was missing. Hence downloaded fftw-3.3dll package and copied libfftw3-3.dll to system32 folder in linux and renamed it to fftw3.dll.
And next i got this error
~/Downloads/VirtualDub-1.9.11$ wine ./avs2yuv.exe -raw “tst_hdr.avs” -o – | convert -depth 16 -size 1920×1088 -set colorspace RGB -colorspace RGB rgb:- “output_%06d.tiff”
fixme:actctx:parse_depend_manifests Could not find dependent assembly L”Microsoft.VC80.OpenMP” (8.0.50727.4053)
fixme:msvcr90:__clean_type_info_names_internal (0x3c1950) stub
err:ole:CoGetClassObject class {b841f346-4835-4de8-aa5e-2e7cd2d4c435} not registered
err:ole:CoGetClassObject class {b841f346-4835-4de8-aa5e-2e7cd2d4c435} not registered
err:ole:create_server class {b841f346-4835-4de8-aa5e-2e7cd2d4c435} not registered
fixme:ole:CoGetClassObject CLSCTX_REMOTE_SERVER not supported
err:ole:CoGetClassObject no class object {b841f346-4835-4de8-aa5e-2e7cd2d4c435} could be created for context 0×17
err:ole:CoGetClassObject class {db43b405-43aa-4f01-82d8-d84d47e6019c} not registered
err:ole:CoGetClassObject class {db43b405-43aa-4f01-82d8-d84d47e6019c} not registered
err:ole:create_server class {db43b405-43aa-4f01-82d8-d84d47e6019c} not registered
fixme:ole:CoGetClassObject CLSCTX_REMOTE_SERVER not supported
err:ole:CoGetClassObject no class object {db43b405-43aa-4f01-82d8-d84d47e6019c} could be created for context 0×17
Avisynth error:
Dither_convey_rgb48_on_yv12: r, g and b must be YV12.
(dither.avsi, line 461)
(tst_hdr.avs, line 8)
hi mohan, are you hashing out the Ditherpost() & unhashing the following:
Dither_convert_yuv_to_rgb(matrix=”601″, tv_range=false, cplace=”MPEG2″, chromak=”bicubic”, lsb_in=true, output=”rgb48y”)
Dither_y_gamma_to_linear (tv_range_in=false, tv_range_out=false, curve=”709″)
Dither_convey_rgb48_on_yv12 (SelectEvery (3, 0),SelectEvery (3, 1),SelectEvery (3, 2) )
yes i have hashed the Ditherpost() and unhashed the Dither_convert… Dither_y_gamma.. Dither_convey
I changed this line to use masktool 26 version
LoadPlugin(“c:\Program Files\AviSynth 2.5\plugins\mt_masktools-26.dll”)
otherwise i would be getting this error
Avisynth error:
mt_lutxy : unsupported colorspace. masktools only support planar YUV colorspaces (YV12, YV16, YV24)
(dither.avsi, line 770)
(dither.avsi, line 749)
(dither.avsi, line 263)
(tst_hdr.avs, line 4)
Yes, there was a bit of discussion a while ago about using a hypen or an underscore in the naming convention.
If you still get errors with this try masktools-25.dll
No,
If i use masktools-25.dll then i would get this error:
mt_lutxy : unsupported colorspace. masktools only support planar YUV colorspaces (YV12, YV16, YV24)
If i use masktools-26.dll then i wouldn’t get the error. Maybe masktools-25 won’t support RGB colorspace?
Mohan if you’re still having trouble try using this fftw3.dll file fftw3.dll.zip it’s safe straight out of my system32, I remember having problems with finding a compatible version.
Also for linearised image formats, blender will always treat .EXR’s as linear, as that’s what they should always be and preview them gamma corrected, where as linearised .tifs will appear dark in Blender and you’ll need to apply gamma to them via Nodes to get a corrected preview in the UV Image Viewer and Scopes for instance.
Hope your having some success.
y am i getting these errors
I notice your error message includes Microsoft.VC80, do you have the Microsoft Visual C++ Redistributable package installed, if not try installing it and trying again.
Hi.
I am still gettting this error. I have added fftw3.dll in system32 folder.
~/Downloads/VirtualDub-1.9.11$ wine ./avs2yuv.exe -raw “tst_hdr.avs” -o – |convert -depth 16 -size 1920×1088 -set colorspace RGB -colorspace RGB rgb:- “output_%06d.tiff”
fixme:actctx:parse_depend_manifests Could not find dependent assembly L”Microsoft.VC80.OpenMP” (8.0.50727.4053)
fixme:msvcr90:__clean_type_info_names_internal (0x3c1950) stub
err:ole:CoGetClassObject class {b841f346-4835-4de8-aa5e-2e7cd2d4c435} not registered
err:ole:CoGetClassObject class {b841f346-4835-4de8-aa5e-2e7cd2d4c435} not registered
err:ole:create_server class {b841f346-4835-4de8-aa5e-2e7cd2d4c435} not registered
fixme:ole:CoGetClassObject CLSCTX_REMOTE_SERVER not supported
err:ole:CoGetClassObject no class object {b841f346-4835-4de8-aa5e-2e7cd2d4c435} could be created for context 0×17
err:ole:CoGetClassObject class {db43b405-43aa-4f01-82d8-d84d47e6019c} not registered
err:ole:CoGetClassObject class {db43b405-43aa-4f01-82d8-d84d47e6019c} not registered
err:ole:create_server class {db43b405-43aa-4f01-82d8-d84d47e6019c} not registered
fixme:ole:CoGetClassObject CLSCTX_REMOTE_SERVER not supported
err:ole:CoGetClassObject no class object {db43b405-43aa-4f01-82d8-d84d47e6019c} could be created for context 0×17
Avisynth error:
Dither_convey_rgb48_on_yv12: r, g and b must be YV12.
(dither.avsi, line 461)
(tst_hdr.avs, line 9)
And this is my script..
LoadPlugin(“c:\Program Files\AviSynth 2.5\plugins\VariableBlur.dll”)
LoadPlugin(“c:\Program Files\AviSynth 2.5\plugins\ffms2.dll”)
LoadPlugin(“c:\Program Files\AviSynth 2.5\plugins\dither.dll”)
LoadPlugin(“c:\Program Files\AviSynth 2.5\plugins\mt_masktools-26.dll”)
FFmpegSource2(“z:\media\New Volume\karanika_shishu\day1\MVI_0009.MOV”)
Dither_convert_8_to_16 ()
Dither_convert_yuv_to_rgb(matrix=”601″, tv_range=false, cplace=”MPEG2″, chromak=”bicubic”, lsb_in=true, output=”rgb48y”)
#Dither_y_gamma_to_linear (tv_range_in=false, tv_range_out=false, curve=”709″)
Dither_convey_rgb48_on_yv12 (SelectEvery (3, 0),SelectEvery (3, 1),SelectEvery (3, 2) )
#DitherPost()
this is the command line..
wine ./avs2yuv.exe -raw “tst_hdr.avs” -o – |convert -depth 16 -size 1920×1088 -set colorspace RGB -colorspace RGB rgb:- “output_%06d.tiff”
Mohan your avs script and avs2yuv command line work fine for me, so no problem with this part of the jigsaw.
Hi yellow ..
Thank you for your support. I had success with getting out tiff files in windows. Don’t know what problem with my Ubuntu 11.04. Will re-install as i get time.
But one problem is when i execute the script i think convert command or avs2yuv is feeding all the uncompressed data directly to ram and its filling up very fast and also my pagefile system is also filling up and hence if i have a footage of around 20mb above i would get out of memory error. Is there any change to tell these commands to process each frame and render it out to hard disk and take the next frame, instead of doing all at once. I think you maybe also having this sort of problem
.
Then next thing is as i have to convert all the footage of my feature film project, it is impractical to convert every footage to 16 bit tiff and hence was thinking to use my edl and take the start edit point and end edit point and then specifying it in my avs file (through Trim command) and then only to render out the specified frames. What do you think? Will this work out?
My English isn’t so good
Hope you could understand.
Hey Mohan that’s great, earlier versions of Dither did have memory issues but any version after 1.4 should be ok. I’m using on Linux with a machine that only has 2GB RAM, I’ll do some bigger runs and see as comparison.
The trim command should do the job.
Good to hear of your success and your film.
hi..
did you have any success regarding working with some larger files?
Mohan, no haven’t looked at it further at the moment. Time is tight.
oh ..
Mohan, I’ve found time to look at this a bit and a ‘fix’ for the memory problem can be done by limiting the memory Imagemagick uses, when that memory limit is reached IM starts writing the rest of the video data to /tmp in 32mb chunks. So the process can continue. So depending on your available RAM and disk space you can set two parameters as follows:
First establish what Imagemagick considers available resources with this on the CLI:
identify -list resource
You can allocate limits within that by using IM’s -limit functions described here: http://www.imagemagick.org/script/command-line-options.php?#limit by example amending the avs2yuv line to:
wine ./avs2yuv.exe -raw “tst_hdr.avs” -o – | convert -limit memory 500MiB -limit map 1GiB -depth 16 -size 1920×1088 -set colorspace RGB -colorspace RGB rgb:- “output_%06d.tiff”
Make sure however that you have enough disk space to accommodate the temporary files until IM writes your images to disk.
Hope that resolves the problem.
Post updated to include info on “identify -list resource’ & -limit memory -limit map
hi..
Was busy with voice over process of my movie and hence this long break. Sorry i wasn’t able to reply you back on time. Thanks for your findings though
One problem is ….
-limit memory and -limit map option isn’t doing anything i suspect. I am unable to convert large files like a 2 minutes of HD footage. Still my pagefile under windows is filling up. I taught convert command would take one frame at a time and render it and go next frame…
Mohan, I hope your movie is going well and that everything is falling into place. No need for apologies whatsoever.
I’ve only tested the -limit memory & -limit map on 64bit Linux. Piping from Avisynth under Wine 1.3 to Linux based Q16 Imagemagick and I’ve found that the -limit commands solve the memory problem, converting all I give it without error, albeit with ample hard disk space for the temporary files and the test machine is an old Sempron (64bit version) with 2GB RAM.
I’m sorry it’s not working for you and I’ll investigate further on a Windows based machine.
Hi,
Do you know of a way to get 10 or 16 bit pngs out of AVISynth rather than videos?
Thanks
Tom
You can substitute the .exr or .tiff in the post and write them out with Imagemagick. IM supports 16bit pngs I think.
Writing 10 or 16bit directly out of Avisynth is not possible as it only supports 8bit formats.
Thanks for your interest.
Hi,
Thanks, when I do that I get the following error:
C:\16bit test>avs2yuv.exe -raw “Test.avs” -o – | convert -depth 16 -size 1024×57
6 -set colorspace RGB -colorspace RGB rgb:- “output_%06d.png”
Test.avs: 1440×1152, 25 fps, 51 frames
convert: unexpected end-of-file `-’: No such file or directory @ error/rgb.c/Rea
dRGBImage/232.
I think something needs to go after the “-o -”but I’m not sure what?
Thanks
Tom
hi, the -o – | all looks ok, just checking but make sure your frame size in your Test.avs is the same size as your source.
Updated the post with method of embedding an ICC profile into the file output from Imagemagick for color managed applications.