3D Vision Blog

A normal user's look into the world of 3D Stereo Technologies

3D Vision Blog header image 2

2D to 3D Realtime Video Conversion Script for Avisynth v0.3

January 12th, 2010 · 115 Comments · 2D to 3D Conversion

3d-vision-realtime-2d-3d-convert


After some more experimenting and help from some readers it is time for the new updated version 0.3b of the Avisynth script I wrote about realtime conversion of 2D video to 3D. The first version of the script was a bit rough and not very functional, then the second version was more functional and improved, but still performing slow on 720p or higher resoltion. The new version does not use the slow Reform plugin anymore as it is quite heavy for the CPU for real time processing of frames as Quadrilaterals. This version can also take advantage of multi-core CPUs, just use the MT version of the script with the multithreading support included (version 0.8 for AviSynth 2.5.8). The multithreaded script is recommended if you have a dual or quad core processor and get slower framerates in order to get better framerate. Just as a reminder, this script is to be opened instead of a video file from 3D Vision Stereoscopic Player or the Stereoscopic Player in a Side by Side L/R format by default and is designed to be viewed on a computer that is equipped with a 120Hz display and Nvidia’s GeForce 3D Vision. Thanks to the help of Martin Haverland and based on some parts of eslave’s similar script the conversion can now also be used with anaglyph glasses, on interlaced displays etc. You just need to comment the StackHorizontal command and uncomment the respective mode you need to use in the script code…


## 2D to 3D Realtime Video Conversion Avisynth script v0.3b
## Made by Anton Belev at 3D Vision Blog
## http://www.3dvision-blog.com
## Additionally extended by Martin Haverland at audiomh.de for quality resize
## and different output modes including interlaced format for use in non-3d specific players e.g. windows media player.


## Open the video file for conversion, change the video file name
video2d = DirectShowSource("Avatar_Trailer_HD.avi")

## Increase video brightnes on dark videos, good for 3D Vision owners
# video2d = video2d.Tweak(Bright=10)

## Convert to RGB32 to avoid the width restrictions
video2d = ConvertToRGB32(video2d)


## Optional aspect ratio maintaining quality resize for 3d monitor target resolution.
## Very cpu intensive, may be for offline use only, e.g. in virtualdubmod.
## 2x 3.0ghz cpu may give you a framerate of 16fps while running the whole script in virtualdubmod including xvid compression in HDTV quality saving setting.
## Offers great quality in the result video for fullscreen playback in every .avs capable player later.
## Also reduces ghosting if the original file resolution is smaller than the target resolution.
# videoW = width(video2d)
# videoH = height(video2d)
## For 19" Zalman use 1280, for 22" Zalman Trimon it is 1680 etc.
# hzTargetSize = 1280
# video2d = Lanczos4Resize(video2d, hzTargetsize, hzTargetsize * videoH / videoW)
## Commenting out the above resizing maintains realtime capability!


## Get video width/height and set the frame stretch factor
## Lower the value 100 to increase frame stretch, may introduce ghosting
videoW = width(video2d)
videoH = height(video2d)
ResW = videoW + (videoW / 100)
CropW = (ResW - videoW) / 2


## Create variables for left and right frame with one frame difference
## This is the Plufrich-like simulation that creates illusion of depth from movement
f1 = video2d
f2 = DeleteFrame(video2d, 0)


## Stretch the right frame to further the depth effect
f1 = LanczosResize(f1, ResW, videoH)
f1 = Crop(f1, 0, 0, videoW, videoH)

## Stretch the left frame to further the depth effect
f2 = LanczosResize(f2, ResW, videoH)
f2 = Crop(f2, CropW, 0, videoW, videoH) 


## Output the two video frames in a side-by-side / parallel format
## Use this as a default for playing back on 3D Vision (Side by Side L/R)
StackHorizontal(f2, f1)

## Output the two video frames in a Above/Below format (like Sony?)
# StackVertical(f2,f1)


