Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Usage

Reply
 
Thread Tools Search this Thread Display Modes
Old 5th June 2014, 21:55   #1  |  Link
cretindesalpes
͡҉҉ ̵̡̢̛̗̘̙̜̝̞̟̠͇̊̋̌̍̎̏̿̿
 
cretindesalpes's Avatar
 
Join Date: Feb 2009
Location: No support in PM
Posts: 712
CRT emulation with scanline and phosphor effects

Download: crt_display v1.0

This function emulates a CRT display using aperture grille (Trinitron) or Cromaclear technologies. It is slow but gives interesting results. Could be nice to chain after a NTSC defect emulator like dotcrawlplus. It implements various features like:
  • Works at any (non-integer) upscaling factor
  • Various ways of adjusting the scanline thickness and beam shape
  • Low-pass filtering of the input signal
  • Specific gamma target
  • Beam glow
  • Optional colored phosphor effect and shadow mask
  • Colors shift caused by beam misalignment
  • Automatic contrast adjustment
  • Halation
  • Very large upscale is possible, showing the grid of phosphors.

Requirements: Dither 1.26.0 or above and its dependencies, Avisynth 2.6, RGB colorspace.

Detailed instructions in the .avsi file. Prototype:
Code:
Function crt_display (clip src, float sw, float sh, float "voff", float "ppp",
\	float "cutoff", float "scandist", float "sharpv", float "sharph",
\	float "blurh", float "glowgain", float "glowh", float "glowv",
\	float "glowsens", float "contrast", float "gamma", float "softclip",
\	float "mix", float "beamshape", bool "phosphor", bool "pgrid",
\	float "vcs", float "cromaclear", float "maskpp", float "gainb",
\	float "halgain", float "halrange", string "pixel_type")

Examples of real NTSC footage with aperture grille (left) and Cromaclear shadow mask (right):

Code:
ar = 10.0 / 11.0
crt_display (2*ar, 2, ppp=1*ar, blurh=2.0) # Left
crt_display (2.5*ar, 2.5, ppp=1.25*ar, maskpp=1.25, cromaclear=1.0, voff=0.25) # right
Make sure to check the pictures at their original size.
Note that the scanline density (480) makes difficult to reproduce the Cromaclear effect in a limited resolution and exhibits unwanted pattern effects. We would need at least three lines per scanline to give it a better look.

But it works very well for upscaling 240p content, especially old-school videogame captures:

Sources, point-resized:

I don’t know at which gamma these pictures should be viewed so I kept them untouched like if they were in standard sRGB.

Cromaclear display type:

Code:
ar = 8.0 / 7.0
crt_display (5*ar, 5, ppp=2.5*ar, blurh=1.0, maskpp=2.5, cromaclear=1, scandist=1.5, cutoff=0.9, glowgain=0.125, halgain=0.03)
Aperture grille display type:

Code:
crt_display (5*ar, 5, ppp=2.5*ar, blurh=0.75, scandist=1, cutoff=0.9, glowgain=0.125, halgain=0.03)
The scanline effect and variable-width beam could have been more pronounced just by adding sharpv=2, beamshape=2.

Simple scanlines without phosphor effect:

Code:
crt_display (5*ar, 5, ppp=2.5*ar, blurh=1.0, maskpp=2.5, phosphor=false, scandist=3, cutoff=0.8, glowgain=1.0, glowh=6, glowv=0, halgain=0.03, sharpv=2)
This is just insane but gives an idea about how it could look with extreme settings.

More screenshots here. Default settings are generally OK, but tweaking the parameters can improve the results a lot.

My 15 kHz CRT is gone for a long time and I only have half-decent monitor photos for reference, so any advice based on real CRTs is welcome to improve the emulation.
__________________
dither 1.28.1 for AviSynth | avstp 1.0.4 for AviSynth development | fmtconv r30 for Vapoursynth & Avs+ | trimx264opt segmented encoding

Last edited by cretindesalpes; 7th September 2018 at 17:04. Reason: Fixed the gallery url
cretindesalpes is offline   Reply With Quote
Old 5th June 2014, 23:41   #2  |  Link
Motenai Yoda
Registered User
 
Motenai Yoda's Avatar
 
Join Date: Jan 2010
Posts: 709
It's look very like my old Sony Triniton!!!

But Triniton have also a defect, there were some horizontal gray lines.

http://www.dansdata.com/sg400.htm
__________________
powered by Google Translator

Last edited by Motenai Yoda; 5th June 2014 at 23:44.
Motenai Yoda is offline   Reply With Quote
Old 6th June 2014, 00:07   #3  |  Link
TheSkiller
Registered User
 
Join Date: Dec 2007
Location: Germany
Posts: 632
Impressive!
Being a CRT expert and lover I definitely have to say this is the most authentic CRT simulation I've seen. Goes very nice especially with old games. I'll have some fun with this, even though I have plenty real CRTs right here.


