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 6th May 2012, 08:52   #1  |  Link
peacemaker69
Registered User
 
Join Date: Apr 2012
Posts: 7
detecting black frames

I found a script that detects black frames in a video file. I created a test video with black frames. I opened this script in VirtualDubMod, it loads the video but there is no report text file with detected black frames. I am a professional editor but a TOTAL Avisynth noob. There must be something I am doing wrong. Below is the script I am using.


#Specify the name and location of the output file
filename = "c:\output_blank_frames.txt"

#Specify the threshold that will be considered black (0 = pure black)
global blankthreshold=28

#DirectShowSource("black_frames_av2i.avi").killaudio()
AVISource("black_frames_test.avi").killaudio()

#Only look at half the fields (speeds up processing
i=separatefields.selectodd.ConvertToYV12()

#Write the frame number
WriteFileIf(last, filename, "(AverageLuma(i)<blankthreshold)", "current_frame+1", append = false)


thanks for help
peacemaker69 is offline   Reply With Quote
Old 6th May 2012, 10:39   #2  |  Link
librarian
Registered User
 
Join Date: Nov 2011
Posts: 63
Quote:
Originally Posted by peacemaker69 View Post


#Specify the name and location of the output file
global filename = "c:\output_blank_frames.txt"

#Specify the threshold that will be considered black (0 = pure black)
global blankthreshold=28

#DirectShowSource("black_frames_av2i.avi").killaudio()
AVISource("black_frames_test.avi").killaudio()

#Only look at half the fields (speeds up processing
i=separatefields.selectodd.ConvertToYV12()

#Write the frame number
i.WriteFileIf( filename, "(AverageLuma(i)<blankthreshold)", "current_frame+1", append = false)
If you want to use filename inside WRITEFILEIF make it global, the output file is written only if the result of WRITEFILEIF is rendered, from the manual:
Quote:
Note that since output is produced only for ''rendered'' frames, there will be no output at all if the result of the filter is not used in deriving the final result of the script.
librarian is offline   Reply With Quote
Old 6th May 2012, 11:45   #3  |  Link
peacemaker69
Registered User
 
Join Date: Apr 2012
Posts: 7
I added "global" before "filename" and added "i." before "writefileif" but I get a message:

Script error: Invalid arguments to function "WriteFileIf"

If I delete "i.", I don't get any message but there is no output text file too.
peacemaker69 is offline   Reply With Quote
Old 6th May 2012, 11:53   #4  |  Link
librarian
Registered User
 
Join Date: Nov 2011
Posts: 63
Quote:
Originally Posted by peacemaker69 View Post
I added "global" before "filename" and added "i." before "writefileif" but I get a message:

Script error: Invalid arguments to function "WriteFileIf"

If I delete "i.", I don't get any message but there is no output text file too.
With my solution, last line has to be:
i.WriteFileIf( filename, "(AverageLuma(i)<blankthreshold)", "current_frame+1", append = false)
not:
i.WriteFileIf(last, filename, "(AverageLuma(i)<blankthreshold)", "current_frame+1", append = false)
just like I posted above.
librarian is offline   Reply With Quote
Old 6th May 2012, 12:17   #5  |  Link
peacemaker69
Registered User
 
Join Date: Apr 2012
Posts: 7
decompressor

Now I got a message like this:

[!] Couldn't locate decompressor for format 'YV12' (unknown).
VirtualDub requires a Video for Windows (VFW) compatible codec to
decompress video. DirectShow codecs, such as those used by Windows Media
Player, are not suitable. Only 'Direct stream copy' is available for this
video.


I tried this with DV avi and uncompressed avi, same answer. Where to download best codecs for Avisynth?
peacemaker69 is offline   Reply With Quote
Old 6th May 2012, 12:26   #6  |  Link
librarian
Registered User
 
Join Date: Nov 2011
Posts: 63
According to forum rules never ask for the "best".
You already got a good answer:
Quote:
Originally Posted by Yellow_ View Post
BTW this is off topic here.
librarian is offline   Reply With Quote
Old 6th May 2012, 13:10   #7  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,431
Quote:
Originally Posted by librarian View Post
If you want to use filename inside WRITEFILEIF make it global
filename does not need to be global.
Neither does blankthreshold.
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 7th May 2012, 01:25   #8  |  Link
johnmeyer
Registered User
 
