11-06-2018, 10:35 AM | #1 |
Human being with feelings
Join Date: May 2017
Location: Leipzig
Posts: 6,621
|
Getting individual pixels (via gfx_evalrect() -- edited title)
I would like to suggest a function to the video-processor, that allows me to actually get the content of a frame/input.
Sometimes, I would love to compare the actual content of two frames on a pixel-level. One such example would be tracking objects, analysing the content of a picture, finding out, if a video needs to be stabilized. So I would love to get a 2-d-array, which holds the actual frame as bitmap with individual pixels to work with, as well as being able to blit this array again. So for that, I would love to ask for the function: image_array = gfx_get_image(input) - where image_array is an array of the like: image_array[x][y][r] - red-color-value image_array[x][y][g] - green-color-value image_array[x][y][b] - blue-color-value image_array[x][y][a] - alpha-color-value This is based on the question about ability to compare two video-items, from this thread: https://forum.cockos.com/showthread....21#post2054521
__________________
Use you/she/her.Ultraschall-Api Lua Api4Reaper - Donate, if you wish On vacation for the time being... |
11-07-2018, 03:55 PM | #2 | ||
Human being with feelings
Join Date: Oct 2009
Posts: 99
|
Quote:
From the docs: Quote:
Code:
//Pixel blend //@param 1:byp "bypass?" 0 0 1 0 1 //@param 3:mode "mode (1=add 2=sub)" 1 1 2 1.5 1 //@param 5:plotCode "plot code?" 0 0 1 0 1 curX=0; function m(msg) local(s,h,id) ( id = match("%s",msg) ? "%s" : msg|0===msg ? "%d" : "%f"; sprintf(s=#,id, msg); gfx_str_measure(s,0,h); gfx_set(1,1,1,1); gfx_str_draw(s,0,curX); curX+=h; ); in1=0; in2=1; lcolorspace=colorspace; colorspace='RGBA'; gfx_blit(in1); op=mode==1 ? "+" : "-"; sprintf(#code, " r=min(255,max(0,r%ssr)); g=min(255,max(0,g%ssg)); b=min(255,max(0,b%ssb)); a=1; ", op,op,op,op); !byp ? gfx_evalrect(0,0,project_w,project_h,#code,1,in2); plotCode ? ( gfx_set(0.15); gfx_fillrect(0,0,project_w*0.4,project_h); m(#code); ); colorspace=lcolorspace; |
||
11-09-2018, 05:27 AM | #3 |
Human being with feelings
Join Date: May 2017
Location: Leipzig
Posts: 6,621
|
Thanks, good to hear that
__________________
Use you/she/her.Ultraschall-Api Lua Api4Reaper - Donate, if you wish On vacation for the time being... |
04-02-2020, 05:35 AM | #4 |
Human being with feelings
Join Date: Mar 2012
Location: Italy
Posts: 1
|
adding some more hints...
Hello, I hope nobody gets offended for necroposting this or for stating things that should be obvious to Video Processor programmers.
I was trying to write a simple code in order to overlay some film grain to a video but without "losing clarity" on the processed video. I found this thread really really useful but I had to spend more than a few hours doing a lot of research and guess work in order to understand this. The documentation of Video Processor is on one hand very short and concise, which is just perfect for everyday reference and quick start for the advanced user, on the other hand it is almost impossible to find a clear explaination of the knowldgebase needed for non-advanced users that are approaching this system. Just to make an example of the doubts I had before: - How is the video signal exactly routed from the clips on the tracks up to the video window output? How do I get the input signal? How do I write an output signal? - Where does "r%ssr" (and similar) comes from ? What are you doing with that "op,op,op,op" ?? I don't know why but I always get really confused with strings. In the documentation these answers are a bit in between the lines and I found them not so easy to get. Also there are a few things mixed together... it gets complicated here! Don't get me wrong, the example of wwwmaze does an amazing job in showing the possibilities with the tool. I just would like to repost a much simpler, cropped down and slightly different version of his code, with a lot of comments, in order to help beginners better understand the basics and ultimately what is really going on in his code. I hope this gives some more hints in order to better understand the documentation. Code:
//Pixel blend // the elaboration algorithm is written into a string at lines 17 - 23 // elaboration takes place in gfx_evalrect(...) at line 39 in1 = 0; // index of video signal that comes from the track where this fx is put in2 = 1; // index of video signal that comes from lower priority tracks lcolorspace = colorspace; // save input colorspace colorspace = 'RGBA'; // change color space to RGBA gfx_blit( in1 ); // put "in1" in the framebuffer (which is the video output of this fx) // put the pixel elaboration code inside the string #code // r,g,b,a are video buffer's red, green, blue and alpha channel // sr,sg,sb are src's red, green, blue channel // in this example src = in2, see gfx_evalrect(...) at the end sprintf(#code, " r = min(255, max(0, max(r, sr))); // the highest red channel wins g = min(255, max(0, max(g, sg))); // the highest green channel wins b = min(255, max(0, max(b, sb))); // the highest blue channel wins a = 1; // (nothing is transparent) "); // prepare the bits of "flags" for gfx_evalrect() FLAGS_PREVENT_MULTIPROCESSING = 1; // process pixels in order FLAGS_IGNORE_OUTPUT = 0; // ??? I'm not sure what this does exactly FLAGS_MULTIPROCESS_DIRECTION = 0; // 0 = horizontal (1 = vertical) FLAGS_MULTIPROCESS_SENSE = 0; // 0 = from the left (or the top) , 1 = opposite sense // compose the "flags" variable flags = 0; // init flags value flags |= FLAGS_PREVENT_MULTIPROCESSING << 0; // set first bit value flags |= FLAGS_IGNORE_OUTPUT << 1; // set second bit value flags |= FLAGS_MULTIPROCESS_DIRECTION << 2; // set third bit value flags |= FLAGS_MULTIPROCESS_SENSE << 3; // set fourth bit value // process the framebuffer (which contains "in1") and the "in2" video with the "#code" gfx_evalrect(0,0,project_w,project_h,#code,flags,in2); // change back to input colorspace colorspace = lcolorspace; |
04-02-2020, 02:58 PM | #5 |
Human being with feelings
Join Date: Mar 2018
Posts: 14
|
Thanks, Robbi, I am definitely looking for more explicitly-commented code like that to learn from! Reverse-engineering the existing examples has been very time consuming and I've only gotten so far.
|
04-06-2020, 06:50 AM | #6 | |
Human being with feelings
Join Date: Mar 2018
Location: Cologne
Posts: 1,362
|
Quote:
__________________
☆.。.:*・°☆.。.:*・°☆.。.:*・°☆REAPER//✿◔‿◔)°☆.。.:*・°☆.。.:*・°☆
|
|
04-06-2020, 07:31 AM | #7 |
Human being with feelings
Join Date: Mar 2018
Location: Cologne
Posts: 1,362
|
This runs very smooth on my laptop. If you don't mind I put your preset into the video presets thread in the video section. Many thanks.
__________________
☆.。.:*・°☆.。.:*・°☆.。.:*・°☆REAPER//✿◔‿◔)°☆.。.:*・°☆.。.:*・°☆
|
Thread Tools | |
Display Modes | |
|
|