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
Register FAQ Calendar Today's Posts Search

Reply
 
Thread Tools Search this Thread Display Modes
Old 29th April 2015, 04:29   #41  |  Link
osgZach
Registered User
 
Join Date: Feb 2009
Location: USA
Posts: 676
raffriff42,

That's a pretty neat script (and fast). Although the screen flicker kind of bothers me.. Can it be reduced a little? Or maybe a version with it removed. Also I noticed when I resized and added bars on the sides to maintain aspect ratio, there is a green line on the left hand side of the picture edge. I Don't know if that's from Vdub for some reason or the script tho.

I did find another thread with some stuff too, if anyone finds it interesting.
http://forum.doom9.org/showthread.php?t=156658
osgZach is offline   Reply With Quote
Old 29th April 2015, 05:44   #42  |  Link
raffriff42
Retried Guesser
 
raffriff42's Avatar
 
Join Date: Jun 2012
Posts: 1,373
Thanks, osgZach. Good points. Try this one, it looks a lot better I think:
Code:
LoadPlugin "mt_masktools-26.dll") 
## version a48 required
## http://forum.doom9.org/showthread.php?t=98985

## Last == YV12
return scanlines2(size=2, strength=0.25, flicker=false)

#######################################
## Add scanlines (light & dark horizontal bars) to a video. 
##
## @ size      - 1 to 4; default 2
## @ strength  - 0.0 to 1.0; default 0.25
## @ flicker   - default false
##
function scanlines2(clip C, int "size", float "strength", bool "flicker")
{
    size     = Min(Max(1, Default(size, 2)), 4)
    strength = Min(Max(0.0, Default(strength, 0.25)), 1.0)
    flicker  = Default(flicker, false)

    C 
    A=mt_lutspa(
    \   mode="absolute", 
    \   expr=mt_polish("(((y/(2*"+String(0.25*size)+"))%2)>0)?128+64:128-64"),
    \   u=-128, v=-128
    \ )

    B = (flicker)
    \ ? ScriptClip(A, """(current_frame % 2) > 0 ? Last : Last.FlipVertical""")
    \ : A

    return Overlay(B, opacity=0.25*strength, mode="luma")
}

Last edited by raffriff42; 22nd August 2016 at 03:06. Reason: fix chroma drift; remove StrReplace
raffriff42 is offline   Reply With Quote
Old 29th April 2015, 11:43   #43  |  Link
osgZach
Registered User
 
Join Date: Feb 2009
Location: USA
Posts: 676
That's a bit easier to tweak, thanks

One last question. For some reason if I try to put my resize/addborders calls after this function is called, they do not work. No error is given, it just shows the image at original resolution. Was that intended? I was hoping to see if there was a big difference in applying the script before / after a resize.
osgZach is offline   Reply With Quote
Old 29th April 2015, 13:29   #44  |  Link
raffriff42
Retried Guesser
 
raffriff42's Avatar
 
Join Date: Jun 2012
Posts: 1,373
Quote:
Originally Posted by osgZach View Post
For some reason if I try to put my resize/addborders calls after this function is called, they do not work. No error is given, it just shows the image at original resolution.
That does not happen for me. Please post your script.
raffriff42 is offline   Reply With Quote
Old 29th April 2015, 14:36   #45  |  Link
osgZach
Registered User
 
Join Date: Feb 2009
Location: USA
Posts: 676
Code:
AviSource("whip_000.avi", audio=false)
ConvertToYV12()
## LoadPlugin ("mt_masktools-26.dll") 
## version a48 required
## http://forum.doom9.org/showthread.php?t=98985

## Last == YV12

return scanlines2(size=2, strength=0.75, flicker=false)
LanczosResize(1152,720)
AddBorders(64,0,64,0)

#######################################
## Add scanlines (light & dark horizontal bars) to a video. 
##
## @ size      - 1 to 4; default 2
## @ strength  - 0.0 to 1.0; default 0.25
## @ flicker   - default false
##
function scanlines2(clip C, int "size", float "strength", bool "flicker")
{
    size     = Min(Max(1, Default(size, 2)), 4)
    strength = Min(Max(0.0, Default(strength, 0.25)), 1.0)
    flicker  = Default(flicker, false)

    C ## Last==C
    A=mt_lutspa(
    \   mode="absolute", 
    \   expr=("""(((y/(2*$s))%2)>0) ? 128+64 : 128-64""")
    \      .StrReplace("$s", String(0.25*size))
    \      .mt_polish,
    \   u=-128, v=-128
    \ )

    B = (flicker)
    \ ? ScriptClip(A, """(current_frame % 2) > 0 ? Last : Last.FlipVertical""")
    \ : A

    return Overlay(B, opacity=0.5*strength, mode="softlight")
}