## Output the two video frames in a page flipping format for shutter glasses etc.
## The Tweak as proposed by eslave is for brighter image, modify the value 30
# f1 = f1.ConvertToYV12.Tweak(Bright=30)
# f2 = f2.ConvertToYV12.Tweak(Bright=30)
# Interleave(f2,f1)


## Output the two video frames in anaglyph red-cyan as proposed by eslave
# MergeRGB(f2.ShowRed, f1.ShowGreen, f1.ShowBlue)

## For reversed anaglyph i.e. cyan-red
# MergeRGB(f1.ShowRed, f2.ShowGreen, f2.ShowBlue)


## Output the two video frames in anaglyph yellow-blue as proposed by eslave (untested)
# f1 = f1.ConvertToYV12(matrix="PC.601").tweak(bright=12.5, sat=1.25, coring=false)
# f1 = f1.ConvertToRGB32
# f1 = f1.Levels(0, 1.05, 255, 0, 255, coring=false)
# MergeRGB(f2.ShowRed, f1.ShowGreen, f1.ShowBlue)

## Output the two video frames in anaglyph blue-Yellow as proposed by eslave (untested)
# f2 = f2.ConvertToYV12(matrix="PC.601").tweak(bright=12.5, sat=1.25, coring=false)
# f2 = f2.ConvertToRGB32
# f2 = f2.Levels(0, 1.05, 255, 0, 255, coring=false)
# MergeRGB(f1.ShowRed, f2.ShowGreen, f2.ShowBlue)


## Output two video frames in Interlaced mode
## Ueed for Zalman Trimon, Acer Aspire 3D etc.
# f1 = SeparateFields(f1)
# f1 = SelectEven(f1)
# f2 = SeparateFields(f2)
# f2 = SelectOdd(f2)
# interleave(f2,f1)
# AssumeFieldBased()
# weave()

The new singlethreaded version of the script requires you to download and install AviSynth on your PC. If you have trouble running it with a high resolution video files (720p or above) you may try the multithreaded version below, just don’t forget that you should have a multicore system for it. And don’t forget to save the code above with AVS file extension and to replace the Avatar_Trailer_HD.avi with the name of the video file you want to play.


## 2D to 3D Realtime Video Conversion Avisynth script v0.3b MultiThreading
## Made by Anton Belev at 3D Vision Blog
## http://www.3dvision-blog.com
## Additionally extended by Martin Haverland at audiomh.de for quality resize
## and different output modes including interlaced format for use in non-3d specific players e.g. windows media player.


## For this to work you need to have AviSynth with MT mod 0.7 installed!!!
SetMTMode(2,0)


## Open the video file for conversion, change the video file name
video2d = DirectShowSource("Avatar_Trailer_HD.avi")

## Increase video brightnes on dark videos, good for 3D Vision owners
# video2d = video2d.Tweak(Bright=10)

## Convert to RGB32 to avoid the width restrictions
video2d = ConvertToRGB32(video2d)


## Optional aspect ratio maintaining quality resize for 3d monitor target resolution.
## Very cpu intensive, may be for offline use only, e.g. in virtualdubmod.
## 2x 3.0ghz cpu may give you a framerate of 16fps while running the whole script in virtualdubmod including xvid compression in HDTV quality saving setting.
## Offers great quality in the result video for fullscreen playback in every .avs capable player later.
## Also reduces ghosting if the original file resolution is smaller than the target resolution.
# videoW = width(video2d)
# videoH = height(video2d)
## For 19" Zalman use 1280, for 22" Zalman Trimon it is 1680 etc.
# hzTargetSize = 1280
# video2d = Lanczos4Resize(video2d, hzTargetsize, hzTargetsize * videoH / videoW)
## Commenting out the above resizing maintains realtime capability!


## Get video width/height and set the frame stretch factor
## Lower the value 100 to increase frame stretch, may introduce ghosting
videoW = width(video2d)
videoH = height(video2d)
ResW = videoW + (videoW / 100)
CropW = (ResW - videoW) / 2


