D'zzy
1st August 2009, 15:23
Hello, I'm totally new to avisynth and basically all the video processing stuff.
What brings me here is this DVD that I'm trying to encode. The content is 6 episodes of the Anime FLCL.
OK, as always, samples first :
Clip01-1.CrackedGuitar.m2v (http://kiwi6.com/upload/hotlink?id=0qye682m) 4.2 MB
Clip01-2.BlackManga.m2v (http://kiwi6.com/upload/hotlink?id=252vcw91) 8.9 MB
Clip01-3.LightScene.m2v (http://kiwi6.com/upload/hotlink?id=hnruc3pp) 17.0 MB
Clip01-4.Fade.m2v (http://kiwi6.com/upload/hotlink?id=qkm6w5en) 9.2 MB
About the samples:
:: They're all from the 1st episode :: Cut using "Save Project and Demux Video" in DGIndex ::
01-1.CrackedGuitar:
High motion scene where noise/blockiness peak. Play it one frame per step to see the rubbish...
01-2.BlackManga:
There're several minutes in the episode where it's totally black and white manga, with some high motion among them, where it's very noisy/blocky...
01-3.LightScene:
Light scene during the dark blue night. I'm not sure it's haloing or ringing...as in the other parts of the video.
01-4.Fade:
Scene change, where the previous scene shrinks to top-right. High motion produces some noise. Also look at the girl's skirt( haloing or ringing?)
The noise after scene change is intentional I think, though there're non-intentional ones...Complicated...
I want to use avisynth(version 2.58) to do some filtering and to frameserve to x264.exe for encoding, then mux video and audio through mkvmerge.
Used DGIndex "Respect Pulldown Flags" to produce .d2v file, with Clipping set to "8,8,0,0".
My avisynth script looks like this so far:
LoadPlugin("G:\FLCL\software\dgmpgdec155\DGDecode.dll")
LoadPlugin("G:\FLCL\software\TIVTC\TIVTC.dll")
LoadPlugin("G:\FLCL\software\dedup\Dedup.dll")
MPEG2Source("G:\FLCL\output\VTS_01_1.d2v", cpu=0)
# 2nd pass of TIVTC(VFR mkv), use ovr to override mis-postprocessing.
tfm(d2v="G:\FLCL\output\VTS_01_1.d2v",mode=3,pp=6,slow=2,ovr="ovr.txt",input="matches.txt")
tdecimate(mode=5,hybrid=2,vfrDec=1,hint=true,input="metrics.txt",tfmIn="matches.txt",mkvOut="tivtc_timecodes.txt")
# Replace Bad frames with images
# Remove duplicated frames with DeDup
# Denoise/Deblock/Dering/Dehalo...
# Sharpen/Linedarken...
"matches.txt" and "metrics.txt" are generated by 1st pass of TIVTC:
tfm(d2v="G:\FLCL\output\VTS_01_1.d2v",mode=3,pp=1,slow=2,output="matches.txt")
tdecimate(mode=4,output="metrics.txt")
You may notice that I'm making the video a Variable FrameRate one. This brings further confusion, as described later.
By using TIVTC and "ovr.txt" I see almost no combing now. Fine.
Obviously, there's a lot left to be done...
One thing is around frame 904 to 911 there's tiny blocks (http://omploader.org/vMjJsYQ) hanging between the girl's nose and mouth, which means a wierd flash of 0.33
second.
Experimented with some denoiser with no good result. I thought,"How about painting it by hand?"
So here is the first challenge:
>> Replace frames with external images <<
>Solution 1.0:
SetMemoryMax(512)
___LoadPlugin___
___MPEG2Source___
function imagesplice (clip c, string "filename", int "frameno")
{
frame=imagesource(filename)
frame=frame.selectevery(frame.framecount,0).assumefps(c.framerate).converttoyv12()
c.trim(0,frameno-1)++frame++c.trim(frameno+1,0)
}
___TIVTC___
imagesplice("904.png",904)
imagesplice("905.png",905)
imagesplice("906.png",906)
imagesplice("907.png",907)
imagesplice("908.png",908)
imagesplice("909.png",909)
imagesplice("910.png",910)
imagesplice("911.png",911)
It basically does a great job but there's the problem:
"Avisynth read error: CAVISteamSynth: System expection - Access Violation at 0x16cbf7d, reading from 0x3fad004" -- Memory Leak
This happened when I added DegrainMedian().deen() and LimitedSharpenFaster() to the script.
Too many trims and splices make it crash.
Note: the imagesplice function is from Mug Funky's post (http://forum.doom9.org/showthread.php?p=805328#post805328)
I don't know how ReplaceFrame (http://zeratul.cellosoft.com/replaceframe/) works since the link seems dead.
>Solution 1.1:
SetMemoryMax(512)
___LoadPlugin___
___MPEG2Source___
function imagesplice2 (clip c, string "filename", int "frameno",int "replaceno")
{
frames=imagesource(filename,frameno,frameno+replaceno-1,c.framerate).converttoyv12()
c.trim(0,frameno-1)++frames++c.trim(frameno+replaceno,0)
}
___TIVTC___
imagesplice2("%03d.png",904,8)
It looks to me a better solution... But unfortunately crashes in the same situation.
>> I just find Freezeframe(21433,21442,21443) works great in replacing bad frames with a good version which is inside the video.
>> Also I've read about LBKiller. Haven't tried it yet but there I read : "avs script generation, using frame freezing" So... it's using Freezeframe() to replace frames with
external images?
>Solution 2.0:
Help me with this version bump... ^^
>> Note: Since I'm making the clip VFR, the image replacing the corresponding frame should read exactly the framerate of the replaced frame......Or, maybe NOT??
Now it's challenge 2:
>> Denoise <<
I see there're always a lot discussions dedicated to this topic. But... I think I'd better ask here for this specific solution anyway.
The video is anime material but there is something to be taken into account:
1. Sometimes there are some background with more detail than normal anime, e.g. a wall (http://omploader.org/vMjJsNA) or bridge (http://omploader.org/vMjJsOA)
with some detailed texture.
2. High motion scene brings much more noise than static scene.
3. The manga part. It's black and white and some frames are really noisy. I guess denoising method differs with manga from normal anime?
So... different parts need different strategy.
If I need to apply different filters to different parts of the video, what do I do? ApplyRange? ConditionalFilter? (I don't really know how to use them, yet.)
Also, I'm not quite sure about those terms: noise / ring / halo, maybe also block / grain etc...
Another challenge:
>> Color Problem <<
I'm confused a little about the color display in VirtualDub:
1. When playing the script in VDub, there's some "rainbow effect"(if I understand it right...it's like "Posterization", or "banding") -- the picture is no way smooth...
2. When paused, I see the color obviously off(darker/less saturation). But the rainbow is gone and it looks smooth.
3. Still paused, but with the VDub window unfocused, the color seems fine. It's the same as "Copy source frame to clipboard" and paste it in photoshop.
4. Play the .avs in Windows Media Player 6.4.09.1130, and the color is the same as 2. : color is off but no rainbow effect. No matter focused or not, no matter playing or paused.
So, do you also experience this? Which is the color in the final encoded video?
Also, I've read about ColorMatrix()... [ Makes someone doubt if they've been encoding crap all those years...lol ]
With "MPEG2Source("G:\FLCL\output\VTS_01_1.d2v", cpu=0,info=1)" I get:
Colorimetry: ITU-R BT.470-2 System B, G (5)
Which is equal to ITU-R BT.601 or Rec.601.
Do I need to add ColorMatrix() to my script? If I do, where?
>> Sharpen <<
Anime materials always look better when those dark lines are sharp with smooth outlines. I tried LimitedSharpenFaster() and am already amazed:
original (http://omploader.org/vMjJsZQ) --> deen().LimitedSharpenFaster() (http://omploader.org/vMjJsZA)
I think I only need to do the denoising before sharpen better and it's gonna be great!
Maybe you guys have something else to recommend too? Or help me tweak the parameters ^^
>> Filter Order <<
I don't know how avisynth reads the commands... I mean the order they're read/applied.
Say, normally, in a programming language, we have "if... then ... elif... then... fi"...Some structure like this is read from top until the condition is matched, then the command
is run. While in avisynth, there is:
___Filter_for_all___
A = Last
___Filter_for_Bad_Frames___
B = Last
ConditionalFilter(A, B, "Bad", "==", "False", false)
ConditionalReader("If.txt", "Bad", false)
The "Bad" values are placed in a file called "If.txt"... ConditionalReader is placed at the bottom, which looks strange to me... Someone can explain this to me?
Back to the practical side, I want to ask what is the best order for those filters/commands to be placed?
Say, I want to use dedup to reduce unnecessary frames, it is for sure placed after tdecimate, but where exactly? Before replacing frames with images or after?
And how about VFR? When replacing frames with images, how to keep the framerate intact?
Also, is it OK, in terms of compression, to replace frames woth images?(Though the image size is no big anyway,but...just in case.^^)
So much so far. Thanks in advance.
What brings me here is this DVD that I'm trying to encode. The content is 6 episodes of the Anime FLCL.
OK, as always, samples first :
Clip01-1.CrackedGuitar.m2v (http://kiwi6.com/upload/hotlink?id=0qye682m) 4.2 MB
Clip01-2.BlackManga.m2v (http://kiwi6.com/upload/hotlink?id=252vcw91) 8.9 MB
Clip01-3.LightScene.m2v (http://kiwi6.com/upload/hotlink?id=hnruc3pp) 17.0 MB
Clip01-4.Fade.m2v (http://kiwi6.com/upload/hotlink?id=qkm6w5en) 9.2 MB
About the samples:
:: They're all from the 1st episode :: Cut using "Save Project and Demux Video" in DGIndex ::
01-1.CrackedGuitar:
High motion scene where noise/blockiness peak. Play it one frame per step to see the rubbish...
01-2.BlackManga:
There're several minutes in the episode where it's totally black and white manga, with some high motion among them, where it's very noisy/blocky...
01-3.LightScene:
Light scene during the dark blue night. I'm not sure it's haloing or ringing...as in the other parts of the video.
01-4.Fade:
Scene change, where the previous scene shrinks to top-right. High motion produces some noise. Also look at the girl's skirt( haloing or ringing?)
The noise after scene change is intentional I think, though there're non-intentional ones...Complicated...
I want to use avisynth(version 2.58) to do some filtering and to frameserve to x264.exe for encoding, then mux video and audio through mkvmerge.
Used DGIndex "Respect Pulldown Flags" to produce .d2v file, with Clipping set to "8,8,0,0".
My avisynth script looks like this so far:
LoadPlugin("G:\FLCL\software\dgmpgdec155\DGDecode.dll")
LoadPlugin("G:\FLCL\software\TIVTC\TIVTC.dll")
LoadPlugin("G:\FLCL\software\dedup\Dedup.dll")
MPEG2Source("G:\FLCL\output\VTS_01_1.d2v", cpu=0)
# 2nd pass of TIVTC(VFR mkv), use ovr to override mis-postprocessing.
tfm(d2v="G:\FLCL\output\VTS_01_1.d2v",mode=3,pp=6,slow=2,ovr="ovr.txt",input="matches.txt")
tdecimate(mode=5,hybrid=2,vfrDec=1,hint=true,input="metrics.txt",tfmIn="matches.txt",mkvOut="tivtc_timecodes.txt")
# Replace Bad frames with images
# Remove duplicated frames with DeDup
# Denoise/Deblock/Dering/Dehalo...
# Sharpen/Linedarken...
"matches.txt" and "metrics.txt" are generated by 1st pass of TIVTC:
tfm(d2v="G:\FLCL\output\VTS_01_1.d2v",mode=3,pp=1,slow=2,output="matches.txt")
tdecimate(mode=4,output="metrics.txt")
You may notice that I'm making the video a Variable FrameRate one. This brings further confusion, as described later.
By using TIVTC and "ovr.txt" I see almost no combing now. Fine.
Obviously, there's a lot left to be done...
One thing is around frame 904 to 911 there's tiny blocks (http://omploader.org/vMjJsYQ) hanging between the girl's nose and mouth, which means a wierd flash of 0.33
second.
Experimented with some denoiser with no good result. I thought,"How about painting it by hand?"
So here is the first challenge:
>> Replace frames with external images <<
>Solution 1.0:
SetMemoryMax(512)
___LoadPlugin___
___MPEG2Source___
function imagesplice (clip c, string "filename", int "frameno")
{
frame=imagesource(filename)
frame=frame.selectevery(frame.framecount,0).assumefps(c.framerate).converttoyv12()
c.trim(0,frameno-1)++frame++c.trim(frameno+1,0)
}
___TIVTC___
imagesplice("904.png",904)
imagesplice("905.png",905)
imagesplice("906.png",906)
imagesplice("907.png",907)
imagesplice("908.png",908)
imagesplice("909.png",909)
imagesplice("910.png",910)
imagesplice("911.png",911)
It basically does a great job but there's the problem:
"Avisynth read error: CAVISteamSynth: System expection - Access Violation at 0x16cbf7d, reading from 0x3fad004" -- Memory Leak
This happened when I added DegrainMedian().deen() and LimitedSharpenFaster() to the script.
Too many trims and splices make it crash.
Note: the imagesplice function is from Mug Funky's post (http://forum.doom9.org/showthread.php?p=805328#post805328)
I don't know how ReplaceFrame (http://zeratul.cellosoft.com/replaceframe/) works since the link seems dead.
>Solution 1.1:
SetMemoryMax(512)
___LoadPlugin___
___MPEG2Source___
function imagesplice2 (clip c, string "filename", int "frameno",int "replaceno")
{
frames=imagesource(filename,frameno,frameno+replaceno-1,c.framerate).converttoyv12()
c.trim(0,frameno-1)++frames++c.trim(frameno+replaceno,0)
}
___TIVTC___
imagesplice2("%03d.png",904,8)
It looks to me a better solution... But unfortunately crashes in the same situation.
>> I just find Freezeframe(21433,21442,21443) works great in replacing bad frames with a good version which is inside the video.
>> Also I've read about LBKiller. Haven't tried it yet but there I read : "avs script generation, using frame freezing" So... it's using Freezeframe() to replace frames with
external images?
>Solution 2.0:
Help me with this version bump... ^^
>> Note: Since I'm making the clip VFR, the image replacing the corresponding frame should read exactly the framerate of the replaced frame......Or, maybe NOT??
Now it's challenge 2:
>> Denoise <<
I see there're always a lot discussions dedicated to this topic. But... I think I'd better ask here for this specific solution anyway.
The video is anime material but there is something to be taken into account:
1. Sometimes there are some background with more detail than normal anime, e.g. a wall (http://omploader.org/vMjJsNA) or bridge (http://omploader.org/vMjJsOA)
with some detailed texture.
2. High motion scene brings much more noise than static scene.
3. The manga part. It's black and white and some frames are really noisy. I guess denoising method differs with manga from normal anime?
So... different parts need different strategy.
If I need to apply different filters to different parts of the video, what do I do? ApplyRange? ConditionalFilter? (I don't really know how to use them, yet.)
Also, I'm not quite sure about those terms: noise / ring / halo, maybe also block / grain etc...
Another challenge:
>> Color Problem <<
I'm confused a little about the color display in VirtualDub:
1. When playing the script in VDub, there's some "rainbow effect"(if I understand it right...it's like "Posterization", or "banding") -- the picture is no way smooth...
2. When paused, I see the color obviously off(darker/less saturation). But the rainbow is gone and it looks smooth.
3. Still paused, but with the VDub window unfocused, the color seems fine. It's the same as "Copy source frame to clipboard" and paste it in photoshop.
4. Play the .avs in Windows Media Player 6.4.09.1130, and the color is the same as 2. : color is off but no rainbow effect. No matter focused or not, no matter playing or paused.
So, do you also experience this? Which is the color in the final encoded video?
Also, I've read about ColorMatrix()... [ Makes someone doubt if they've been encoding crap all those years...lol ]
With "MPEG2Source("G:\FLCL\output\VTS_01_1.d2v", cpu=0,info=1)" I get:
Colorimetry: ITU-R BT.470-2 System B, G (5)
Which is equal to ITU-R BT.601 or Rec.601.
Do I need to add ColorMatrix() to my script? If I do, where?
>> Sharpen <<
Anime materials always look better when those dark lines are sharp with smooth outlines. I tried LimitedSharpenFaster() and am already amazed:
original (http://omploader.org/vMjJsZQ) --> deen().LimitedSharpenFaster() (http://omploader.org/vMjJsZA)
I think I only need to do the denoising before sharpen better and it's gonna be great!
Maybe you guys have something else to recommend too? Or help me tweak the parameters ^^
>> Filter Order <<
I don't know how avisynth reads the commands... I mean the order they're read/applied.
Say, normally, in a programming language, we have "if... then ... elif... then... fi"...Some structure like this is read from top until the condition is matched, then the command
is run. While in avisynth, there is:
___Filter_for_all___
A = Last
___Filter_for_Bad_Frames___
B = Last
ConditionalFilter(A, B, "Bad", "==", "False", false)
ConditionalReader("If.txt", "Bad", false)
The "Bad" values are placed in a file called "If.txt"... ConditionalReader is placed at the bottom, which looks strange to me... Someone can explain this to me?
Back to the practical side, I want to ask what is the best order for those filters/commands to be placed?
Say, I want to use dedup to reduce unnecessary frames, it is for sure placed after tdecimate, but where exactly? Before replacing frames with images or after?
And how about VFR? When replacing frames with images, how to keep the framerate intact?
Also, is it OK, in terms of compression, to replace frames woth images?(Though the image size is no big anyway,but...just in case.^^)
So much so far. Thanks in advance.