# http://avisynth.nl/index.php/HDColorBars
function StrReplace(string base, string sought, string rep)
{
    pos = FindStr(base, sought)
    return (sought == "") || (pos == 0) \
        ? base \
        : StrReplace( \
            LeftStr(base, pos - 1) + rep + \
            MidStr(base, pos + StrLen(sought)), \
            sought, rep)
}
I only really modified it to comment out the DLL loading (in plugins directory already) and then to add the resize/addborders. But for w/e reason if I move them back before the call to the function, they work.
osgZach is offline   Reply With Quote
Old 29th April 2015, 14:48   #46  |  Link
ndjamena
Registered User
 
Join Date: Sep 2012
Posts: 366
Lose the "return".

I didn't even know you could return from the base of the script. It looks a tad better than "__END__".
ndjamena is offline   Reply With Quote
Old 29th April 2015, 15:14   #47  |  Link
osgZach
Registered User
 
Join Date: Feb 2009
Location: USA
Posts: 676
thank you
osgZach is offline   Reply With Quote
Old 29th April 2015, 17:23   #48  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Quote:
Originally Posted by ndjamena View Post

I didn't even know you could return from the base of the script. It looks a tad better than "__END__".
The functionality of Return and __END__ is a little different.
Return allows to return a named clip eg 'myclip' rather than default Last clip, and is needed if the final function call before the end of script does not explicitly or implicitly set Last clip.
It (return) also allows you to return early where you want to temporarily disable some following lines of script.

__END__, makes anything following it COMMENT.
Below will produce an error (EDIT: due to ',' COMMA), try remove '#' hash comment (no error).
Code:
return Colorbars

#__END__
,
EDIT: Can also use C style comments eg
Code:
return Colorbars

/*
,    # No error
*/
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 29th April 2015 at 20:59.
StainlessS is offline   Reply With Quote
Old 30th April 2015, 01:34   #49  |  Link
osgZach
Registered User
 
Join Date: Feb 2009
Location: USA
Posts: 676
I did 2 tests. I'm a little partial to the second one at this point (scanlines after resizing). All I have to do now is see if I can tweak the brightness or gamma to reduce some of the washed out look.

Test 1 - Resize after Scanlines

Test 2 - Resize before Scanlines

Chrome / 720p / 60fps for best experience.
osgZach is offline   Reply With Quote
Old 30th April 2015, 05:38   #50  |  Link
raffriff42
Retried Guesser
 
raffriff42's Avatar
 
Join Date: Jun 2012
Posts: 1,373
Looks great! However I find it a bit difficult to watch for more than a few seconds. Maybe with lower strength?

When using the effect after resizing, suggest setting the scanline size to match the native pixel size, for most realistic effect IMHO.

Regarding your brightness issue, here's yet another version with a brightness adjustment, and a few other minor changes.
Code:
# http://manao4.free.fr/mt_masktools.html
## version a48 required
LoadPlugin("mt_masktools-26.dll")

# http://forum.doom9.org/showthread.php?p=1719737#post1719737
#######################################
## Add scanlines (light & dark horizontal bars) to a video. 
##
## @ size      - 1 to 16; default 2 (scanline size)
## @ strength  - 0.0 to 1.0; default 0.25 (scanline strength)
## @ bright    - min -128, max +128; default 0 (brightness adjustment)
## @ flicker   - default false (if true, swap light & dark lines on each frame)
##               (only allowed if bright == 0)
##
function scanlines2(clip C, int "size", float "strength", int "bright", bool "flicker")
{
    Assert(IsYV12(C),
    \   "scanlines2: source must be YV12")

    size     = Min(Max(1, Default(size, 2)), 16)
    strength = Min(Max(0.0, Default(strength, 0.25)), 1.0)
    bright   = Min(Max(-128, Default(bright, 0)), +128)
    flicker  = Default(flicker, false)

    C ## Last==C
    A=mt_lutspa(
    \   mode="absolute", 
    \   expr=("""(((y/(2*$s))%2)>0) ? 128+64+$b : 128-64+$b""")
    \      .StrReplace("$s", String(0.25*size))
    \      .StrReplace("$b", String(bright))
    \      .mt_polish,
    \   u=-128, v=-128
    \ )

    B = (flicker && bright==0)
    \ ? ScriptClip(A, """(current_frame % 2) > 0 ? Last : Last.Invert""")
    \ : A

    return Overlay(B, opacity=0.5*strength, mode="softlight")
}

