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 26th March 2013, 11:11   #1  |  Link
frenshprince
Registered User
 
Join Date: May 2009
Posts: 27
Report sceenshots instead of txt

Hi there,

I use this script to fing bad frame in my videos
Quote:
AVISource("***.avi", audio=false).AssumeFPS(24000,1001)
ConvertToYV12()
prev=deleteframe(0)
next=duplicateframe(0)
prevdiff=mt_lutxy(last,prev,"x y - 4 / 2 ^")
nextdiff=mt_lutxy(last,next,"x y - 4 / 2 ^")
writefileif("D:\video\***.txt","AverageLuma(prevdiff) > 100 && AverageLuma(nextdiff) > 100","current_frame")
And it works nice, except that I would like a report of the bad frame, in screenshot instead of inside a TXT file.

Is that possible to do ?

Thanks for your help
frenshprince is offline   Reply With Quote
Old 26th March 2013, 11:33   #2  |  Link
fvisagie
Registered User
 
Join Date: Aug 2008
Location: Isle of Man
Posts: 586
Use a runtime filter to call Subtitle() on each frame, with your text string as input to Subtitle().

Cheers,
Francois
fvisagie is offline   Reply With Quote
Old 26th March 2013, 11:40   #3  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,380
You could use my DeleteFrames() function from this thread to delete all the good frames, leaving just the bad ones, eg
DeleteFrames("AverageLuma(prevdiff) <= 100 || AverageLuma(nextdiff) <= 100")

Incidentally, your code
Quote:
Originally Posted by frenshprince View Post
Code:
prev=deleteframe(0)
next=duplicateframe(0)
has prev and next the wrong way round - frame n of prev will be frame n+1 of the original, although it doesn't really matter here since your process treats both directions equally .
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 26th March 2013, 11:52   #4  |  Link
frenshprince
Registered User
 
Join Date: May 2009
Posts: 27
Quote:
Originally Posted by Gavino View Post
You could use my DeleteFrames() function from this thread to delete all the good frames, leaving just the bad ones, eg
DeleteFrames("AverageLuma(prevdiff) <= 100 || AverageLuma(nextdiff) <= 100")

Incidentally, your code

has prev and next the wrong way round - frame n of prev will be frame n+1 of the original, although it doesn't really matter here since your process treats both directions equally .
Hi Gavino,

I used this script this way
Quote:
AVISource("test.avi", audio=false).AssumeFPS(24000,1001)
ConvertToYV12()
prev=deleteframe(0)
next=duplicateframe(0)
prevdiff=mt_lutxy(last,prev,"x y - 4 / 2 ^")
nextdiff=mt_lutxy(last,next,"x y - 4 / 2 ^")
DeleteFrames("AverageLuma(prevdiff) <= 100 || AverageLuma(nextdiff) <= 100")
But Vdub told me that there is no function nemed "delete frames".
frenshprince is offline   Reply With Quote
Old 26th March 2013, 11:53   #5  |  Link
frenshprince
Registered User
 
Join Date: May 2009
Posts: 27
Quote:
Originally Posted by fvisagie View Post
Use a runtime filter to call Subtitle() on each frame, with your text string as input to Subtitle().

Cheers,
Francois
Hi François,

Thanks for your help, but it seems too complicated to me.
frenshprince is offline   Reply With Quote
Old 26th March 2013, 12:14   #6  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,380
Quote:
Originally Posted by frenshprince View Post
Vdub told me that there is no function nemed "delete frames".
Your script needs to include the function source code from the thread I linked.
You will also need GScript.
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 26th March 2013, 12:29   #7  |  Link
frenshprince
Registered User
 
Join Date: May 2009
Posts: 27
Thanks for you help Gavino

But I'm a total noob; and can't make it works.
I Installed Gscript plugins, but I don't understand your source code.

This is what I tried
Quote:
AVISource("test.avi", audio=false).AssumeFPS(24000,1001)
ConvertToYV12()
GScript("""
function DeleteFrames(clip c, string condition) {
DeleteFrames("AverageLuma(prevdiff) <= 100 || AverageLuma(nextdiff) <= 100")

c
fc = FrameCount()
res = BlankClip(c, length=0)
current_frame = 0

while (current_frame < fc) {
while (Eval(condition) && current_frame < fc) {
current_frame = current_frame+1
}
if (current_frame < fc) { # not at end
start = current_frame # start of wanted section
while (!Eval(condition) && current_frame < fc) {
current_frame = current_frame+1
}
res = res + Trim(start, start-current_frame)
}
}

return res
}
""")

