Posts for nanogyth

1 2
7 8 9 10
Experienced Forum User, Published Author, Player (65)
Joined: 4/21/2011
Posts: 232
What are you using to decode? An 8bit decoder won't throw an error, but will produce "crap". Is that what you're referring to? http://img841.imageshack.us/img841/1557/misumkvsnapshot00032011.jpg
Experienced Forum User, Published Author, Player (65)
Joined: 4/21/2011
Posts: 232
Why 10 bit YUV compresses better than 8 bit YUV in x264 is complex and I don't understand it.
It is easiest for me to think of it in terms of banding. A color gradient in 8 bit has banding because we can see the difference from one color to the next. To fix this in 8 bit you can apply dithering, a checkerboard pattern which gives an appearance of a greater number of colors. But the pattern is hard to compress, so you lose it if you don't up the bitrate. 10 bit has more colors, so it doesn't need dithering, so you can produce the same visual effect in less bits. (you don't have a 10bit monitor so the dithering is still there, but it is added after decompression by the codec or your graphics card) Chroma Subsampling Dropping most of the color data cuts the raw file size/bandwidth in half. This works ok because color data is mostly redundant. But video compression is great at reducing exactly the type of redundancy present in chroma data. So for compressed video you can have full chroma at very little increase to bitrate.
Experienced Forum User, Published Author, Player (65)
Joined: 4/21/2011
Posts: 232
Don't shake the mother brain
clip_a
assumefps(60)
trim(392,622)
src=last

converttoyv12
mt_edge("-1 0 0 0 1 0 0 0 0", thY1=0, thY2=0)
om1=selectevery(4,-1)
e0=selectevery(4,0)
o1=selectevery(4,1)
e2=selectevery(4,2)
diff=mt_logic(e0,o1,mode="xor")
s1=mt_logic(om1,o1,mode="xor")
s2=mt_logic(e0,e2,mode="xor")
same=mt_logic(s1,s2,mode="or").mt_invert
mask=mt_logic(diff,same,mode="and").mt_expand.mt_expand.mt_deflate(u=-128,v=-128).converttorgb32

   # #   \  ##
    # #  /    ##
# -1012    -1)!2
sm1=src.selectevery(4,-1)
s0=src.selectevery(4,0)
s1=src.selectevery(4,1)
s2=src.selectevery(4,2)
n0=layer(s0,s1.mask(mask))
n1=layer(s1,s0.mask(mask))

new=interleave(sm1,n0,n1,s2).trim(1,0)
stackhorizontal(src,new)

pointresize(width * 2, height *2)
ConvertToYV24(chromaresample="point", matrix=("PC.601") )
ConvertToYV12(chromaresample="point", matrix=("PC.601") )
Experienced Forum User, Published Author, Player (65)
Joined: 4/21/2011
Posts: 232
Being able to work on just the part of the scene that is flickering is nice (when it works).
Experienced Forum User, Published Author, Player (65)
Joined: 4/21/2011
Posts: 232
creaothceann wrote:
What I noticed is that Deblink doesn't show shaking in the exploding-Mother-Brain scene of the intro, so there's still no single algorithm for everything.
Yah, frustration over that scene is why I gave up working on this stuff the last time. It is in black/white (so color is no help for matching), the intensity changed with time, and the shake pattern skips a frame in the middle =_=
Experienced Forum User, Published Author, Player (65)
Joined: 4/21/2011
Posts: 232
If {1 frame off, 1 frame on} at 60 fps looks like transparency to you, your monitor sucks.
Yes, that is definitely a possibility =_=
creaothceann wrote:
nanogyth wrote:
Still plenty of artifacts, but I think it is a step in the right direction
Do you think they're too obvious or that you can fix them? If not then it could be added to the site as an alternative to 50/50 blending and TASBlend.
It is an imperfect solution to a hard problem. A useful tool that can complement the others, but not something which should be blindly applied in all situations. First thing to add is functionality similar to TASblend
function deblink2(clip clp, float "ratio"){
    ratio    = default(ratio, 2.0 / 3) 
    opacity1 = round((1 - ratio) * 257) 
    opacity2 = round((    ratio) * 257) 

    # blend on the frame it blinks in and out
    blink=clp.ng_blinkmask_new
    blink2=mt_logic(blink.selectevery(1,-1), blink, mode="or").converttorgb32
    even = layer(clp, clp.trim(1,0).mask(blink2), level=opacity1)
    odd = layer(clp, clp.trim(1,0).mask(blink2), level=opacity2)
    interleave(even.selectevery(4,0),even.selectevery(4,1),
\              odd.selectevery(4,2),odd.selectevery(4,3))
}
That seems to work pretty well. Can slide between no flicker at .5 and full flicker at 1.0 Then there are some issues with the blinkmask not picking up all the motion. (roadrunners toes get chopped off)
function deblink3(clip clp, float "ratio", int "radius"){
    radius   = default(radius, 1) 
    ratio    = default(ratio, 2.0 / 3) 
    opacity1 = round((1 - ratio) * 257) 
    opacity2 = round((    ratio) * 257) 

    # blend on the frame it blinks in and out
    blink=clp.ng_blinkmask_new
    blink2=mt_logic(blink.mt_expand(mode=mt_circle(radius)), clp.shake, mode="and")
    blink3=mt_logic(blink, blink2, mode="or")
    blink4=mt_logic(blink3.selectevery(1,-1), blink3, mode="or")
    masked_clp=clp.trim(1,0).mask(blink4.converttorgb32)
    even = layer(clp, masked_clp, level=opacity1)
    odd = layer(clp, masked_clp, level=opacity2)
    interleave(even.selectevery(4,0),even.selectevery(4,1),
\              odd.selectevery(4,2),odd.selectevery(4,3))
}

function shake(clip c){
    e0=c.selectevery(1,0)
    o1=c.selectevery(1,1)
    e2=c.selectevery(1,2)

    mt_logic(ng_diff(e0,o1),ng_same(e0,e2),mode="and")
}

function ng_diff(clip A, clip B, int "thr"){
    thr=default(thr,0)
    TAD=ng_TAD(A,B)
    return mt_binarize(TAD, threshold=thr)
}

function ng_same(clip A, clip B, int "thr"){
    thr=default(thr,0)
    TAD=ng_TAD(A,B)
    return mt_binarize(TAD, threshold=thr, upper=true)
}

function ng_TAD(clip A, clip B){
    R=ng_AD(A  .showRed("YV12"),B  .showRed("YV12"))
    G=ng_AD(A.showGreen("YV12"),B.showGreen("YV12"))
    B=ng_AD(A .showBlue("YV12"),B .showBlue("YV12"))
    return ng_plus(R, ng_plus(G, B))
}

function ng_AD(clip A, clip B){
    return mt_lutxy(A,B,"x y - abs")
}

function ng_plus(clip A, clip B){
    return mt_lutxy(A,B,"x y +")
}
And so I end up with something like this http://www.youtube.com/watch?v=sQIViVif90g roadrunner with less deflicker
stackhorizontal(last.deblink,last.deblink3(radius=2)).changefps(30)
pointresize(width * 2, height *2)
ConvertToYV24(chromaresample="point", matrix=("PC.601") )
ConvertToYV12(chromaresample="point", matrix=("PC.601") )
Experienced Forum User, Published Author, Player (65)
Joined: 4/21/2011
Posts: 232
natt wrote:
but I think the expected user viewing result with a lot of these flicker patterns was in fact flicker.
To me, at 60fps, "on one, off one" looks like transparency and "on two, off two" looks like flickering. Changing both to "on one, off one" at 30fps is the wrong thing to aim for IMO. If you download the roadrunner clip it has the three side by side (on/off, 60fps, blended). I think the blended looks more like the 60fps, would you disagree?
Experienced Forum User, Published Author, Player (65)
Joined: 4/21/2011
Posts: 232
Use of flickering in games is usually used to simulate transparency, not flickering. That works at 60fps, but at 30fps it isn't right. My idea was to blend one frame effects into two frame effects. Making a 60fps clip which is safe to reduce to 30fps. Still plenty of artifacts, but I think it is a step in the right direction, do you agree? http://www.youtube.com/watch?v=tjrRqrOQ1O8 http://www.mediafire.com/?3l6x53xq9999q8m
function deblink(clip clp){
    # blend on the frame it blinks in and out
    blink=clp.ng_blinkmask_new
    blink2=mt_logic(blink.selectevery(1,-1), blink, mode="or").converttorgb32
    layer(clp, clp.trim(1,0).mask(blink2), level=127)
}

function ng_blinkmask_new(clip c,int "ml"){
    ml=default(ml,128)
    src=c.ConvertToYv12
    super=MSuper(src, pel=1)
    fvec =MAnalyse(super, isb=false, blksize=4)
    bvec =MAnalyse(super, isb=true , blksize=4)
    fmask=Mmask(src,fvec,kind=1,ml=ml).mt_binarize(u=-128,v=-128)
    bmask=Mmask(src,bvec,kind=1,ml=ml).mt_binarize(u=-128,v=-128)

    eo0_to =fmask.selectevery(2,1)
    oe_from=bmask.selectevery(2,1)
    front  =mt_logic(eo0_to,oe_from,mode="and")

    oe_to  =fmask.selectevery(2,2)
    eo_from=bmask.selectevery(2,2)
    back   =mt_logic(oe_to,eo_from,mode="and")

    ee_src=src.selecteven
    ee_super=MSuper(ee_src, pel=1)
    ee_fvec =MAnalyse(ee_super, isb=false, blksize=4)
    ee_bvec =MAnalyse(ee_super, isb=true , blksize=4)
    ee_fmask=Mmask(ee_src,ee_fvec,kind=1,ml=ml).mt_binarize(u=-128,v=-128)
    ee_bmask=Mmask(ee_src,ee_bvec,kind=1,ml=ml).mt_binarize(u=-128,v=-128)

    ee_to  =ee_fmask.trim(1,0)
    ee_from=ee_bmask
    ee     =mt_logic(ee_to,ee_from,mode="or")

    oo_src=src.selectodd
    oo_super=MSuper(oo_src, pel=1)
    oo_fvec =MAnalyse(oo_super, isb=false, blksize=4)
    oo_bvec =MAnalyse(oo_super, isb=true , blksize=4)
    oo_fmask=Mmask(oo_src,oo_fvec,kind=1,ml=ml).mt_binarize(u=-128,v=-128)
    oo_bmask=Mmask(oo_src,oo_bvec,kind=1,ml=ml).mt_binarize(u=-128,v=-128)

    oo_to  =oo_fmask.trim(1,0)
    oo_from=oo_bmask
    oo     =mt_logic(oo_to,oo_from,mode="or")

    #to e0-o1, from o1-e2, nothing e0-e2
    even_blink=mt_logic(front,ee.mt_invert,mode="and")

    #to o1-e2, from e2-o3, nothing o1-o3
    odd_blink =mt_logic(back,oo.mt_invert,mode="and")

    blinkmask=interleave(even_blink, odd_blink)
    return blinkmask
}
more samples Gunstar Heros Street Fighter SuperC Mega Turrican Super Metroid
Experienced Forum User, Published Author, Player (65)
Joined: 4/21/2011
Posts: 232
Why not have lossless RGB as the primary encode? The quality would be better, and it would fail properly if you didn't have it setup right. I've heard lossless is smaller than x264 compressed on some games, is that generally true?
Post subject: Encoding Tools
Experienced Forum User, Published Author, Player (65)
Joined: 4/21/2011
Posts: 232
These are some tools I put together when I was hacking around at encoding final fantasy viii. I'm sharing in case someone else might find them useful, or someone can give me some tips on my usage. (Thanks to Dark Kobold for making the TAS) 1. PSXjin outputs files at several resolutions. In order to join the files in Avisynth they need to have the same resolution/colorspace/framerate. So I made a source function to crop/pad them to match.
function customsource(string X){
    avisource(X).converttorgb32
    w=width
    h=height
    (w==368) ? crop(8,0,0,0) : nop()
    (w==320) ? addborders(20,0,20,0) : nop()
    (h==224) ? addborders(0,8,0,8) : \
        (h==216) ? addborders(0,12,0,12) : spline36resize(360,240)
}
2. Most of the game is 240p, but the disc change scenes are 480i. Square seemed to intentionally mess up the interlacing here, but I think it looks awful, so I matched the same intensity fields.
avisource("M:\ff8_avi4\000_disc4-640x480.avi")
crop(31,38,580,406)
separatefields

#2 fields of Bright, 6 of medium, 4 of dim
#e e e e e e
#B;;.;.;B.;.;
#      BB;;..
#      0769A5
selectevery(12, 0,7, 6,9, 10,5)
#pattern is always the same, but it doesn't always start on the same frame

weave
interleave(last,last)
#double frames to get back to 60Hz
#deleteframe/duplicateframe to match original frame count
3. PSXjin outputs A LOT of files. 178 avis for Disc 1. Avisynth can't usually open that many files at once, and typing them all in would be painful anyway. So I made a batch file that would take the name of a directory and splice together the avis into more managable pieces.
@ECHO OFF
SET maxsources=25
SET customsource="C:\Program Files (x86)\anrichan3.3\cs.avs"
SET counter=0
SET counterB=0

CD %~1

IF EXIST "spliced\" (
    ECHO Spliced files already exist. OVERWRITING?!?
    PAUSE
)
MKDIR "spliced\"

