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 with Avisynth (Proof of Concept)

December 29th, 2009 · 9 Comments · 2D to 3D Conversion


I few days ago when I’ve written about the 3Dfier DirectShow filter Philip Heggie suggested that similar thing can be achieved with the help of a simple AviSynth script. So I’ve developed a bit on his idea and prepared a bit more advanced (still quite simple actually) AviSynth script that takes an 720p 2D video file and converts it in real time to a side by side stereoscopic 3D video. The end result is much like what you can achieve with the help of the 3Dfier, and I’m sharing the code here so that everyone may experiment with it to further improve it…

In order for you to be able to run this script you’ll first have to download and install AviSynthon your PC. Then you also need to download V. C. Mohan’s Reform plugin for AviSynth and extract it at the same folder when you have the AVS script and the 720p video file you are going to convert from 2D to 3D in real time. What the script does is to create one frame difference between the frames for the left and right eye, makes quite good illusion of depth in objects… kind of Pulfrich effect. The second thing is to create a perspective distortion for one of the frames by stretching the upper part of the image and then cropping the extensive visual information to maintain the rectangular frame size. Two very simple things that create very impressive results, although it is still far from perfect as some objects are at wrong depth and there are some weird visual artefacts on some fast moving scenes, but still the end result is very good.

# Load the Reform plugin for the skew function
LoadPlugin ("Reform.dll")

# Open the video file for conversion
video2d = DirectShowSource("avatar_trailer_720p.mov")

# Create variables for left and right frame with one frame difference
f2=DeleteFrame(video2d, 0)

# Add the perspective effect to the second frame and crop it
f1 = PointResize(f1, 1360, 720)
bg = BlankClip(f1, color = $000000)
f1 = skew(f1, bg, ltopx=2, ltopy=2, lbotx=32, lboty=718, rtopx=1358, rtopy=2, rbotx=1318, rboty=718, resize = "point")
f1 = Crop(f1, 40, 0, 1280, 720) 

# Output the two video frames in a side by side format
StackHorizontal(f2, f1)

You need to copy the above code and save it to a file lets say called 2d-to-3d.avs and then load this file in the video player for example 3D Vision Video Player instead of directly loading the video file. Instead of the avatar_trailer_720p.mov you should put the file name to the video you want to convert from 2D to 3D, you can just put the name of the file if it is in the same folder or also include the full path to the file. When asked what stereoscopic format to use for the file you need to choose Side by Side in order for the player to display it correctly, don’t forget to switch to fullscreen with 3D vision Video Player of Stereoscopic Player. As you can see in the script I’m using the simplest and fastest Point resize method in order to achieve the best possible speed, other methods can also be used for better quality, but that will lead to more load on the CPU and can make the framerate too slow tor normal video playback. Even with point resize if you try to use the script on a slow CPU you might still get slower framerate, but this is to be expected, because although the script is quite simple the calculations done on the video are actually quite heavy and they have to be done on each frames a lot of times each second.

As usual if you try the above script please don’t forget to leave your comments, ideas, suggestions etc. This is something intended for more advanced users and as a proof of concept is not optimized for performance or ease of use in any way!

Tags: ·······

9 responses so far ↓

  • 1 ChrisL // Dec 30, 2009 at 02:34

    This is very cool. Thanks for sharing your work

  • 2 Alex // Dec 30, 2009 at 04:37

    I have to give this a try, thanks!

  • 3 LaurentL // Dec 31, 2009 at 08:40

    This seems very cool but after installing avisynth, Reform.dll and launching the script with a test video file i receive the following error message : unexpected (
    are you sure that the script is correct as it is ?

  • 4 Bloody // Dec 31, 2009 at 16:37

    Yes it is working, have you changed the video file name to a clip that you have and is 1280×720?

  • 5 Master DAO // Jan 2, 2010 at 02:29

    Many thanks. All work. The Applause author article.

  • 6 Cheth20 // Jan 5, 2010 at 09:17

    I am kinda new to this…need some help from gurus like u:-) can I get this working on my dell laptop(intel display adapter not nvdia), if yes what glasses would I need..another question is how can I convert the existing normal video to 3D so that I can use colored glasses(cheap ones, cant afford)…have got some cellophane, but does not seem to work….may be I need the software to convert having the same colors as my cellophanes

  • 7 Bloody // Jan 5, 2010 at 15:32

    You can use it with Stereoscopic Player in anaglyph mode (red-cyan) or another color filters depending on what you have, but the effect with anaglyph glasses is not that good.

  • 8 nightsu // May 20, 2010 at 10:03

    #plugins http://web.missouri.edu/~kes25c/TEdgeMaskv09.zip

    f1= ConvertToRGB32(f1,matrix=”Rec601″, interlaced=false)
    fR=RGBAdjust(f1,r=1, g=0, b=0, a=0.0)
    fC=RGBAdjust(f1,r=0, g=1, b=1, a=0.0)
    fS=Merge(fR,fC, weight=0.50)
    Overlay(fS,video2d, x=0, y=0, opacity=1.0, mode=”add”, greymask=true, ignore_conditional=false, pc_range=false)

  • 9 Marcus Venturi // Apr 3, 2015 at 14:54

    I’ve implemented your concept into a plugin for MediaPortal in Direct3D. Works without any performance problems.


    Thank you for work and sharing this information!

Leave a Comment