Join Date: Feb 2002
Location: California
Posts: 2,691
Here's a script I use all the time. I'm sure you'll need to modify it, but perhaps it will get you started.

You'll note that I wrote the script to only output the first frame that falls below a given luma threshold. The reason for this is that there are lots of situations where a video will go to black for many frames (like between commercials), and with my editing workflow I only need to know where the blank/black series of frames starts. The script below has a line that is commented out that will give you every frame that falls below the blank luma threshold.

Code:
#Script to find blank frames
#The script outputs the frame number of the first frame that falls below
#the threshold luma value. 

#Specify the name and location of the output file
filename = "m:\output_blank_frames.txt"

#Specify the blank threshold. Set to zero for pure black.
global blankthreshold=49

#Specify the name and location of your video file
AVISource("E:\fs.avi").killaudio().ConvertToYV12

#Optional: For analog captures, get rid of the borders.
#          Analog video can have border garbage that affects averageluma
Crop(16,16,-16,-16)

# Use the following to reduce the number of fields by 50% in order to speed processing
separatefields.selectodd

i=last
j=trim(i,1,0) #Previous frame [edit] Actually, it is the NEXT frame

# Temporarily un-comment next line to display the average luma value on screen to help determine threshold value
#ScriptClip(i,"Subtitle(String(AverageLuma(i) ))" )

#This line below will output EVERY frame that is below threshold, which results in LOTS of frames
#Normally you don't do this, but it is included for those who want this capability.
#WriteFileIf(last, filename,  "(AverageLuma(i)<blankthreshold)", "current_frame+1", append = false)

#This is the line that actually writes the frame number of the FIRST frame that falls below the threshold
WriteFileIf(last, filename,  "(AverageLuma(i)<blankthreshold)&&AverageLuma(j)>blankthreshold", "current_frame+1", append = false)

#The line below finds the LAST blank frame. 
#WriteFileIf(last, filename,  "(AverageLuma(i)>blankthreshold)&&AverageLuma(j)<blankthreshold", "current_frame+1", append = false)

Last edited by johnmeyer; 12th March 2013 at 18:02. Reason: Fixed incorrect comment next to the trim(1,0) statement
johnmeyer is offline   Reply With Quote
Old 7th May 2012, 01:48   #9  |  Link
Groucho2004
 
Join Date: Mar 2006
Location: Barcelona
Posts: 5,034
Try this: Run your script from the first post (which works perfectly fine and creates the file with the frames numbers) through AVSMeter.
__________________
Groucho's Avisynth Stuff
Groucho2004 is offline   Reply With Quote
Old 8th May 2012, 03:43   #10  |  Link
Mug Funky
interlace this!
 
Mug Funky's Avatar
 
Join Date: Jun 2003
Location: i'm in ur transfers, addin noise
Posts: 4,555
as an alternative, you might also find that using silence detection on the audio gets you something usable in less time.

both would be nice of course...

i have an EDL generating script that finds hard cuts if you need that. very good for splitting up a tape capture into shots that can be graded in an app that supports CMX format EDLs.
__________________
sucking the life out of your videos since 2004
Mug Funky is offline   Reply With Quote
Old 8th May 2012, 10:04   #11  |  Link
peacemaker69
Registered User
 
Join Date: Apr 2012
Posts: 7
open failure

I am a pro editor but a total avisynth noob, although I think avisynth is a great tool that could help me in my everydays work, that's why I am not giving up!

When I try to work with a DV AVI I get the message:

Avisynth open failure:
Avisource: couldn't locate a decompressor for fourdcc dvsd


when I try uncompressed avi I get:

Couldn't locate decompressor for format YV12 (uknown).
VirtualDub requires a Video for Windows (VFW) compatible codec to decompress video. DirectShow codecs, such as those used by Windows Media Player, are not suitable. Only 'Direct stream copy' is available for this video.
peacemaker69 is offline   Reply With Quote
Old 8th May 2012, 10:20   #12  |  Link
Groucho2004
 
Join Date: Mar 2006
Location: Barcelona
Posts: 5,034
Did you try it with FFMpegsource as suggested to you (twice)?
Groucho2004 is offline   Reply With Quote
Old 8th May 2012, 11:19   #13  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
It is perhaps likely that you will in future encounter further problems without a YV12 decoder, see here if you do:
http://forum.doom9.org/showthread.ph...ght=helix+yv12
__________________
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 8th May 2012, 12:41   #14  |  Link
peacemaker69
Registered User
 