# http://avisynth.nl/index.php/HDColorBars
function StrReplace(string base, string sought, string rep)
{
    pos = FindStr(base, sought)
    return (sought == "") || (pos == 0) \
        ? base \
        : StrReplace( \
            LeftStr(base, pos - 1) + rep + \
            MidStr(base, pos + StrLen(sought)), \
            sought, rep)
}
(Sorry if hijacking the topic. Maybe discussion of this script belongs in a new thread?)

Last edited by raffriff42; 30th April 2015 at 13:03.
raffriff42 is offline   Reply With Quote
Old 30th April 2015, 13:43   #51  |  Link
osgZach
Registered User
 
Join Date: Feb 2009
Location: USA
Posts: 676
(If a mod would like to split this off into new thread that would be cool)

What do you mean by "difficult to watch" though? I'll admit personally my scanline preferences are a little weird. I like having smallish looking ones. I'll give the new version a try in a little while. Thanks
osgZach is offline   Reply With Quote
Old 30th April 2015, 16:53   #52  |  Link
cretindesalpes
͡҉҉ ̵̡̢̛̗̘̙̜̝̞̟̠͇̊̋̌̍̎̏̿̿
 
cretindesalpes's Avatar
 
Join Date: Feb 2009
Location: No support in PM
Posts: 712
You can also disable most of the crt_display features and keep the scanline effect. For example:
Code:
crt_display (2, 2, scandist=1.5, phosphor=false, cromaclear=0)
You can play with the scandist parameter to change the effect strength.
Then resize to the target frame size. However the scanlines will be correctly preserved only if it is a vertical upscale, not a downscale.

The script will be faster than with all the features enabled. The good thing is that colors and contrast will be left almost intact.
__________________
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 30th April 2015, 17:24   #53  |  Link
osgZach
Registered User
 
Join Date: Feb 2009
Location: USA
Posts: 676
Quote:
Originally Posted by cretindesalpes View Post
You can also disable most of the crt_display features and keep the scanline effect. For example:
Code:
crt_display (2, 2, scandist=1.5, phosphor=false, cromaclear=0)
You can play with the scandist parameter to change the effect strength.
Then resize to the target frame size. However the scanlines will be correctly preserved only if it is a vertical upscale, not a downscale.

The script will be faster than with all the features enabled. The good thing is that colors and contrast will be left almost intact.
I'm not so sure.. I changed the scaling numbers from "2" to "1.7" to get the needed 1152x720 output, so I wouldn't have to downscale it.

But the end result is the same as if I had not changed from "2" and then applied a downsize. Scanlines still look funky

The speed did improve quite a bit, but in terms of the effect + speed I think raffriff's script is a pretty good contender as it is orders of magnitudes faster.

Last edited by osgZach; 30th April 2015 at 17:26.
osgZach is offline   Reply With Quote
Old 30th April 2015, 18:12   #54  |  Link
cretindesalpes
͡҉҉ ̵̡̢̛̗̘̙̜̝̞̟̠͇̊̋̌̍̎̏̿̿
 
cretindesalpes's Avatar
 
Join Date: Feb 2009
Location: No support in PM
Posts: 712
What you actually see as funky scanlines is pure aliasing left by imperfect resizers (from a spectral content PoV). If you downsize, the scanlines should disappear because their frequencies are over the new Nyquist frequency. This happens if you use a resizer with a large kernel, for example BlackmanResize(w, h, taps=16).
__________________
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 16th November 2015, 00:55   #55  |  Link
NightSprinter
Registered User
 
Join Date: Sep 2014
Posts: 13
Been a while since I responded to this thread, but outside of upgrading to a beefier Core i7 and more than 6GB of memory what else can I do to make loading video with the script and rendering the final video faster and not hog so much memory? I've ran into some still high-cpu usage even with MT mode on, and even sometimes I just get out of memory errors trying to render a 15-second clip of Pac-Mania (which is also rotated so it's in proper vertical orientation) to a final video.
NightSprinter is offline   Reply With Quote
Old 16th November 2015, 03:23   #56  |  Link
creaothceann
Registered User
 