SETLOCAL EnableDelayedExpansion
FOR %%G IN ("*.avi") DO (
    IF !counter! EQU 0 (
        ECHO import^(%customsource%^) > "spliced\!counterB!.avs"
    ) ELSE (
        ECHO \++\ >> "spliced\!counterB!.avs"
    )
    ECHO customsource^("%%~fG"^) >> "spliced\!counterB!.avs"
    SET /A counter += 1
    ECHO !counterB!.!counter! %%~fG
    IF !counter! EQU %maxsources% (
        SET /A counter = 0
        SET /A counterB += 1
    )
)

ECHO Encode Files?
PAUSE
CD "spliced"

SET vdub="C:\Program Files (x86)\anrichan3.3\VirtualDub-1.9.7\vdub.exe"
SET vcf="C:\Program Files (x86)\anrichan3.3\spliced.vcf"
FOR %%G IN ("*.avs") DO (
    %vdub% "%%G" /i %vcf% "%%~nG.avi"
)
PAUSE
GOTO:EOF
Make the .vcf file in virtualdub, setup your encode setting, choose "Save processing settings... Crtl+S" from the file menu and add this line to the bottom.
VirtualDub.SaveAVI(VirtualDub.params[0]);
4. PSXjin outputs at a nonstandard framerate. (59.997?) I want to up this to 60, then resample the audio to keep it in synch.
avisource("0.avi")
\++\
avisource("1.avi")
\++\
avisource("2.avi")
\++\
avisource("3.avi")
\++\
avisource("4.avi")
vid=assumefps(60)

