My first attempt at the Magic Lantern HDR feature recently released by the awesome ML team here: http://magiclantern.wikia.com/wiki/Unified>

This first attempt follows the interpolate in between frames approach but since considering it further and the fundamental problems with this method and the fact that all the motion has been captured its exposure and color that need constructing. To make use of the potentially wider dynamic range the output its assumed a bit depth greater than 8bit is required and possible as seen in a recent post.

But the following is a Interframe based method for now.

Really following on from my last post regarding 16bit Scene referred linear .EXR’s and 10bit lossless 4:4:4 h264 from video shooting Canon DSLR’s.

First some files as to where I’m at:

Basic output 1920×1088 8bit 4:2:0 h264 file: [Save As]

http://www.yellowspace.webspace.virginmedia.com/merge.mp4

A 16bit .tif frame:

http://www.yellowspace.webspace.virginmedia.com/IM-hdr_000000.tif>

A 16bit linear light .exr frame:

http://www.yellowspace.webspace.virginmedia.com/IM-hdr_000000.exr>

The process and tools is basically the same as here:

8bit Video to 16bit Scene Referred Linear .EXR’s>

With the addition of a great frame doubling/interpolation tool called Interframe for AVISynth:

http://www.spirton.com/interframe/>

And as always the excellent support from the Doom9 community.

http://forum.doom9.org>

Particularly -Vit- (QTGMC) & cretindesalpes (Dither Tools). The Interframe referencing lines in the script below is courtesy of -Vit- word for word, although not his tool :-) . Disclaimer this does not negate the need to read the Interframe documentation. :-)

So using the sample Canon MOV file provided by the RedKiteMedia, log in to download native file:

http://vimeo.com/33987353>

And this script, which is work in progress and needs work. :-)

LoadPlugin(“c:\Program Files\AviSynth 2.5\plugins\mvtools2.dll”)

LoadPlugin(“c:\Program Files\AviSynth 2.5\plugins\ffms2.dll”)

LoadPlugin(“c:\Program Files\AviSynth 2.5\plugins\fft3dfilter.dll”)

LoadPlugin(“c:\Program Files\AviSynth 2.5\plugins\removegrain.dll”)

LoadPlugin(“c:\Program Files\AviSynth 2.5\plugins\mt_masktools-25.dll”)

LoadPlugin(“c:\Program Files\AviSynth 2.5\plugins\dfttest.dll”)

Input=ffmpegsource2(“77506626.mov”)

Assert( Input.FrameCount() >= 3, “Need at least 3 frames!” )

num = Input.FrameRateNumerator()

den = Input.FrameRateDenominator()

# Interpolate even and odd frames separately to source rate

A = SelectEven(Input).InterFrame(FlowPath=”c:\Program Files\AviSynth 2.5\plugins\”, Preset=”Placebo”, NewNum=num, NewDen=den)

B = SelectOdd(Input).InterFrame(FlowPath=”c:\Program Files\AviSynth 2.5\plugins\”, Preset=”Placebo”, NewNum=num, NewDen=den)

# Trim off end frames for which an interpolated frame cannot be calculated for the other exposure

A = (Input.FrameCount() % 2 == 0) ? A.trim(1,0) : A.trim(1,A.FrameCount()-2)

B = (Input.FrameCount() % 2 == 0) ? B.trim(0,B.FrameCount()-2) : B

src1=A
src2=B

# Blending amount for the first clip

bl = 0.75

bls1 = String ( bl)

bls2 = String (1 – bl)

# 8-bit clips converted to linear 16-bit full range (gamma undone)

ug = ” 16 – 0 max 1.41624 / 2.2 ^ “

# Redo the gamma, result in 16 bits YUV

rg = ” 0.454545 ^ 362.5585 * 4096 +”

# Blend

Dither_lutxy8 (src1, src2, expr =”x ” + bls1 + ” * y ” + bls2 + ” * + 256 *”, yexpr=”x” + ug + bls1 + ” * y” + ug + bls2 + ” * +” + rg, y=3, u=3, v=3)

#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) )

Dither_convey_yuv4xxp16_on_yvxx()

There are things to tidy up in the script, such as a reverse rec709 curve to linearise as per previous .EXR workflow rather than the sRGB 0.45 ‘degamma’ in the script.

Although blending is done linear light and creating a 16bit output, there’s room for a lot of improvement. :-) I question the ‘merge” method compared to enfuse or Tufuse, but kind of feel this is more a LCE / Local Adaptiation process rather than a ‘traditional’ HDR one. HDR from only two exposures?, not really. Compared to a bracketed set. Where as Local Adaptation / Local Contrast Enhancement may provide more natural results, scroll down to the “Concept:Tonal Hierarchy and Image Contrast” here:

http://www.cambridgeincolour.com/tutorials/high-dynamic-range.htm

A way of merging the two luma planes into one 16bit levels range and whether to merge both chroma or just one from decent exposure, haven’t bothered with audio currently either.

Save the script as an .avs and then use AVS2yuv or AVS2pipemod along with a 10bit build of x264 or a 16bit hdri build of Imagemagick depending on output required. All as per previous post:

8bit Video to 16bit Scene Referred Linear .EXR’s>

Although I’ve loaded the latest Magic Lantern Firmware still haven’t had chance to test it yet. :-) Awesome work by the Magic Lantern Team.