PDA

View Full Version : Statistics output file


mustardman
23rd August 2003, 06:40
I want to analyse a video stream for errors, caused by bad sync on the original material, which has caused "jittering" (the image jumps up and down by one or two lines *randomly*).

I know how to analyse each frame for this error (just look at the first/second/third line and analyse the luminance). A skipped line is usually black, but its' level does vary (10 to 50). A picture that is already dark can have a "normal" line with luminance less than 40!

So, writing a script (using ConditionalFilter) to test the first (etc) line is *almost* possible. Unfortunately, the parameter list is...
ConditionalFilter(clip testclip, clip source1, clip source2, string filter, string operator, string value, [bool show])

"value" is a constant, and can only been determined by trial and error. A slightly wrong value can cause the problem to remain, or actually introduce it to a good frame! In addition, the value can vary throughout a clip.

One solution is to be able to scan through a video stream, and output a textfile with stats on each frame (not just the first line like what I need)... such as
0, 12, 50, 249
1, 14, 46, 253
2, 13, 55, 232

First column is the frame number...

I have not been able to find such a beast within AVIsynth. Is there one?

Using this I can look at the text file and very easily sort it for min/max...

Another (perhaps easier, but not as useful or generic) solution is to make ConditionalFilter able to use "filter" on both sides of the "operator".

Any comments?

Mustardman.

neily
23rd August 2003, 10:50
I have been thinking about analytical stuff recently from a different perspective, and wish there were more analytical functions available too.

I can't think of a perfect solution to your problem, but wondered whether cropping your videostream to a height of 2, creating a black blankclip based on this, then doing a compare might help. The resultant log file should help discriminate between the 3 situations of no black lines, one black line, and 2 black lines. What it doesn't do is tell whether one of two black line situation is a bad line.

Depending on the character of the bad black line, ie does it's luminance vary, refining the above to compare the left and right halves of the croped image may add something.

I will be interested to see what other ideas people come up with.

Wilbert
23rd August 2003, 17:07
One solution is to be able to scan through a video stream, and output a textfile with stats on each frame (not just the first line like what I need)... such as
0, 12, 50, 249
1, 14, 46, 253
2, 13, 55, 232

First column is the frame number...
If the other three are the average (or minimal/maximal) Y, U and V values, then this is possible. What kind of stats do you exactly want?

mustardman
24th August 2003, 00:38
@neily
When the line is bad (caused by bad sync) the blackness of the line depends on the picture content. The stuff is from an old analog video camera, hence the recording process is... well... pretty suspect.

When the image content of the top of the picture (near the bad inserted line) has luminance ~230 then the bad line ~50. When this area of the image is black, luminance ~40, then the bad line ~20. Making it really hard (impossible?) to choose a value that works for all frames.

If you could compare two lines (eg: luma(line1) < luma(line2) ) then it would be easy (well, easier!).

Just had a thought, is it possible (ConditionalFilter) to specify the "filter" as somthing like 'luma(line1) - luma(line2)' and compare to 0 ??? I'll have to try it...

@Wilbert
For my application, the values I would want would be...
Frame,average(luma(line0)),average(luma(line1)),average(luma(line2))
I can make up dummy clips called line0/1/2 easily with crop.

But of course that is a bit specific. Such a thing would be of benifit to considerably more people if the number of aruments could vary for 1 up to ??. The frame number would always have to be included - bit of a waste without some sort of reference!
Useful functions might be...
max(luma(clip)), average(luma(clip)), min(luma(clip)), colour average/difference figures. The colour values are of no interest to me personally..!

Thanks for the interest,
Mustardman

neily
24th August 2003, 02:17
I still don't think it is exactly possible to do what you want to do without cropping your video into seperate streams each consisting of a single line and doing a Compare. Without being able to see a sample of the problem, it is difficult to suggest alternatives, but if the bad frames do jump, I wonder whether they could be detected as scene changes. I guess it depends on the content and noise.

By the latter, I mean something like:

Compare(vid00,Trim(vid00,1,0),"YUV","test.log")

edit
Or what about doing a scene change detection on the top 2 lines:

vid00=AVISource("your.avi").Crop(0,0,width,2)
Compare(vid00,Trim(vid00,1,0),"YUV","test.log")
edit

I am also not clear about what you want to do with the bad frames. Do you want to edit them manually (i.e. you want a text file output) or do you want to script avisynth to deal with them automatically?

mustardman
26th August 2003, 00:39
Hi Neily,

Unfortunately I do not have a location to put samples - if you wish I could email you small pieces of the frames.

What appears to happen is one of the fields in the frame goes bad, resulting in a frame (MJPG) where one field is fine, the other has 'slipped' leaving a black line where it should have started... perhaps some numbers...

Normal frame = 0 1 2 3 4 5 (Odd & Even feilds)
Bad frame = 0 x 2 1 4 3 (the odd frame has slipped 1 line)

A filter to shift only each feild can fix the problem, by removing the "x" line, and shifting the odd field back to where it should be.

But anyhow, I didn't realise that "compare" had a file output function, I will check it out. I had also not considered a scene detection - but would this work with interlaced? Perhaps the video stream could be split into fields, fiddled, and then re-combined?

In answer to your last question, I was hoping a text file output would give me an idea of what sort of values I should use for detecting a bad line, so I could use that value in "conditionalfilter". It would also show me what sort of frame ranges have bright/dark material, so I could possibly process a several minute file in two or three chunks (rather than frame by frame :( )

Thanks for your time,
Mustardman.

neily
26th August 2003, 23:51
Wilbert,

When you said that it was possible to output the information to a text file, I was wondering how?

Wilbert
27th August 2003, 10:10
Yes, but only properties of the clip and of the frames. You have to use the call plugin for this:

http://forum.doom9.org/showthread.php?s=&threadid=46506

The plugin can be downloaded from WarpEnterprises collection page. The framenumber can also be written to the text file (using scriptclip), but I forgot how.