Last edited by frenshprince; 26th March 2013 at 12:31.
frenshprince is offline   Reply With Quote
Old 26th March 2013, 13:06   #8  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,380
Copy the code unchanged from the other thread (which defines the function) before the rest of your script, then add the function call at the end:
Code:
GScript("""
  function DeleteFrames(clip c, string condition) {
    ...
""")

AVISource("test.avi", audio=false).AssumeFPS(24000,1001)
ConvertToYV12()
prev=deleteframe(0)
next=duplicateframe(0)
prevdiff=mt_lutxy(last,prev,"x y - 4 / 2 ^")
nextdiff=mt_lutxy(last,next,"x y - 4 / 2 ^")
DeleteFrames("AverageLuma(prevdiff) <= 100 || AverageLuma(nextdiff) <= 100")
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 26th March 2013, 13:52   #9  |  Link
fvisagie
Registered User
 
Join Date: Aug 2008
Location: Isle of Man
Posts: 586
Quote:
Originally Posted by frenshprince View Post
Hi François,

Thanks for your help, but it seems too complicated to me.
You can replace the WriteFileIf() line at the end of your script with something like
Code:
ScriptClip("(AverageLuma(prevdiff) > 100 && AverageLuma(nextdiff) > 100) ? Subtitle(String(current_frame)) : last")
to identify the frames considered bad on-screen.

If you want to add string literals to the displayed string, you have to enclose the lot in triple quotes
Code:
ScriptClip("""(AverageLuma(prevdiff) > 100 && AverageLuma(nextdiff) > 100) ? Subtitle("Bad frame: " + String(current_frame)) : last""")
Hope this helps,
Francois
fvisagie is offline   Reply With Quote
Old 26th March 2013, 14:06   #10  |  Link
frenshprince
Registered User
 
Join Date: May 2009
Posts: 27
Thanks Gavino, but I don't get "add the function call at the end"
Remember, I'm an avisynth noob
Quote:
GScript("""
function DeleteFrames(clip c, string condition) {
# DeleteFrames (Gavino, 16 Nov 2011)
# A generic function that will delete all frames satisfying an arbitrary user-defined condition.
# The condition can use any of the Avisynth run-time functions such as AverageLuma(), etc,
# and/or the variable 'current_frame'.
# (Note - Since the condition is evaluated inside the function,
# any variables used (except current_frame) must be global.)
# Example use (delete duplicate frames):
# DeleteFrames("YDifferenceFromPrevious < 0.1 && current_frame > 0")

c
fc = FrameCount()
res = BlankClip(c, length=0)
current_frame = 0

while (current_frame < fc) {
while (Eval(condition) && current_frame < fc) {
current_frame = current_frame+1
}
if (current_frame < fc) { # not at end
start = current_frame # start of wanted section
while (!Eval(condition) && current_frame < fc) {
current_frame = current_frame+1
}
res = res + Trim(start, start-current_frame)
}
}

return res
}
""")

AVISource("test.avi", audio=false).AssumeFPS(24000,1001)
ConvertToYV12()
prev=deleteframe(0)
next=duplicateframe(0)
prevdiff=mt_lutxy(last,prev,"x y - 4 / 2 ^")
nextdiff=mt_lutxy(last,next,"x y - 4 / 2 ^")
DeleteFrames("AverageLuma(prevdiff) <= 100 || AverageLuma(nextdiff) <= 100")
When I try to open it in Vdub, it tells me "I don't know what prediff means"

frenshprince is offline   Reply With Quote
Old 26th March 2013, 14:11   #11  |  Link
fvisagie
Registered User
 
Join Date: Aug 2008
Location: Isle of Man
Posts: 586
Quote:
Originally Posted by fvisagie View Post
You can replace the WriteFileIf() line at the end of your script with something like
Code:
ScriptClip("(AverageLuma(prevdiff) > 100 && AverageLuma(nextdiff) > 100) ? Subtitle(String(current_frame)) : last")
to identify the frames considered bad on-screen.
Or, as Gavino pointed out elsewhere, you could use ShowFrameNumber() instead of Subtitle() in your last line
Code:
ScriptClip("(AverageLuma(prevdiff) > 100 && AverageLuma(nextdiff) > 100) ? ShowFrameNumber(size=100) : last")
Cheers,
Francois
fvisagie is offline   Reply With Quote
Old 26th March 2013, 14:16   #12  |  Link
frenshprince
Registered User
 
Join Date: May 2009
Posts: 27
Quote:
Originally Posted by fvisagie View Post
You can replace the WriteFileIf() line at the end of your script with something like
Code:
ScriptClip("(AverageLuma(prevdiff) > 100 && AverageLuma(nextdiff) > 100) ? Subtitle(String(current_frame)) : last")
to identify the frames considered bad on-screen.

