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 f1=video2d 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!