wavsource("M:\ff8_avi2\000_disc2.wav")
ResampleAudio(4409787,100)
aud=AssumeSampleRate(44100)

audiodub(vid,aud)
Experienced Forum User, Published Author, Player (65)
Joined: 4/21/2011
Posts: 232
Fake it with side by side "YV8" for red green and blue?
Experienced Forum User, Published Author, Player (65)
Joined: 4/21/2011
Posts: 232
What about games that are letterboxed? Like road runner. Is it ok to drop the letter boxing?
Experienced Forum User, Published Author, Player (65)
Joined: 4/21/2011
Posts: 232
natt wrote:
That's a pretty bad tradeoff
Yep, it is called placebo for a reason. --preset veryslow --slow-firstpass --no-fast-pskip --bframes 16 would be the same as --preset placebo --me umh --subme 10 but might convey the intent better. Weakening the --preset seems odd to me.
Experienced Forum User, Published Author, Player (65)
Joined: 4/21/2011
Posts: 232
--me umh --subme 10
Why these instead of placebos defaults of tesa, 11?
Experienced Forum User, Published Author, Player (65)
Joined: 4/21/2011
Posts: 232
It is easier to blur a sharp vid than sharpen a blurry vid, because blurring loses information which can't be regained. What system are you using that you can't see pixels on your TV? Break out an Atari and you'll see characteristically blocky groups of pixels. Transitions from one color to the next were sharp (possibly a little noisy), but limited color palettes meant you never had the smooth color transitions that bilinearresize comes up with.
Experienced Forum User, Published Author, Player (65)
Joined: 4/21/2011
Posts: 232
Scanlines are pretty easy
ffvideosource("8_bosses1.mp4").converttoRGB
a=pointresize(2*width, height)
b=blankclip(a)
interleave(a,b)
assumefieldbased.weave
Experienced Forum User, Published Author, Player (65)
Joined: 4/21/2011
Posts: 232
ledauphinbenoit wrote:
AviSynth does not support higher bit-depth by default and the hybrid script makes no mention of how to convert.
You don't need to convert anything. 10bit x264 will produce more efficient output because it is using higher precision for its internal calculations, even when using an 8bit source. P.S. there is a missing newline in second_10bit444.bat
x264-10 --sar 7:6 --keyint infinite --crf 0 --fullrange on -o NUL encode.avs
x264-10 --threads 1 --sar 7:6 --crf 20 --keyint 600 --ref 16 --no-fast-pskip --bframes 16 --b-adapt 2 --direct auto --me umh --merange 64 --subme 10 --trellis 2 --partitions all --rc-lookahead 250 --no-dct-decimate --fullrange on --tcfile-in times.txt -o sd_10bit444.mp4 --output-csp i444 encode.avs 
Experienced Forum User, Published Author, Player (65)
Joined: 4/21/2011
Posts: 232
Brandon wrote:
In all seriousness, I figure that there's way to tweak the algorithm from preventing these cases from happening.
There are MANY ways to tweak the algorithm, but no one solution will give best results for all scenes on all sources.
Experienced Forum User, Published Author, Player (65)
Joined: 4/21/2011
Posts: 232
No, be so kind as to explain to me why it's a joke.
YV12 has chroma subsampling. Pointresize( *2, *2) before the color resampling will help preserve the information contained in the RGB original. CRTs generally don't have square pixels. The NES renders a 256x224 color field which gets analogly spread onto a 4:3 screen. Stretching to 298x224 is a lossy process, but pointresize( *14, *12) isn't. Youtube doesn't let you choose your upsizer when viewing fullscreen. Knowing that a truly pointresized option is availible at all resolutions is comforting to some. Others like to show off how shiny hqx/nedi makes things, while the rest of us gag. Youtube doesn't always honor your resolution when it doesn't fall exactly on 240, and letting youtube decide how to handle resizing is pretty scary. Pointresize( *14, *12) seems crazy, but with pristine sources and lossless encoding it compacts incredibly well. Lossy encodes will oddly be much bigger in most cases.
Experienced Forum User, Published Author, Player (65)
Joined: 4/21/2011
Posts: 232
http://research.microsoft.com/en-us/um/people/kopf/pixelart/supplementary/multi_comparison.html Pixels are cool. For modest upscaling, pointresize looks the best. For crazy upscaling the pixels can cause eyebleed. Something with the shape of hq4x and the colors of EPX might be ok, but IMO none of the available choices are better than point, and most are worse.
Experienced Forum User, Published Author, Player (65)
Joined: 4/21/2011
Posts: 232
i2=layer(e2,o1.mask(blinkmask.converttorgb32))
#interleave(e0,o1,i2,o3)
#i2=layer(i2,o1.mask(shakemask.converttorgb32)) 
i2 is defined in the first line. If your source has shaking you should leave the first line as is and uncomment the 2nd and 3rd lines.
Experienced Forum User, Published Author, Player (65)
Joined: 4/21/2011
Posts: 232
Toothache wrote:
Alisia Dragoon
I pulled the mp4 off of archive. Is the frame rate really 48.9, or has it been dedupped or something?
Experienced Forum User, Published Author, Player (65)
Joined: 4/21/2011
Posts: 232
feos wrote:
The round turns into a square after processing.
You won't be able to do blinking and the round. TASblend would probably be a good compromise there, but it might mess up the motion in the rest of the scene. A version that turns just the blinking into transparency should be possible. Baxter
Experienced Forum User, Published Author, Player (65)
Joined: 4/21/2011
Posts: 232
Those seem to work ok. A trim(1,0) was needed for the Turrican, I guess it is easier to overlay the larger sprite than try to cover it up. Gunstar Turrican
Experienced Forum User, Published Author, Player (65)
Joined: 4/21/2011
Posts: 232
The blinkmask is working pretty well. But the shakemask I need in the metroid clip is giving me trouble. road runner http://www.youtube.com/watch?v=tdLJQYwHMXw street fighter http://www.youtube.com/watch?v=tlUc4s0xkMs super metroid http://www.youtube.com/watch?v=90sL_0bAiWc
converttorgb32