Edit: One thing I noticed is the scanlines in your simulation are more pronounced with the Cromaclear setting compared to the Trinitron setting. Well, in my experience, and I have a Trinitron as well as a shadow mask CRT side by side here, the scanlines are generally more pronounced with Trinitrion masks and slightly less with shadow masks. This is also commonly known among retro gamer "CRT fetishists" on the internet. Trinitrons have slightly more pronounced scanlines compared to shadow masks.

Last edited by TheSkiller; 6th June 2014 at 00:18.
TheSkiller is offline   Reply With Quote
Old 6th June 2014, 00:24   #4  |  Link
cretindesalpes
͡҉҉ ̵̡̢̛̗̘̙̜̝̞̟̠͇̊̋̌̍̎̏̿̿
 
cretindesalpes's Avatar
 
Join Date: Feb 2009
Location: No support in PM
Posts: 712
TheSkiller:

Thanks. I agree with the Cromaclear/Trinitron mismatch. I just put different settings to show the versatility of the function, of course it’s possible to increase the scanline effect with the Trinitron.

Motenai Yoda:

Indeed, I haven’t included the “damping wire” effect. I’m not sure if it’s a wanted feature…
__________________
dither 1.28.1 for AviSynth | avstp 1.0.4 for AviSynth development | fmtconv r30 for Vapoursynth & Avs+ | trimx264opt segmented encoding
cretindesalpes is offline   Reply With Quote
Old 6th June 2014, 03:52   #5  |  Link
Reel.Deel
Registered User
 
Join Date: Mar 2012
Location: Texas
Posts: 1,664
This is nice, it reminds me of much simpler times.
Kudos cretindesalpes.
Reel.Deel is offline   Reply With Quote
Old 6th June 2014, 04:29   #6  |  Link
Lyris
Registered User
 
Join Date: Sep 2007
Location: Europe
Posts: 602
Outstanding attention to detail. That really puts the crummy "Old TV effect" in NLEs to shame.
Lyris is offline   Reply With Quote
Old 6th June 2014, 07:17   #7  |  Link
creaothceann
Registered User
 
Join Date: Jul 2010
Location: Germany
Posts: 357
Here's another thread about CRT simulation.

Btw. I get this error (crt_display.avsi is in the plugins folder)... any idea what could be the cause? I have this version and the plugins.
creaothceann is offline   Reply With Quote
Old 6th June 2014, 08:33   #8  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,431
Quote:
Originally Posted by creaothceann View Post
I get this error (crt_display.avsi is in the plugins folder)... any idea what could be the cause? I have this version and the plugins.
You need an updated MaskTools fully compatible with 2.6a4 - see here.
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 6th June 2014, 17:55   #9  |  Link
creaothceann
Registered User
 
Join Date: Jul 2010
Location: Germany
Posts: 357
Mmmh...
creaothceann is offline   Reply With Quote
Old 6th June 2014, 21:14   #10  |  Link
Motenai Yoda
Registered User
 
Motenai Yoda's Avatar
 
Join Date: Jan 2010
Posts: 709
Quote:
Originally Posted by creaothceann View Post
U must delete old mt dlls
__________________
powered by Google Translator
Motenai Yoda is offline   Reply With Quote
Old 17th June 2014, 13:21   #11  |  Link
osgZach
Registered User
 
Join Date: Feb 2009
Location: USA
Posts: 676
This is so awesome...

It would be sweet if someone could turn these particular effects into shaders (or provide SweetFX/etc. settings that can emulate them)
osgZach is offline   Reply With Quote
Old 22nd September 2014, 13:48   #12  |  Link
NightSprinter
Registered User
 
Join Date: Sep 2014
Posts: 13
To the author of this script/OP of the thread, I know I asked this via e-mail, but is there any way to help with the speed for rendering a video with this? Rendering to an MP4 file on my machine takes sometimes upwards of a day for a five minute recording.
NightSprinter is offline   Reply With Quote
Old 22nd September 2014, 22:03   #13  |  Link
cretindesalpes
͡҉҉ ̵̡̢̛̗̘̙̜̝̞̟̠͇̊̋̌̍̎̏̿̿
 
cretindesalpes's Avatar
 
Join Date: Feb 2009
Location: No support in PM
Posts: 712
Yes I saw your email but the previous week was quite intense for me IRL and I hadn’t the time to reply. Anyway I’m not sure about what is slow in the script, and if it can be optimized. I’ll try to benchmark it and narrow down the slowest parts in the next days but I cannot guarantee that I can come with significant speed improvement.

EDIT: I just found that vertical resizing/convolution in Dither_resize16 was not multi-threaded… Got a 75 % speed-up just by fixing it. More later.
__________________
dither 1.28.1 for AviSynth | avstp 1.0.4 for AviSynth development | fmtconv r30 for Vapoursynth & Avs+ | trimx264opt segmented encoding

Last edited by cretindesalpes; 23rd September 2014 at 12:47.
cretindesalpes is offline   Reply With Quote
Old 23rd September 2014, 18:53   #14  |  Link
cretindesalpes
͡҉҉ ̵̡̢̛̗̘̙̜̝̞̟̠͇̊̋̌̍̎̏̿̿
 