## Create variables for left and right frame with one frame difference
## This is the Plufrich-like simulation that creates illusion of depth from movement
f1 = video2d
f2 = DeleteFrame(video2d, 0)


## Stretch the right frame to further the depth effect
f1 = LanczosResize(f1, ResW, videoH)
f1 = Crop(f1, 0, 0, videoW, videoH)

## Stretch the left frame to further the depth effect
f2 = LanczosResize(f2, ResW, videoH)
f2 = Crop(f2, CropW, 0, videoW, videoH) 


## Output the two video frames in a side-by-side / parallel format
## Use this as a default for playing back on 3D Vision (Side by Side L/R)
StackHorizontal(f2, f1)

## Output the two video frames in a Above/Below format (like Sony?)
# StackVertical(f2,f1)


## Output the two video frames in a page flipping format for shutter glasses etc.
## The Tweak as proposed by eslave is for brighter image, modify the value 30
# f1 = f1.ConvertToYV12.Tweak(Bright=30)
# f2 = f2.ConvertToYV12.Tweak(Bright=30)
# Interleave(f2,f1)


## Output the two video frames in anaglyph red-cyan as proposed by eslave
# MergeRGB(f2.ShowRed, f1.ShowGreen, f1.ShowBlue)

## For reversed anaglyph i.e. cyan-red
# MergeRGB(f1.ShowRed, f2.ShowGreen, f2.ShowBlue)


## Output the two video frames in anaglyph yellow-blue as proposed by eslave (untested)
# f1 = f1.ConvertToYV12(matrix="PC.601").tweak(bright=12.5, sat=1.25, coring=false)
# f1 = f1.ConvertToRGB32
# f1 = f1.Levels(0, 1.05, 255, 0, 255, coring=false)
# MergeRGB(f2.ShowRed, f1.ShowGreen, f1.ShowBlue)

## Output the two video frames in anaglyph blue-Yellow as proposed by eslave (untested)
# f2 = f2.ConvertToYV12(matrix="PC.601").tweak(bright=12.5, sat=1.25, coring=false)
# f2 = f2.ConvertToRGB32
# f2 = f2.Levels(0, 1.05, 255, 0, 255, coring=false)
# MergeRGB(f1.ShowRed, f2.ShowGreen, f2.ShowBlue)


## Output two video frames in Interlaced mode
## Ueed for Zalman Trimon, Acer Aspire 3D etc.
# f1 = SeparateFields(f1)
# f1 = SelectEven(f1)
# f2 = SeparateFields(f2)
# f2 = SelectOdd(f2)
# interleave(f2,f1)
# AssumeFieldBased()
# weave()

For the multithreading version, besides the need for Avisynth, you’ll also need to download the latest Avisynth MT mod and then apply it. This means extracting the MT.dll library in the plugins folder of the Avisynth installation and then overwriting the original avisynth.dll with the modified one (\Windows\System32 for 32-bit OS or \Windows\SysWOW64 for 64-bit OS). After that you’ll be ready to run the script and see that all the available cores of the CPU are being used for processing and thus get a better framerate than with the singlethreading version of the script.

You can download the two scripts along with Avisynth and the MT mod in a single archive file to save you the trouble of getting all the separate files you need. And as always don’t forget to share your comments if you try the scripts and any ideas for further improvements are more than welcome too, especially if they are related to improving the performance as this is a bit of an issue at the moment.

- Download the 2D to 3D conversion scripts and all the needed installation files…


Other similar posts you might be interested in:

Tags: ··········