Join Date: Jul 2010
Location: Germany
Posts: 357
Quote:
Originally Posted by NightSprinter View Post
I've ran into some still high-cpu usage even with MT mode on
High CPU usage is good, imo (and especially expected when using multithreading). It means that your encoding is completed sooner.
creaothceann is offline   Reply With Quote
Old 16th November 2015, 03:27   #57  |  Link
NightSprinter
Registered User
 
Join Date: Sep 2014
Posts: 13
But should I expect an out of memory error even for 6GB of memory? I understand the memory usage for video editing rises exponentially when the video size gets bigger (and moreso if the video and audio are in raw format). It's just all I'm doing is trying to maybe render it at a final resolution (after rotation) of 720x960 with the effects. I'm going to guess that for my current system rendering a 20-minute video will be an all-day process?
NightSprinter is offline   Reply With Quote
Old 16th November 2015, 04:29   #58  |  Link
NightSprinter
Registered User
 
Join Date: Sep 2014
Posts: 13
Oh this is sweet. With the 64-bit AVISynth+ (though I'm not sure what plugins exactly will need the MT options), my CPU usage in 64-bit VirtualDub for rendering the video is topping out at 60% on my i7-920. Not getting any "out of memory" errors so far. I am going to have to leave the rather shoddy gameplay of mine to test this filter chain out to run all night to render (6076 frames, and time to complete already over 5 hours). I can upload a YT video or post it to my Dropbox afterwards to see the final result.

[Edit] Wow, I guess even my current system seems to be quite weak. Just this four minute clip of some brief gameplay (PS1 Arcade's Greatest Hits: The Midway Collection 1, BurgerTime) is taking a total of nearly 30 hours to render with the effects chain. At least the 64-bit VDub and AVISynth+ plugins are letting me render it. Going to see if I can't find 64-bit versions of the encoders.

Last edited by NightSprinter; 16th November 2015 at 16:48. Reason: Add info regarding the amount of time rendering takes.
NightSprinter is offline   Reply With Quote
Old 18th November 2015, 17:49   #59  |  Link
NightSprinter
Registered User
 
Join Date: Sep 2014
Posts: 13
The script's working more and more for me now. It doesn't seem to get along with multithreading too well (especially if working with huge aspect ratio multiples and/or the ppp setting at higher than 1, or even setting the prefetch parameter in any manner).

If need-be, I can upload my script in order to debug. I can also upload the gameplay clip I recorded that I'm using the script on.
NightSprinter is offline   Reply With Quote
Old 20th November 2015, 15:47   #60  |  Link
NightSprinter
Registered User
 
Join Date: Sep 2014
Posts: 13
So, since all of this is stuck at single-threaded (settings I used take literally a week with AVISynth+ 64-bit and 64-bit VDub), I'd thought I'd just take a screenshot to show how nice very extreme phosphor mask settings can get. I'll also post my crt_display line in said script.



Code:
Import ("crt_display.avsi")
#Import("dotcrawlplus.avsi")
SetFilterMTMode("DEFAULT_MT_MODE", 2)
SetFilterMTMode("AVISource", 3)
LoadPlugin ("C:\AviSynth+\plugins64\mt_masktools-26-x64.dll")
AVISource("C:\Amarectv310\amarec(20151117-1402).avi")
## version a48 required
## http://forum.doom9.org/showthread.php?t=98985
crop (50,0,640,240)
pointresize(320,240)
converttorgb()
ar = 1.0/1.0
crt_display (6*ar, 6, ppp=3*ar, sharpv=0.75, sharph=0.25, blurh=1.5, scandist=1, cutoff=0.8, gamma=2, glowgain=0.125, halgain=0.03, contrast=3, phosphor=true, maskpp=3, beamshape=1.0, vcs=0.25, cromaclear=1, voff=0, pgrid=true, halrange=3, mix=2)
pointresize(960,720)
#converttoyv12()
#dotcrawlpreset("medium")
#prefetch(2)
Note that I had to comment out prefectch. All the masktools dll files I'm linked to for AVISynth+ are not compiled for MT support.
NightSprinter is offline   Reply With Quote
Reply

Tags
crt, emulation, phosphor, scanline


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 22:28.


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