e0=selectevery(4,0)
o1=selectevery(4,1)
e2=selectevery(4,2)
o3=selectevery(4,3)

i2=layer(e2,o1.mask(blinkmask.converttorgb32))
#interleave(e0,o1,i2,o3)
#i2=layer(i2,o1.mask(shakemask.converttorgb32))

interleave(e0,i2)
pointresize(width * 2, height *2)
ConvertToYV24(chromaresample="point", matrix=("PC.601") )
ConvertToYV12(chromaresample="point", matrix=("PC.601") )

function blinkmask(clip c,int "ml"){
    ml=default(ml,128)
    src=c.ConvertToYv12
    super=MSuper(src, pel=1)
    fvec =MAnalyse(super, isb=false, blksize=4)
    bvec =MAnalyse(super, isb=true , blksize=4)
    fmask=Mmask(src,fvec,kind=1,ml=ml).mt_binarize(u=-128,v=-128)
    bmask=Mmask(src,bvec,kind=1,ml=ml).mt_binarize(u=-128,v=-128)

    eo0_to =fmask.selectevery(4,1)
    oe_from=bmask.selectevery(4,1)
    front  =mt_logic(eo0_to,oe_from,mode="and")

    oe_to  =fmask.selectevery(4,2)
    eo_from=bmask.selectevery(4,2)
    back   =mt_logic(oe_to,eo_from,mode="and")

    ee_src=src.selecteven
    ee_super=MSuper(ee_src, pel=1)
    ee_fvec =MAnalyse(ee_super, isb=false, blksize=4)
    ee_bvec =MAnalyse(ee_super, isb=true , blksize=4)
    ee_fmask=Mmask(ee_src,ee_fvec,kind=1,ml=ml).mt_binarize(u=-128,v=-128)
    ee_bmask=Mmask(ee_src,ee_bvec,kind=1,ml=ml).mt_binarize(u=-128,v=-128)

    ee_to  =ee_fmask.selectevery(2,1)
    ee_from=ee_bmask.selectevery(2,0)
    ee     =mt_logic(ee_to,ee_from,mode="or")

    oo_src=src.selectodd
    oo_super=MSuper(oo_src, pel=1)
    oo_fvec =MAnalyse(oo_super, isb=false, blksize=4)
    oo_bvec =MAnalyse(oo_super, isb=true , blksize=4)
    oo_fmask=Mmask(oo_src,oo_fvec,kind=1,ml=ml).mt_binarize(u=-128,v=-128)
    oo_bmask=Mmask(oo_src,oo_bvec,kind=1,ml=ml).mt_binarize(u=-128,v=-128)

    oo_to  =oo_fmask.selectevery(2,1)
    oo_from=oo_bmask.selectevery(2,0)
    oo     =mt_logic(oo_to,oo_from,mode="or")

    #to e0-o1, from o1-e2, nothing e0-e2
    unblink=mt_logic(front,ee.mt_invert,mode="and")

    #to o1-e2, from e2-o3, nothing o1-o3
    blink  =mt_logic(back,oo.mt_invert,mode="and")

    return mt_logic(blink,unblink,mode="or")
}

