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. |
9th November 2011, 20:42 | #41 | Link |
Registered User
Join Date: Jan 2006
Posts: 1,867
|
@Fluff
You have to realize that Avisynth script is, by far, the easier way for me to create specific videos as I require. I am not a Windows programmer and do not know enough Video For Windows to create a new video, and anyhow I still think it would be tremondously complicated to try to learn that now. Otherwise, I need to research the AVI file format, come up with a header, research the raw format, and do the byte packing or complicated calculations to draw directly into Y1 U Y2 V bytes in 32 bit words, which are then padded. Not simple at all. The only other way I know of is the math expressions feature in ImageMagick. Please, tell me even one method which is simpler than what I'm doing, which won't take an hour of reading API's, or file formats. |
9th November 2011, 20:58 | #42 | Link |
Registered User
Join Date: Jan 2006
Posts: 1,867
|
@Fluff
http://msdn.microsoft.com/en-us/library/ms779636.aspx So I will actually try what you suggest. I should write : 'RIFF' (filesize) ('AVI') ckID ckSize ... I also have to create an AVI index... there really seems to be a lot of research and calculations involved. Do you see my point? |
9th November 2011, 21:05 | #43 | Link | |
Excessively jovial fellow
Join Date: Jun 2004
Location: rude
Posts: 1,100
|
Quote:
Anyway, while there is certainly no shortage of sane(r) ways to do what you want, the obvious answer here is to write an Avisynth plugin. Blending a single-color rectangle on top of an existing image is literally about fifteen lines of rendering code in addition to the maybe 50 lines of Avisynth boilerplate stuff that you can just copypaste from somewhere. There is not exactly a shortage of good sample code, since most plugins are open source. The entire GetFrame() function in the original assrender (my first and so far only Avisynth plugin), which essentially blends RGB32 bitmaps with a given opacity and a given pixel offset on top of an RGB32 image, is about 60 lines of code total, which includes about 10 lines of comments. The inner rendering loop is 17 lines. Go take a look at lachs0r's C implementation (which takes care of some really complicated shit like rendering RGB32 on top of YV12 with chroma interpolation and all, without converting the source image like overlay() does) and you're basically almost done already. It's a sunday afternoon project, really. Last edited by TheFluff; 9th November 2011 at 21:14. |
|
9th November 2011, 21:26 | #44 | Link | |
Registered User
Join Date: Jan 2006
Posts: 1,867
|
@Fluff
Ok, I tried another possibility. You can draw with imagemagick. Great. But I still can't specify YUV colors: http://www.imagemagick.org/script/co...ions.php?#fill You are right, there's lots of easy ways to draw RGB shapes, but nearly impossible to draw YUV colors. So I looked into converted raw files. Code:
convert -size 720x480 movie.yuv Quote:
I've had to give up, however, as I was not able to modify the sample code to work. The best I'd be able to do is not change a thing except for the pixel calculation part, thus resulting in a plugin with useless parameters. And I really doubt there's a plugin with just enough int's in it's parameters to cover my needs. It's not as simple as copy & paste, though part of it is. Parsing and checking the parameters takes some though of course. Perhaps you could write a sample pure C plugin that does nothing but average two clips, then I could base my article off that. Please release as GPL. Last edited by jmac698; 9th November 2011 at 21:32. |
|
9th November 2011, 21:32 | #45 | Link | |
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,431
|
Quote:
You had this more or less written almost a year ago and I pointed out the errors then. What more do you need to know? |
|
9th November 2011, 21:40 | #47 | Link | |
Excessively jovial fellow
Join Date: Jun 2004
Location: rude
Posts: 1,100
|
Quote:
I have no interest in your project (beyond questioning its sanity). Furthermore, I don't have any experience at all with the avisynth_c interface, so you probably know more about it than me. |
|
9th November 2011, 21:49 | #48 | Link |
Registered User
Join Date: Nov 2009
Posts: 2,361
|
@jmac698, I don't know why you quote me so late in time, as I'm already using the nice lutspa function you gave me.
Code:
function BoxMask(clip clip, int "x1", int "x2", int "y1", int "y2", bool "show"){ w=clip.width() h=clip.height() x1=string(default(x1,0)) x2=string(default(x2,w)) y1=string(default(y1,0)) y2=string(default(y2,h)) show=default(show, false) mt_lutspa(clip, mode="absolute", yexpr="x "+x1+" >= x "+x2+" <= & y "+y1+" >= y "+y2+" <= & & 255 0 ?", chroma= "128").trim(0,-1).FreezeFrame(0, FrameCount(clip)-1, 0) show?mt_lutxy(clip,last,"x 0.75 * y 0.25 * + 2 /"):last} Last edited by Dogway; 9th November 2011 at 21:53. |
9th November 2011, 21:50 | #49 | Link |
Registered User
Join Date: Jan 2006
Posts: 1,867
|
@Fluff
There are pre-determined YUV formats which ImageMagick will accept. I think the convert option only accepts 1:1:1 sampling. I'm still uncertain if it expects planar or interleaved, and/or if I can specify which to use. I certainly do not see any command line options with the words "planar" in them. Anyhow, thanks for your suggestions. I would desperately love to be able to write plugins, and have started another thread on that topic, perhaps I will figure it out someday. Otherwise, ImageMagick remains hopeful, however I think you will have to admit, that after following all your suggestions, what I have started re: DrawRect is not as insane as it seems. You obviously have a different skillset than me at this point, so please be aware of the differences. |
9th November 2011, 21:53 | #50 | Link |
Registered User
Join Date: Jan 2006
Posts: 1,867
|
@Dogway,
I didn't realize you had finished your function. I would like to create a draw shapes plugin, finally there will be an efficient way to do this. I need to draw some 'fancy shapes' but they aren't things that could be handdrawn, for example Avia type test charts like resolution (which involves various sinewaves). |
1st December 2011, 09:51 | #51 | Link | |
Registered User
Join Date: Jan 2005
Location: Praha (not that one in Texas)
Posts: 863
|
Quote:
I had here and there also issues with this mt_merge-->254 thing, so I just btw made my own merge;-) Tell me if this meets your needs in that case: Code:
RMerge(c1,c2,m,mode=256,sse=0) #sse=0 necessary before I add optimization |
|
4th August 2014, 09:26 | #52 | Link |
Registered User
Join Date: Jan 2006
Posts: 1,867
|
I needed a way to draw shapes and found my own script again.
Just to summarize the thread, 1 I investigated imagemagick and subtitles renderers; both require specifying colours only in RGB 2 Some YUV colours cannot be specified in RGB without using negative values, and neither of the above tools allow this 3 Even the range of YUV colours which can be made from positive RGB values, can't all be made, because of precision loss in the mapping between coordinate systems. (think of communicating an x,y coordinate from another coordinate system that's slanted 45 degrees; (2,2) in the slanted version maps to (1.414,1.414) in the second version, so you can see how gaps can occur). 4 In summary, there is no way to use positive, 8bit RGB colours to specify all video YUV colours. 5 I need opacity to range 0-256 because otherwise, there is an error when using all-white (white=255, 99.6% opacity=255/256, 255*255/256=254. A fully opaque white should give 255. The small error of 254 means that further masking steps won't match when looking for 255. 6 Drawing shapes in a paint program still has the same problem; you can only specify colours in RGB. Also, the shapes I need would be very tedious to create by hand - imagine drawing standard colourbars, or a frequency sweep (something which can only be calculated). 7 I'd like to expand these tools to draw sinewaves, circles and special YUV colours like I/Q (from the standard colourbars). 8 You can import raw YUV in imagemagick but it's expecting a specific raw format, which I haven't found documented. There are no options to specify variations of the format. ps I'm actually working on an improved de-comet algorithm now, and I *still* have no better way to programaticaly create YUV test patterns Last edited by jmac698; 4th August 2014 at 09:40. |
4th August 2014, 16:48 | #53 | Link | |
Excessively jovial fellow
Join Date: Jun 2004
Location: rude
Posts: 1,100
|
Quote:
Also, here's some food for thought: RGB24 and YUV 444 both happen to have 24 bits per pixel. What a neat coincidence! If only there was an AssumePixelFormat() (hint: it's probably trivial to write). Of course, blending doesn't work the same in YUV as it does in RGB but at least it gives you a trivial way to draw shapes using existing tools that only support RGB. Overlay() should solve the rest. Last edited by TheFluff; 4th August 2014 at 16:54. |
|
4th August 2014, 21:12 | #54 | Link |
Registered User
Join Date: Jan 2006
Posts: 1,867
|
AssumePixelFormat would have been very useful when I was trying to do operations in YUV like http://forum.doom9.org/archive/index.php/t-108018.html. Then I could use RGB calculations and move back to YUV (but that was before I discovered masktools). I remember going through all sorts of hoops to perfectly copy YUV planes <> to RGB. I believe it was the use of YtoUV, UtoY, VtoY, and using greyscale and mergeRGB. Now I wish masktools worked in RGB! The problem remains.
I'm allowing an opacity range up to 256 for the same reason http://avisynth.nl/index.php/Overlay does, to allow fully transparent and fully opaque. 255/256 refers to the internal calculation that is done; the value of the mask is interpreted as a fraction of 256 (and yes, Overlay needs to do 16bit calculations). You also have to be aware that Overlay does extra manipulations that I want to avoid (which is also why it's slow), such as colour interpolation. ps anyhow, I got the job done now. I made my test video and solved a programming problem I was having. Avisynth to the rescue I made progress on my de-comet plugin, the problem is cluster analysis of Guassian mixing, and I want to use maximum expectation. Last edited by jmac698; 4th August 2014 at 21:56. |
4th August 2014, 22:42 | #55 | Link | |||
Excessively jovial fellow
Join Date: Jun 2004
Location: rude
Posts: 1,100
|
Quote:
0/255 == 0 Please explain to me in what way this does not allow fully transparent and fully opaque. I'm not exactly sure why Overlay() uses 0-256 internally but a random guess says it's to get a right shift by 8 instead of a division by 255 in a calculation in an inner loop. In other words, it's probably a 90's optimization that doesn't really matter today, and I suspect it's actually off-by-one in some situations. It's most definitely not to allow "fully transparent and fully opaque"; any scale would allow that. As Gavino said three years ago: Quote:
Quote:
edit: I was right about the 128 thing. mt_merge uses the same wonky 256 and like I suspected it's sometimes off-by-one; see https://github.com/tp7/masktools/issues/12 Last edited by TheFluff; 4th August 2014 at 23:50. |
|||
5th August 2014, 19:18 | #56 | Link | |
Moderator
Join Date: Nov 2001
Location: Netherlands
Posts: 6,364
|
Quote:
I guess the following should also work: Code:
rgb_clip = ... y = rgb_clip.ShowRed("Y8") # not documented yet u = rgb_clip.ShowGreen("Y8") v = rgb_clip.ShowBlue("Y8") YToUV(y,u,v) |
|
8th August 2015, 20:27 | #58 | Link |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
|
Creates a Marker
Code:
AVISource("E:\V\StarWars.avi") Blk = Last.Blankclip(width=64,height=64,Length=1) #InFix = RT_string("(x==0|x==%d|y==0|y==%d)?128:0",Blk.Width-1,Blk.Height-1) InFix = RT_string("((x==0|x==%d|y==0|y==%d)&(x<4|x>=%d)&(y<4|y>=%d))?255:0",Blk.Width-1,Blk.Height-1,Blk.Width-4,Blk.Height-4) Marker=Blk.mt_lutspa(relative = false,yExpr=mt_Polish(InFix), chroma = "128") Overlay(Marker,x=(Width-Marker.width)/2,y=(Height-Marker.Height)/2,Mode="Exclusion") return last Code:
__ __ | | |_ _| EDIT: Here as function to create mask for Overlay, Hit=false for some kind of 'Miss' and true for some kind of 'Hit' (detect). Code:
Function RectMarker(clip c,int W, Int H,Bool "Hit") { # req RT_Stats & mt_tools_2, Returns YV12 frame WxH same FPS as c and without audio Hit=Default(hit,False) InFix = (Hit) \ ? RT_string("(((x<=1|x>=%d|y<=1|y>=%d)&(x<4|x>=%d)&(y<4|y>=%d)|(x==0|x==%d|y==0|y==%d)))?255:0", W-2,H-2,W-4,H-4,W-1,H-1) \ : RT_string("((x<=1|x>=%d|y<=1|y>=%d)&(x<4|x>=%d)&(y<4|y>=%d))?255:0", W-2,H-2,W-4,H-4) c.Blankclip(width=W,height=H,Length=1,pixel_type="YV12").Killaudio return mt_lutspa(relative = false,yExpr=mt_Polish(InFix), chroma = "128") } Code:
# ... MissMask = RectMarker(c,BlkW,BlkH,false) HitMask = RectMarker(c,BlkW,BlkH,true) MissMark = MissMask.BlankClip(Color=MissColor) HitMark = HitMask.BlankClip(Color=HitColor) # ... (hit!=0) ? Overlay((hit==2)?HitMark:MissMark,x=x,y=y,Mask=(hit==2)?HitMask:MissMask,Mode="Blend") : NOP
__________________
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; 10th August 2015 at 09:08. |
2nd April 2017, 12:39 | #59 | Link |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
|
Small update to prev post Rectal Marker, for marking your territory or something.
Code:
Function Elliptical_Marker(clip c,int W, Int H,Bool "Soft") { # Req mt_tools_2, Returns YV12 frame WxH same FPS as c and without audio Soft=Default(Soft,False) # INFIX_H="(((x-.5)^2 +(y-.5)^2) < .25 ? 255 : 0" # INFIX: Elliptical Disk (Hard Edge) :: mode = "relative", Radius=0.5, Rad^2=0.25 :: SOFT_Inner rad:(Rad*0.9)^2~=0.2 # INFIX_S="((x-.5)^2+(y-.5)^2)<.2?255:(((x-.5)^2+(y-.5)^2)<.25?(.25-((x-.5)^2+(y-.5)^2))*5100):255" # INFIX: Elliptical Disk (Soft Edge) :: (.25-0.2)*5100=255 : (.25-.25)*5100=0.0] :: mode="relative", 0.25=1.0 : 0.2~=0.9 rpn = (!Soft) \ ? "x 0.5 - 2 ^ y 0.5 - 2 ^ + 0.25 < 255 0 ?" [* RPN: Elliptical Disk [Hard Edge] *] \ : "x 0.5 - 2 ^ y 0.5 - 2 ^ + 0.2 < 255 x 0.5 - 2 ^ y 0.5 - 2 ^ + 0.25 < 0.25 x 0.5 - 2 ^ y 0.5 - 2 ^ + - 5100 *" [* RPN: Elliptical Disk [Soft Edge] *] c.Blankclip(width=W,height=H,Length=1,pixel_type="YV12").Killaudio return Last.mt_lutspa(mode = "relative", expr = rpn, chroma = "-128" ) } EDIT: And an EllipticalDisk marker, used in this case as an Overlay mask. Code:
Function Elliptical_Marker(clip c,int W, Int H,Bool "Soft") { # Req mt_tools_2, Returns YV12 frame WxH same FPS as c and without audio Soft=Default(Soft,False) # INFIX_H="(((x-.5)^2 +(y-.5)^2) < .25 ? 255 : 0" # INFIX: Elliptical Disk (Hard Edge) :: mode = "relative", Radius=0.5, Rad^2=0.25 :: SOFT_Inner rad:(Rad*0.9)^2~=0.2 # INFIX_S="((x-.5)^2+(y-.5)^2)<.2?255:(((x-.5)^2+(y-.5)^2)<.25?(.25-((x-.5)^2+(y-.5)^2))*5100):255" # INFIX: Elliptical Disk (Soft Edge) :: (.25-0.2)*5100=255 : (.25-.25)*5100=0.0] :: mode="relative", 0.25=1.0 : 0.2~=0.9 rpn = (!Soft) \ ? "x 0.5 - 2 ^ y 0.5 - 2 ^ + 0.25 < 255 0 ?" [* RPN: Elliptical Disk [Hard Edge] *] \ : "x 0.5 - 2 ^ y 0.5 - 2 ^ + 0.2 < 255 x 0.5 - 2 ^ y 0.5 - 2 ^ + 0.25 < 0.25 x 0.5 - 2 ^ y 0.5 - 2 ^ + - 5100 *" [* RPN: Elliptical Disk [Soft Edge] *] c.Blankclip(width=W,height=H,Length=1,pixel_type="YV12").Killaudio return Last.mt_lutspa(mode = "relative", expr = rpn, chroma = "-128" ) } Avisource("F:\V\StarWars.avi") # Source YV12 Sym=Avisource("F:\V\XMen2.avi").Trim(5000,0) # Overlay clip W=(Width/16) * 4 H=(Height/16) * 4 Sym=Sym.BilinearResize(W,H) El = Sym.EllipticalMarker(W,H,true).Loop(Sym.Framecount) Return OverlayClip(Last,Sym,S=100,E= -Sym.FrameCount,x= -(Sym.Width+16),y= -(Sym.Height+16),mask=El) EDIT: Changed to Soft edge disk.
__________________
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; 28th December 2019 at 18:16. |
3rd April 2017, 04:00 | #60 | Link |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
|
Script to make any movie under the sun, seem interesting. [EDIT: Req Masktools v2.0]
Code:
# BouncingBallMovie.avs Function Elliptical_Marker(clip c,int W, Int H,Bool "Soft") { # Req mt_tools_2, Returns YV12 frame WxH same FPS as c and without audio Soft=Default(Soft,False) # INFIX_H="(((x-.5)^2 +(y-.5)^2) < .25 ? 255 : 0" # INFIX: Elliptical Disk (Hard Edge) :: mode = "relative", Radius=0.5, Rad^2=0.25 :: SOFT_Inner rad:(Rad*0.9)^2~=0.2 # INFIX_S="((x-.5)^2+(y-.5)^2)<.2?255:(((x-.5)^2+(y-.5)^2)<.25?(.25-((x-.5)^2+(y-.5)^2))*5100):255" # INFIX: Elliptical Disk (Soft Edge) :: (.25-0.2)*5100=255 : (.25-.25)*5100=0.0] :: mode="relative", 0.25=1.0 : 0.2~=0.9 rpn = (!Soft) \ ? "x 0.5 - 2 ^ y 0.5 - 2 ^ + 0.25 < 255 0 ?" [* RPN: Elliptical Disk [Hard Edge] *] \ : "x 0.5 - 2 ^ y 0.5 - 2 ^ + 0.2 < 255 x 0.5 - 2 ^ y 0.5 - 2 ^ + 0.25 < 0.25 x 0.5 - 2 ^ y 0.5 - 2 ^ + - 5100 *" [* RPN: Elliptical Disk [Soft Edge] *] c.Blankclip(width=W,height=H,Length=1,pixel_type="YV12").Killaudio return Last.mt_lutspa(mode = "relative", expr = rpn, chroma = "-128" ) } Function DrawBounce(clip c) { # Physical window coords Squash = (G_bounceY == 0) B = (Squash) ? G_Squashed_Ball : G_Ball Xrel = (b.Width - G_Ball.Width) / 2 phyX = Round(G_bounceX * (c.Width - G_Ball.Width - xrel)) phyY = Round((1.0 - G_bounceY) * c.Height) - B.Height (G_Sym.IsClip) \ ? c.Overlay(Squash?G_Sym_Squashed:G_Sym,x=phyX,y=phyY,mask=B) \ : c.OverLay(B.BlankClip(Color=G_BALLCOLOR,Length=1),x=phyX,y=phyY,Mask=B) return Last } Function MoveBounce(clip c) { # Logical coords (0.0 -> 1.0, cartesian) bX = G_bounceX + G_bounceXstep Global G_bounceXstep = (0.0 < bX < 1.0) ? G_bounceXstep : -G_bounceXstep # Wall Bounce, Switch direction next time Global G_bounceX = (0.0 > bX) ? 0.0 : (bX > 1.0) ? 1.0 : bX bY = Sin(G_bounceAngle) * G_bounceMax Global G_bounceY = (bY < 0.0) ? 0.0 : bY bAng = G_bounceAngle + G_bounceAngleStep Global G_bounceAngle = (bAng > PI) ? 0.0 : bAng return c.DrawBounce } Function RandF() {return Rand / 32767.0} ###### #Avisource("F:\V\SexInTheCity.avi") #Avisource("F:\V\XMen2.avi") ColorBars.ShowFrameNumber.KillAudio Rand(Seed=True) ### Global G_BALLCOLOR = $C020FF BALLSZ = 128 SQUISH = 8 SOFT = True SYM = True # False = Plain bouncing ball ### GENERAL CONTROL for bouncer (1.0=norm) SPEED = 1.0 BOUNCEHEIGHT = 1.0 ### Global G_bounceMax = BOUNCEHEIGHT * (1.0-Float(BALLSZ)/Height) Global G_bounceXstep = 0.005 * SPEED # Xpos increment Global G_bounceAngleStep = (0.01 + RandF * 0.04) * SPEED # Step angle ### Start pos Global G_bounceX = RandF # Current X position Global G_bounceY = RandF # Current Y position Global G_bounceAngle = RandF * PI ###### Global G_Ball = Last.Elliptical_Marker(BALLSZ,BALLSZ,SOFT) Global G_Squashed_Ball = Last.Elliptical_Marker(BALLSZ+SQUISH,BALLSZ-SQUISH,SOFT) Global G_Sym = (SYM) ? BilinearResize(BALLSZ,BALLSZ) : 0 Global G_Sym_Squashed = (SYM) ? BilinearResize(G_Squashed_Ball.Width,G_Squashed_Ball.Height): 0 ScriptClip("return MoveBounce")
__________________
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; 28th December 2019 at 18:01. |
|
|