115 responses so far ↓

  • 101 Brooklyn // Apr 30, 2011 at 20:51

    I am no vice on this 2D to 3D conversion but I hope some one in this thread will help. I have tried many software programs but failed to get what I need.

    I have one 2d film here. Could some one convert this to 3D and send me? Also please let me know how I can feel watching the converted video as a real 3D video?

    http://www.megaupload.com/?d=UV6OVBEN

  • 102 games-on-ps3 // May 10, 2011 at 10:32

    I tried this with an episode from family guy, just to see what it can do with a cartoon, and i was impressed by what it picked up, some spots were a little weird looking, but as for the most part, it worked quite well.

  • 103 Adam // Jul 1, 2011 at 05:01

    I seem to get an error…It says An object or name was not found. and refers to line 8? Any Ideas

    I changed the code name of Avatar to the movie I wanted to play and saved them in the same Directory but did not work?

  • 104 jedilost // Aug 5, 2011 at 19:22

    i tried the script and i got results with all of the options – except one, but they were either side by side pictures or blurred pictures, not 3d. so i guess i need 3d glasses to see the 3d picture, right? or maybe, do i need some special hardware?

    if it is a matter of glasses, what kind of glasses should i use? i happen to have Real D glasses with me, but they didnt work with neither of the options. so is it possible to include an option for the REAL D glasses, too?

  • 105 Antonio José // Jan 2, 2012 at 06:48

    Every time I play the .AVS file I t makes the video play side by side instead of the red, cyan blur. How do I fix that?

  • 106 Antonio José // Jan 2, 2012 at 07:10

    Nevermind.. I figured it out.. Sorry, shoulda read the script more thoroughly

  • 107 Antonio José // Jan 2, 2012 at 07:36

    Okay so now I have the red – cyan video playing at half the speed. how would I fix that?

  • 108 lalit khatri // Jan 17, 2012 at 02:20

    Use AssumeFPS().
    Google this function and you will find complete avisynth api.
    Enjoy the customisation !!!!

  • 109 Ean // Jan 30, 2012 at 07:49

    My videos are coming out in a narrow, in output video height, format and I’d like to expand them to the full size of my 16:9 widescreen 3D TV. I would greatly appreciate your expertise and help. Thank you.

  • 110 Michael Johnson // Jun 23, 2012 at 20:43

    I don’t know if anybody like this script I made but here’s the code:
    ########################################
    ConvertToRGB()
    z = levels(100,1,198,0,325)
    l = Layer(last,mask(z,last), x = 5)
    r = Layer(last,mask(z,last), x = -2).duplicateframe(0)
    leftright3d(l,r)
    converttoyv12()
    ########################################

    in ffdshow resize to 900 X 300 ( I have a 1.6 ghz cpu dual core, may keep video from lagging if set to higher size on faster cpu) and in settings tab use warpresize

    http://kmplayer.en.softonic.com/

    kmplayer has a 3d feature for 3d content

  • 111 Michael Johnson // Jun 23, 2012 at 20:49

    ########################################
    ConvertToRGB()
    ChannelMixer(41.3, 41.2, 17.4, 33.8, 69.6, -3.4, -8.7,
    -13.4,122.1)
    z = levels(100,1,198,0,325)
    l = Layer(last,mask(z,last), x = 5)
    r = Layer(last,mask(z,last), x = -2).duplicateframe(0)
    rcanaglyph(l,r)
    converttoyv12()
    ########################################

    in ffdshow resize to 900 X 300 ( I have a 1.6 ghz cpu dual core, may keep video from lagging if set to higher size on faster cpu) and in settings tab use warpresize

    media player classic and ffdshow video decoder

  • 112 Robert // Jul 14, 2012 at 11:25

    I want to convert these 3D .avs files to .avi

  • 113 Bloody // Jul 14, 2012 at 14:24

    Just open the AVS script in VirtualDub and render the video as AVI…

  • 114 Robert // Sep 15, 2012 at 01:50

    How to I make to where it doesn’t delete frames for a seamless conversion?

  • 115 Jeet // Sep 29, 2012 at 16:13

    will anyone suggest me what type of glass i have to use along with this software
    i am using aoc 2236vw lcd will it support to view in 3d?

Leave a Comment

Current day month ye@r *