function shakemask(clip c){
    e0=c.selectevery(4,0)
    o1=c.selectevery(4,1)
    e2=c.selectevery(4,2)
    o3=c.selectevery(4,3)
    e4=c.selectevery(4,4)

    ee1=ng_same(e0,e2).mt_inpand
    ee2=ng_same(e2,e4).mt_inpand
    oo=ng_same(o1,o3).mt_inpand

    mask=mt_logic(ee1,ee2,mode="or")
    return mt_logic(mask,oo,mode="and")
}

function ng_same(clip A, clip B, int "thr"){
    thr=default(thr,0)
    TAD=ng_TAD(A,B)
    return mt_binarize(TAD, threshold=thr, upper=true)
}

function ng_TAD(clip A, clip B){
    R=ng_AD(A  .showRed("YV12"),B  .showRed("YV12"))
    G=ng_AD(A.showGreen("YV12"),B.showGreen("YV12"))
    B=ng_AD(A .showBlue("YV12"),B .showBlue("YV12"))
    return ng_plus(R, ng_plus(G, B))
}

function ng_AD(clip A, clip B){
    return mt_lutxy(A,B,"x y - abs")
}

function ng_plus(clip A, clip B){
    return mt_lutxy(A,B,"x y +")
}
1 2
7 8 9 10