Log in

View Full Version : Looking for illegal Colours detection script


fonzzie31
20th February 2018, 13:20
Hello,

I'm working with v210 video files.
These video files are created when I digitized some NTSC analogue video master tapes.
The video signal is processed through a TBC before the digitize process.
I use a BlackMagic Decklink Studio Capture card.

Then the v210 video files are loaded into Adobe Premiere in order to be edited and re-mastered.

One of the tool I use can generate a video file showing every illegal colours in the video. Only the illegal colours are shown. The rest of the picture is black.

As the video files are about 60 mins length, I would like to find an avisynth script which does to following :

- Parsing an v210 video file (10bits YUV Uncompressed), in order to detect every frame which has other colors than black.
- Return a message telling which frames (frame number or TC) contain other colour than black.

This script will permit me to adjust the colour correction, very precisely in Adobe Premiere.

Any suggestions are welcomed :)
Awaiting your answers. Thanks in advance for your help.

kolak
20th February 2018, 14:35
Are you talking about out of gamut errors?

Get eyeheight plugin for Premiere and it will fix it for you automatically with decent end result.

http://eyeheight.com/wp_eye_int/downloads/broadcastsafe-for-premiere-pro/

If you want to detect frames which are black (or not) you can do it very easily with ffmepg/ffprobe:

https://stackoverflow.com/questions/18722747/can-you-put-the-result-of-a-blackdetect-filter-in-a-textfile-using-ffmpeg

this should be easier than avisynth.

You have also this:
https://forum.doom9.org/showthread.php?t=175219&page=2

johnmeyer
20th February 2018, 17:06
I have dozens of AVISynth scripts which test each frame to see if it satisfies some condition (e.g., average luma less than a certain amount, in order to detect "blank" frames). When the condition is satisfied, it writes the frame number to a text file which you can then use in your editing program to find those frames and take corrective action.

Some of these scripts perform the fix automatically.

I'd post one of these, but I am not clear at all what you are trying to detect. You describe the problem as "illegal colors". You then describe this further as any frame that contains any color other than black. So, my reading is that you have a video which is supposed to be black & white, like an old movie, but which contains some color artifacts that you don't want. If so, that would certainly be easy to detect. However, once detected, what do you actually want to do to the video? If you are actually dealing with a black & white video that has some color because of the chroma issues with VHS technology (which is much worse with NTSC than with the SECAM or PAL video you are probably dealing with), the simple thing is to just desaturate it, something that is a one step fix in most NLEs.

fonzzie31
20th February 2018, 17:21
Hello,

Let me try to explain exactly.

My NTSC videos are in full colour.

I use a premiere plugin named ColourFinesse.
Combined to other plugin included in Premiere, I can ask Premiere to show me for each frame if there still remains illegal colours.

Then what I got, is a frame with all legal colours masked in black. It remains only the part(s) of the frame with illegal colours.

For example, we have the video frame showing a room. The window in this room is light blue. If I ask premiere to show me remaining illegal colours, I'll get black frame except some parts of the light blue window.

My NTSC videos are in full colour.

The script will permit to tell me which frames in the video are not full black.

kolak
20th February 2018, 18:24
Read my previous post.
You either go easy (if you have money) and use plugin which will fix all your problems automatically or use ffmpeg/ffprobe- scripts are there.
It can be done with avisynth but I think its not the best method for this task.

I have very similar python script running ffmepg which detects from whole master places which are not black (and longer than x seconds).