Join Date: Apr 2012
Posts: 7
ffmpeg

Groucho2004 yes I should have done it but.. to load an avi, I use avisource command. How to use ffmpeg in avisynth script to load a video?
peacemaker69 is offline   Reply With Quote
Old 8th May 2012, 13:16   #15  |  Link
Groucho2004
 
Join Date: Mar 2006
Location: Barcelona
Posts: 5,034
Download the latest release and use it like this:
Code:
LoadPlugin("ffms2.dll")
FFVideoSource("vid.avi")
The DLL also comes with documentation.
Groucho2004 is offline   Reply With Quote
Old 23rd February 2013, 16:03   #16  |  Link
lintran
Registered User
 
Join Date: Aug 2008
Posts: 65
........................

Last edited by lintran; 24th May 2013 at 11:04.
lintran is offline   Reply With Quote
Old 23rd February 2013, 18:11   #17  |  Link
Chikuzen
typo lover
 
Chikuzen's Avatar
 
Join Date: May 2009
Posts: 595
Quote:
Originally Posted by lintran View Post
I used peacemaker69 script and it work well though AVSMeter. So anyone can give me avs script that can detect all frames that have silence audio?
Thanks.
Code:
#detect_silence.avs
LoadPlugin("ffms2.dll")
LoadPlugin("MinMaxAudio.dll")

src = "file path to the source"
aud = FFAudioSource(src)
vid = BlankClip(FFVideoSource(src), width=32, height=32)
AudioDub(vid, aud)

#assume max is lesser than -100db as silence frame
WriteFileIf("silence.log", "AudioMax(0) < -100", "current_frame")


> avs2pipemod -benchmark detect_silence.avs
you will get the list of all silence frames.
__________________
my repositories

Last edited by Chikuzen; 12th March 2013 at 21:05.
Chikuzen is offline   Reply With Quote
Old 12th March 2013, 03:31   #18  |  Link
dwilbank
Registered User
 
Join Date: Sep 2012
Posts: 12
Love the "find silence" script, but now how could I make it write out just the first and/or last frames where there is silence?

following johnmayer's example...

I would make i the last frame and j the previous frame,

Then create another && condition and put the "i" and "j" into AudioMax?

Somehow I fear that wouldn't work, would it?

What is the "0" in AudioMax(0) ?

Thanks
dwilbank is offline   Reply With Quote
Old 12th March 2013, 05:10   #19  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Quote:
Originally Posted by dwilbank View Post
What is the "0" in AudioMax(0) ?
Generally the best place to find such info is in the documentation:

Code:
Conditional Audio Filters - MinMaxAudio v0.2

Usage:

Computes the root mean square, maximal or minimal value over all samples in all channels,
or just over all samples in channel, and outputs the value (in decibels) as a float.
It's a conditional audio filter, so the computation is done framewise. The audio is converted
to float internally.


Syntax:

AudioMax(channel) # maximal volume in channel (framewise)
AudioMin(channel) # minimal volume in channel (framewise)
AudioRMS(channel) # root mean square volume in channel (framewise)
# channel = 0 (default) means that the max/min/rms is taken over all samples in all channels (framewise)

Examples:

v = BlankClip(pixel_type="YV12")
a = Tone(type="Triangle", frequency=2, level=0.4)
w = AudioDub(v,a) #.Histogram(mode="audiolevels")
#w = ScriptClip(w, "Subtitle(String(AudioMax(1)))")
w = ScriptClip(w, "Subtitle(String(AudioRMS(0)))")
#w = ScriptClip(w, "Subtitle(String(AudioMin(1)))")
w = w #.ConvertToRGB32.AudioGraph(20)
return w

Note that the values are given in decibels (see also histogram docs for an explanation).

License:

Licensed under GPL by Wilbert Dijkhof
__________________
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 12th March 2013, 06:17   #20  |  Link
dwilbank
Registered User
 
Join Date: Sep 2012
Posts: 12
Thx

But the real question remains.
I see no way to make audiomax() pay attention to specific "i" and "j" frames like johnmayer did with averageluma()

Last edited by dwilbank; 12th March 2013 at 16:14.
dwilbank is offline   Reply With Quote
Reply

Tags
avisynth, black, detection, frames

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 07:57.


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