cretindesalpes's Avatar
 
Join Date: Feb 2009
Location: No support in PM
Posts: 712
As stated in my previous edited post, updating Dither to v1.26.5 will give a significant speed boost to crt_display. You can also maximize the CPU usage and double again the fps throughput by splitting the source video into 2 or 3 parts and encode them simultaneously.

These are probably the only large speed improvement left without altering the quality and accuracy of the emulation. I think implementing a native Dither_lut16 implementation (instead of a wrapper function around several mt_lutxy calls) could help a little too, as the function is heavily used.

Next, there’s a great amount of finetuning to do (like cutting the number of taps to the strict minimum for the gaussian blurs, or reducing the vertical oversampling of the beam), but this is a lot of work for little results.
__________________
dither 1.28.1 for AviSynth | avstp 1.0.4 for AviSynth development | fmtconv r30 for Vapoursynth & Avs+ | trimx264opt segmented encoding
cretindesalpes is offline   Reply With Quote
Old 4th October 2014, 18:50   #15  |  Link
NightSprinter
Registered User
 
Join Date: Sep 2014
Posts: 13
Thanks greatly for the reply. As I'm using AVISynth 2.6, what would you suggest further to improve? I've updated the dither plugins as suggested, and you've mentioned something about multi-threading. If it helps, here are my specs as well:

CPU: Intel Core i7-920 @2.8GHZ overclock
RAM: Corsair XMS3 DDR3-10666
GPU: PNY GeForce GTS-450
Motherboard: Gigabyte X58A-UD3Rv1
PSU: Corsair TX750
HDD: 3x500GB Seagate Barracuda 7200rpm
Capture Card 1: Startech PEXHDCAP (for anything above composite or s-video)
Capture Card 2: Pinnacle Dazzle DVC-101

[Edit] Here's an error that shows up all too often for me. I wonder what I'm doing wrong?
Attached Images
 

Last edited by NightSprinter; 5th October 2014 at 01:15. Reason: Add error screenshot
NightSprinter is offline   Reply With Quote
Old 7th October 2014, 00:32   #16  |  Link
foxyshadis
ангел смерти
 
foxyshadis's Avatar
 
Join Date: Nov 2004
Location: Lost
Posts: 9,558
Quote:
Originally Posted by NightSprinter View Post
[Edit] Here's an error that shows up all too often for me. I wonder what I'm doing wrong?
Use this version of Masktools, which should help speed a bit as well.
foxyshadis is offline   Reply With Quote
Old 9th October 2014, 03:39   #17  |  Link
NightSprinter
Registered User
 
Join Date: Sep 2014
Posts: 13
That seemed to work, though I guess even 6GB of memory may not even be enough to render the 240p deinterlaced image up to 1280x960 in VirtualDub. I had to use AVIDemux and its AVSProxy companion to render the video I had set up in my script.
NightSprinter is offline   Reply With Quote
Old 9th October 2014, 08:58   #18  |  Link
cretindesalpes
͡҉҉ ̵̡̢̛̗̘̙̜̝̞̟̠͇̊̋̌̍̎̏̿̿
 
cretindesalpes's Avatar
 
Join Date: Feb 2009
Location: No support in PM
Posts: 712
With a regular Avisynth 2.6 version (32-bit single-threaded) you shouldn’t need such a huge RAM amount. Playing back a 224p to 1080p conversion in VirtualDub uses only 700 MB here. What is your script?
__________________
dither 1.28.1 for AviSynth | avstp 1.0.4 for AviSynth development | fmtconv r30 for Vapoursynth & Avs+ | trimx264opt segmented encoding
cretindesalpes is offline   Reply With Quote
Old 9th October 2014, 12:59   #19  |  Link
NightSprinter
Registered User
 
Join Date: Sep 2014
Posts: 13
My script looks like this (as I'm using the MT version of AVISynth, and did some deinterlacing of footage captured with a Dazzle at 640x480i)

Code:
SetMemoryMax(512)
SetMTMode(3)
SetMTMode(2)
Import("crt_display.avsi")
AviSource("converttorgb.avi")
SeparateFields(AssumeTFF)
#PointResize(640,480)
#Scanlines(STRENGTH=0)
ar = 1.0 / 1.0 
crt_display (2*ar, 4, ppp=2.5*ar, blurh=1.0, maskpp=2.5, cromaclear=1, scandist=1.5, cutoff=0.9, glowgain=0.125, halgain=0.03)
The render takes an entire night's worth of time via the AVIDemux program setup I have in order to render the final MP4 video.
NightSprinter is offline   Reply With Quote
Old 27th April 2015, 02:34   #20  |  Link
osgZach
Registered User
 
Join Date: Feb 2009
Location: USA
Posts: 676
Anyone got any idea what would cause this?

I'd really like to try this script on some DOSBox captures

osgZach is offline   Reply With Quote
Reply

Tags
crt, emulation, phosphor, scanline

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 00:37.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.