If you want to add string literals to the displayed string, you have to enclose the lot in triple quotes
Code:
ScriptClip("""(AverageLuma(prevdiff) > 100 && AverageLuma(nextdiff) > 100) ? Subtitle("Bad frame: " + String(current_frame)) : last""")
Hope this helps,
Francois
Thanks François,

Bad frames are identified, which is great.
But what do I have to add to the script to capture those bad frame automatically on png/jpeg/bmp ?
frenshprince is offline   Reply With Quote
Old 26th March 2013, 14:36   #13  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,380
Quote:
Originally Posted by frenshprince View Post
When I try to open it in Vdub, it tells me "I don't know what prediff means"
Sorry, I forgot you need to make the prevdiff and nextdiff variables global for use in DeleteFrames. Change it to:
Code:
global prevdiff=mt_lutxy(last,prev,"x y - 4 / 2 ^")
global nextdiff=mt_lutxy(last,next,"x y - 4 / 2 ^")
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 26th March 2013, 15:20   #14  |  Link
frenshprince
Registered User
 
Join Date: May 2009
Posts: 27
It works, Thanks Gavino

Therefore, I can't make batch with it, since the process is made at the opening of the avs file in VDub.
And it takes twenty minutes to process.

I guess, what I would like is something like this :
Quote:
AVISource("test.avi", audio=false).AssumeFPS(24000,1001)
ConvertToYV12()
prev=deleteframe(0)
next=duplicateframe(0)
global prevdiff=mt_lutxy(last,prev,"x y - 4 / 2 ^")
global nextdiff=mt_lutxy(last,next,"x y - 4 / 2 ^")
ScriptClip("(AverageLuma(prevdiff) > 100 && AverageLuma(nextdiff) > 100) ? ShowFrameNumber(size=100) : last")
then create bmp of those bad frames with imagewriter.
But I can't find the good call.
frenshprince is offline   Reply With Quote
Old 26th March 2013, 15:35   #15  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 5,690
Twenty mins aint a big problem, go get yourself a beer. Cheers.
__________________
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 ???
StainlessS is offline   Reply With Quote
Old 26th March 2013, 15:40   #16  |  Link
frenshprince
Registered User
 
Join Date: May 2009
Posts: 27
Quote:
Originally Posted by StainlessS View Post
Twenty mins aint a big problem, go get yourself a beer. Cheers.
Not a bad idea
But I have more than 200 video to check.
I can't be drunk at work
frenshprince is offline   Reply With Quote
Old 26th March 2013, 16:05   #17  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 5,690
Quote:
Originally Posted by frenshprince View Post
I can't be drunk at work

Damn shame.

Code:
Global ImgCounter = 0
AVISource("D:\test.avi", audio=false).AssumeFPS(24000,1001)
ConvertToYV12()
prev=deleteframe(0)
next=duplicateframe(0)
global prevdiff=mt_lutxy(last,prev,"x y - 4 / 2 ^")
global nextdiff=mt_lutxy(last,next,"x y - 4 / 2 ^")
ScriptClip("""
	TmpC=ShowFrameNumber(size=100).ConvertToRGB24().ImageWriter("d:\TestA_",Start=ImgCounter,End=ImgCounter, type="bmp")
	Proc = (AverageLuma(prevdiff) > 100 && AverageLuma(nextdiff) > 100)
	Global ImgCounter = (Proc) ? ImgCounter+1 : ImgCounter
        (Proc) ? RT_TxtWriteFile(String(current_frame),"D:\TESTFILE.TXT",append=True) : NOP
	Last.RT_GraphLink(TmpC,Proc)								# From RT_Stats
""")
Give above a whirl, not tested, test clip did not fulfill condition to output bmp.

You need RT_Stats for RT_Graphlink().

EDIT: If it dont work on correct frame try " """,After_frame=true) " on scripclip close.
__________________
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; 26th March 2013 at 16:50.
StainlessS is offline   Reply With Quote
Old 26th March 2013, 16:13   #18  |  Link
frenshprince
Registered User
 
Join Date: May 2009
Posts: 27
Thanks Stainless.

It doesnt work :
Imagewriter capture every frame, and not only the bad ones.
frenshprince is offline   Reply With Quote
Old 26th March 2013, 16:18   #19  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 5,690
I think I left in "Proc=True", since removed (almost immediately after posting). Was testing that it worked if condition fulfilled.
__________________
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; 26th March 2013 at 16:21.
StainlessS is offline   Reply With Quote
Old 26th March 2013, 16:24   #20  |  Link
frenshprince
Registered User
 
Join Date: May 2009
Posts: 27
It works !

Many thanks to you, and to Gavino and fvisagie as well.

Cheers
frenshprince is offline   Reply With Quote
Reply

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 17:54.


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