StainlessS
20th February 2018, 18:46
This any good (I've never touched v210, and little experience with avs+, maybe below could be persuaded to work for you).

EDIT: Creates a non-black frames file.

#Avisource("D:\TEST.AVI")
A=ColorBars.KillAudio.Trim(0,-1).ConvertToYV12
B=A.Blankclip

A+B+A+B+A+B+A+B+A+B+A

FRAMES="D:\Frames.txt"

YVal = 16.0 # mod to suit eg 0.0, are U and V required ?
UVal = 128.0 # mod to suit eg
VVal = 128.0 # mod to suit eg
SHOW=True

RT_FileDelete(FRAMES)

GSCript("""
Function Fn(clip c,Float YVal,Float UVal,Float VVal,String Frames,Bool Show) {
c
Y=AverageLuma U=AverageChromaU V=AverageChromaV
if(Y!=YVal || U!=UVal || V!=VVal) {
if(Show) { Subtitle(RT_String("%d] Y=%.3f U=%.3f V=%.3f",current_frame,Y,U,V),Align=5,Size=24) }
RT_WriteFile(Frames,"%d",current_frame,Append=True)
} else {
if(Show) { Subtitle(RT_String("%d] Y=%.3f U=%.3f V=%.3f",current_frame,Y,U,V)) }
}
return last
}
""")

Args="YVal,UVal,VVal,Frames,Show"
Return GScriptclip("Last.Fn("+Args+")",Args=Args)

EDIT: Updated

I have very similar python script running ffmepg which detects from whole master places which are not black (and longer than x seconds).

Could easily do that too [but by frame count rather than seconds, EDIT: Should be v.fast for larger frame counts].

EDIT: Req RT_Stats, GSCript (if not avs+) and Grunt (dont know if included in avs+).

EDIT: Here, FindBlack(), Just to save me looking for it again (if necessary):- https://forum.doom9.org/showthread.php?p=1749896#post1749896

StainlessS
20th February 2018, 19:39
Script to (simulate) fix illegal color frames [you provide the real fix].


A=ColorBars.KillAudio.Trim(0,-1).ConvertToYV12 # A=Illegal color
B=A.Blankclip.Subtitle("Good Color")
A=A.Subtitle("Illegal Color")
A+B+A+B+A+B+A+B+A+B+A # test detect clip from 1st script [EDIT: But subtitled here]
#return last
ORIGINAL=ColorBars.KillAudio.Trim(0,-FrameCount).ConvertToYV12 # Pretend original clip of same length as test clip
ORIGINAL # Comment out to return fixed from detection clip

FRAMES="D:\Frames.txt"

Black = Last.FrameSel(Cmd=FRAMES,Ordered=True,Reject=True) # Good frames
NonBlack = Last.FrameSel(Cmd=FRAMES,Ordered=True) # Illegal color frames

#Return Black
#Return NonBlack

#Process NonBlack somehow
FixedNonBlack=NonBlack.Subtitle("Fixed-NonBlack",Align=5)

Return Last.FrameRep(FixedNonBlack,cmd=FRAMES) #.AudioDubEx(ORIGINAL) # Replace fixed frames back from whence they came.

Req FrameSel. [EDIT: FrameSel/Rep should work ok (I think) with avs+ [planar] colorspaces so long as dont use SHOW=True]

lansing
20th February 2018, 19:59
What the op is describing is that he's looking for a broadcast safe filter, which has been answered by kolak on the 2nd post. The filter should be able to detect the intensity of the saturation and keep it under legal broadcast range by reducing the oversaturated part of a color.

The "black" thing he's referring to is the mask made by the filter to make it easier to spot the problems, he's not really looking for a filter to detect black frames.

StainlessS
20th February 2018, 20:10
Yep, I get that, the above 2nd script just pulls out the bad frames for fixing (somehow, by whatever means), then puts them back.
No idea how to fix the illegal color myself, other than to convert to RGB and back again.

EDIT: And this is an Avisynth usage forum, perhaps the op does not use VS.

lansing
20th February 2018, 20:25
Speaking of the plugin, look at that price. It was free in Premiere until Adobe took it out in CC and now some shithead is selling it for £495, are you kidding me?

kolak
20th February 2018, 21:46
Not sure what you're talking about, but this was never free. As far as I know Premiere never had out of gamut fixing ability (definitely not the one which is based on EBU R103 spec).
Eyeheight is a small UK company which use to makes only hardware boxes for broadcast. They have nothing to do with Adobe.
They had first version which was slow and 8bit only, but this one wasn't free either.
Current version is GPU accelerated and price is realistic as such a software is mainly used by post houses which deliver to broadcast (they can make this money in 2h per editor). There is almost no other products like this. It's all rather hardware boxes which cost much bigger money.

kolak
20th February 2018, 21:53
Yep, I get that, the above 2nd script just pulls out the bad frames for fixing (somehow, by whatever means), then puts them back.
No idea how to fix the illegal color myself, other than to convert to RGB and back again.

EDIT: And this is an Avisynth usage forum, perhaps the op does not use VS.

Out of gamut errors are coming from YUV combination (they appear mainly in software which works in YUV) which after conversion to RGB produce illegal values. EBU R103 ( https://tech.ebu.ch/docs/r/r103.pdf) specifies what is treated as illegal and how many % of the frame has to be bad in order to be treated as error.
About every broadcaster requires supplied files to be free of out of gamut errors and "normally" is was done by hardware boxes in SDI chain. Now there is a need for software version and they started appearing.
Fixing them is about soft clipping in the way so YUV combinations stop producing bad RGB values.
Converting to RGB and back is a fix although very aggressive.
VS script was made to detect such an errors. Not sure if it's easy to translate to avs script, but probably not straight forward.

StainlessS
20th February 2018, 22:03
Yep thanx Kolak, I had already read your PDF link.
This topic has occurred before here in Usage (I think), but not sure if it ever had an Avs solution, Myrsloik seems to have solved it though in VS forum.

EDIT: Not sure, I think Gavino may have produced an animation script that showed out of gamut bad colors.

kolak
20th February 2018, 22:05
Yep thanx Kolak, I had already read your PDF link.
This topic has occurred before here in Usage (I think), but not sure if it ever had an Avs solution, Myrsloik seems to have solved it though in VS forum.

Yes, he helped me to polish it, although original idea wasn't his.
It was probably me who brought it here to avs, quite a long time ago. There was never a real solution made for it.

StainlessS
20th February 2018, 22:11
I googled something, and guess whose name came up at top of thread in first link: https://www.google.co.uk/search?source=hp&ei=TI6MWq_eGNL7kwW0oafIBg&q=gamut+near+wilbert+color+near+gavino+site%3Aforum.doom9.org&oq=gamut+near+wilbert+color+near+gavino+site%3Aforum.doom9.org&gs_l=psy-ab.3...1654.24830.0.25013.0.0.0.0.0.0.0.0..0.0....0...1c.1.64.psy-ab..0.0.0....0.w5I-DrCny7g

EDIT: And one of the links in that thread is I think the Gavino animation I mentioned:- https://forum.doom9.org/showthread.php?t=154731
Need Colors_rgb_avsi in plugins.

http://web.archive.org/web/20140315154448/http://img245.imageshack.us/img245/7905/coloryuv.gif

fonzzie31
21st February 2018, 09:16
Let me give you an example with some pictures.

The "full frame.jpg" is a frame from a Prince music video (NTSC Master source U-Matic tape). As you can see, or you can't see, there are some illegal colours, remaining in the frame.

In Premiere I use ColorFinesse in order to adjust precisely saturation and vibrance, for the whole video, but also for the highlights, midtones and shadows parts of the video. Then I add another plugin named "TV Colours" which permits me to mask the legal colours, in order to see if there are still illegal colours. So, I can render and export it. I'll have a black frame video, with sometimes frames showing illegal colours.

What I would like to do is to parse this video in order to detect the frames having other colours than black... like the illegal_colours.jpg. It will help me to adjust precisely the ColorFinesse settings again in order to remove the illegal colours remaining.

raffriff42
21st February 2018, 12:14
>What I would like to do is to parse this video in order to detect the frames having other colours than black

Sounds like you need WriteFile
http://avisynth.nl/index.php/WriteFile
# <source: YUV>

logpath="<set path here>"
limit = 235 ## threshold value

## file header
WriteFileStart(
\ Last,
\ logpath,
\ """ "Frames where YPlaneMax > " + String(limit) """
\ )

## file footer
WriteFileEnd(
\ Last,
\ logpath,
\ """ "(end of list)" """
\ )

## file data
WriteFileIf(
\ Last, [* source clip *]
\ logpath, [* output file *]
\ "YPlaneMax > " + String(limit), [* test condition *]
\ "current_frame", [* output: print current frame number *]
\ """ ": " """, [* output: print literal ': ' *]
\ "YPlaneMax") [* output: print max Y value *]

return Last

Note triple quotes - needed for literal output. Getting literal output is (for me) the most difficult aspect of using WriteFile.

To make sure you scan all frames, do the following in vdub or vdubFM:
- close script if open
- open script, position timeline @ frame 0
- File menu, Run video analysis pass
- let it run all the way through
- close the script

Sample output:Frames where YPlaneMax > 235
252: 240
304: 236
637: 240
829: 244
846: 237
1042: 236
(end of list)

fonzzie31
21st February 2018, 12:23
Thanks raffriff42, I'll try your script :)

kolak
21st February 2018, 14:45
This script shows frames which are out of 235 luminance limit.

If you want all frames which are not black change limit to 16 (assuming your black frames are ideal 16).

Gavino
1st March 2018, 11:38
Not sure, I think Gavino may have produced an animation script that showed out of gamut bad colors.
See the thread U and V ranges for valid RGB. In post #14 of that thread, I produced a function ShowBadRGB() which shows the areas of a YV12 clip that contain 'invalid RGB', with the 'good' pixels replaced by a specified color (default black).

kolak
1st March 2018, 13:16
Yes, but as far as I understand this doesn't take into account allowed thresholds/bad area % specified in EBU-R103.

VS script takes it into account and "adapts" itself to 8/10bit sources.

StainlessS
1st March 2018, 19:38
In the linked Gavino animation, do my eyes decieve me or is Y level shown as producing valid output, both slightly above 235 and slightly below 16 ?

EDIT: Again here:-
http://web.archive.org/web/20140315154448/http://img245.imageshack.us/img245/7905/coloryuv.gif

EDIT: U and V also go 'outside' of 16 239 range.

Asmodian
2nd March 2018, 12:09
The animation is a full range animation, Y goes between 0-255 too.