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 Development

Reply
 
Thread Tools Search this Thread Display Modes
Old 6th August 2012, 10:28   #21  |  Link
jmac698
Registered User
 
Join Date: Jan 2006
Posts: 1,867
Like I said, you can use the call plugin to run a batch script or whatever, but it's only run once before the script starts.

Here's how to read and plot pixels:
Code:
Function GetPixel(clip clip, int x, int y) {
    #Return luma of a pixel
    current_frame=0
    clip
    IsYUY2 ? ConvertToYV12 : clip#AverageLuma only works on planar.  YV12 is planar.
    pointresize(6,6,x,y,1,1)#Blow up the pixel at x,y by 6 times (minimum possible with resize)
    int(AverageLuma)
}

Function PutPixel(clip clip, int x, int y, int luma) {
    #Plot a pixel
    clip
    ClipIsYV12=IsYV12
    ClipIsYV12 ? ConvertToYUY2 : last
    pointresize(width*2, height)
    u=128
    v=128
    pixel=blankclip(last, color_yuv=luma*65536+u*256+v, width=2, height=1)
    layer(last, pixel, "add", 256, x*2, y)#Layer only works with YUY2
    pointresize(width/2, height)
    ClipIsYV12 ? ConvertToYV12 : last
}
I have to tell you, I'm using an undocumented trick here. You can read a pixel once at the start on a specific frame, by setting current_frame. This lets you use the runtime variables, like AverageLuma. Remove the "current_frame=" line to use it as a runtime function. With the runtime way; averageluma has to appear inside scriptclip or one of the others.

The array implementation in avslib is quite slow. I have the same thoughts of a meta-data per-frame with another clip; but it could be added at the bottom. The garbage in the last few lines can be be cropped out.

You can extend this to RGB with showred.converttoyv12 for example. You could also make a kind of array in a clip by plotting pixels and reading them.

My slicer and addcode plugins can also read and plot int's on a line of video.
http://forum.doom9.org/showthread.ph...74#post1582574

for myself: keywords pset, plot, plot a pixel, plot(x,y), pset(x,y)

edit: thank you me! I swear, this is the 5th time I've searched for this post.

Last edited by jmac698; 1st March 2015 at 12:30.
jmac698 is offline   Reply With Quote
Old 6th August 2012, 13:22   #22  |  Link
TheFluff
Excessively jovial fellow
 
Join Date: Jun 2004
Location: rude
Posts: 1,100
Quote:
Originally Posted by jmac698 View Post
And saying it's a filter graph is just semantics; I can write a loop that does nothing but calculate a factorial, if I want to. You could even argue that it's Turiing complete and therefore like any other language. There's even GUI plugins to Avisynth; you can get keyboard input and interact with it just like a real program. Just let the video play forever and forget that it's a video, cause it's really a program
The fact that the scripting language allows you to write external functions in a general purpose language that gives you arbitrary side-effects does not change the fact that the scripting language just describes a graph. The entire script has a return value, which is the end point of that graph.

Quote:
Originally Posted by turbine View Post
Object-oriented has been the standard for a long time due to its advantages. On the contrary it's the intuitive way to way to represent video and audio, the standard "is a" and "has a" questions we ask ourselves when creating classes. A video "has a" set of frames. A frame "has" one or more images (1080p vs. 480p, 1.77 AR vs. 1.33 for example), an image "has a" set of pixels.
Object oriented programming focuses on the interaction between data structures, but video frame buffers don't exactly need to talk to each other. The data structures you describe are all very simple and there's nothing particularly object oriented about them.

I don't deny that object oriented programming is very useful in many scenarios, but pretty much none of its big features (inheritance, encapsulation, polymorphism, data abstraction) are of any particular use for video processing. Complain about Avisynth script all you want, but the dataflow/graph paradigm was definitely the correct choice for the kind of video clip manipulation Avisynth was intended for. As for writing actual video filtering functions, you pretty much have to do that in a low-level compiled and unmanaged language in order to get it fast enough, and when you're on that level you pretty much work with plain byte arrays, so there's really no point to object-orienting anything.

Doing individual pixel manipulations in an interpreted language/managed code environment isn't really very useful in practice because even on modern hardware it's REALLY SLOW for any resolution bigger than a postage stamp, and at the time when Avisynth was designed it was, of course, a completely ridiculous idea, so the scripting language really doesn't try to help you when it comes to that kind of stuff.

Quote:
Originally Posted by turbine View Post
Performance would take a hit, but isn't really a big concern when the weak link in the chain is typically the codec (x264 usually) and it's not realtime. Realtime frame-serving would arguably be a different story.
looks like you've never used a real-world avisynth script to actually do anything productive (hint: the frameserver is almost always the biggest bottleneck by far)

Quote:
Originally Posted by turbine View Post
I realized it could be useful to create a parallel clip to store metadata, a RGB32 pixel can store a 32bit float or four ASCII characters, for example.
The complete inability to store any sort of per-frame or even per-clip metadata is one of Avisynth's greatest weaknesses.

Quote:
Originally Posted by turbine View Post
Uncompressed audio could work if it's possible to read/write individual samples...
It is, if you write a plugin. Start to see a pattern emerging here?

Spoiler: the pattern is "don't use a simplistic graph description language if what you really want is an unmanaged environment that lets you poke arbitrary byte addresses". If you want C, write C.

Quote:
Originally Posted by turbine View Post
On the other hand, if it is still commonly used, there's probably still value in adding a new run mode so that a user could choose to have it execute all commands as written, instead of it's current "lazy" execution model. Doesn't it seem like that would solve so many common problems?
Okay, let me try to explain this one final time.
Avisynth scripts are not executed. The script is compiled, yes, but the result of the compilation is a chain of filter functions, not a program that is executed. Absolutely nothing happens with it until the host application (which loaded the script) requests a video frame. At that point, Avisynth pulls the frame through the function chain, and it's only at this point that things happen in "filter" functions that have side effects (i.e. ImageWriter). In other words, if you want to call a function on each frame of a clip, you need to make sure all frames of that clip are actually requested, either directly by the host application or indirectly via something in your script (careful with that though, you may or may not run into funny issues if frames are requested multiple times).

Your idea that the environment should execute scripts imperatively is, of course, completely ridiculous. Just try thinking it through for a while and you'll probably realize why it's completely wrong to try to process an entire video clip procedurally instead of via a per-frame callback-driven data flow (just think of what kind of memory footprint a source filter that returns an entire clip at once would have). Incidentally, your idea would require changing so much of Avisynth that it'd be easier to just rewrite the entire thing from scratch.

Last edited by TheFluff; 6th August 2012 at 18:12.
TheFluff is offline   Reply With Quote
Old 6th August 2012, 17:06   #23  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
@TheFluff,
Excellent Tutorial
__________________
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 6th August 2012, 20:09   #24  |  Link
gyth
Registered User
 
Join Date: Sep 2011
Posts: 86
Quote:
Originally Posted by TheFluff View Post
I don't really understand what you want to accomplish with your script
Tar with built-in lossy compression???
gyth is offline   Reply With Quote
Old 6th August 2012, 21:12   #25  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Quote:
Originally Posted by TheFluff View Post
I don't really understand what you want to accomplish with your script
Quote:
Originally Posted by gyth View Post
Tar with built-in lossy compression???
I think TheFluff was replying to Turbine, and you were referring to your post:

Code:
a=ImageSource("sm444.png")

a.subtitle("not rendered").ImageWriter("not_rendered", type="png")

a.subtitle("rendered").ImageWriter("rendered", type="png")
In the 1st ImageWriter line the result is thrown away (temp assigned to Last and then overwritten
by following line), so the result is never used (neither is the source of the result, ie 1st ImageWriter,
nor the source of that ie the 'not rendered' Subtitle
) as it plays no part in the output.

a simple
Code:
a=a.subtitle("not rendered").ImageWriter("not_rendered", type="png")
would solve the problem but for the two different outputs required by your script, one with
"not_rendered" on it and the other with "rendered", assuming that you actually want two different
outputs with two different subtitles, then you would need to somehow use the result of the 1st
ImageWriter line in the second.
(The problem here is there is only one output, but you want
to have a clip with two different subtitles, and not one overwriting
the other nor one without and one with a subtitle.
[in the words of a famous movie script, 'There Can Be Only One'])

There are any number of ways this could be done, eg

Code:
a=ImageSource("sm444.png")

Tmp = a.subtitle("not rendered").ImageWriter("not_rendered", type="png")

dummy = Tmp.FrameCount()
dummy = dummy - dummy

a.subtitle("rendered").ImageWriter("rendered",start=0+dummy, type="png")
Not tested but should I think work. (There are probably better ways)

EDIT: The dummy arg forces the 1st Imagewrite chain to be processed
as the output is reliant on both subtitled paths through the
graph, the advantages are that it is a highly efficient way
of selecting what is and is not necessary due to various conditions,
but results in seemingly silly kludges to force 'side effects' to occur.
Avisynth could well do some things better, but is quite remarkable in what
is does and the filter graph model itself is in no need of change.
__________________
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; 6th August 2012 at 22:56.
StainlessS is offline   Reply With Quote
Old 7th August 2012, 00:50   #26  |  Link
gyth
Registered User
 
Join Date: Sep 2011
Posts: 86
Quote:
Tar with built-in lossy compression???
That was my guess as to what turbine was trying to do.

Quote:
Originally Posted by StainlessS View Post
Not tested but should I think work. (There are probably better ways)
And these better ways should be collected and linked to a faq and ImageWriter.

This one works for me
Code:
a = ImageSource("sm444.png")

a0 = a.subtitle("not rendered").ImageWriter("not_rendered", type="png")

a1 = a.subtitle("rendered").ImageWriter("rendered", type="png")

stackhorizontal(a1, a0).crop(0, 0, a1.width, a1.height)
gyth is offline   Reply With Quote
Old 7th August 2012, 00:58   #27  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Perhaps a "Return me a zero", and "Return me a one" should be added to the clip status returns
so you dont have to be silly and be so creative.
Was hard to tell what comment you were replying to, sorry, got it wrong.
The '???' was a clue but I EVENTUALLY got it wrong just the same, Shoot me!
__________________
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; 7th August 2012 at 01:48.
StainlessS is offline   Reply With Quote
Old 7th August 2012, 02:27   #28  |  Link
gyth
Registered User
 
Join Date: Sep 2011
Posts: 86
Maybe add a function designed to produce side effects easily. (while minimizing overhead)
Code:
function render_both_return_first(clip c1, clip c2) {
    ????
}
gyth is offline   Reply With Quote
Old 7th August 2012, 12:04   #29  |  Link
turbine
Registered User
 
Join Date: Jul 2012
Posts: 7
Thanks, for the replies, guys.... I have had my hands full with a big event, I'll have more time later today or tomorrow.

Fluff, As far as script execution goes you're arguing terminology -- I get it; it's event driven, the processing or "execution" of the various commands happens when a frame is requested.
turbine is offline   Reply With Quote
Old 9th August 2012, 00:19   #30  |  Link
jmac698
Registered User
 
Join Date: Jan 2006
Posts: 1,867
And here's how to "execute" an Avisynth script without showing any frames:
http://forum.doom9.org/showthread.php?t=165528

You could wrap this all up into a program that processes text files, and never know it had anything to do with video. Rename it "sh.exe" and no one would be the wiser!
jmac698 is offline   Reply With Quote
Old 9th August 2012, 00:32   #31  |  Link
TheFluff
Excessively jovial fellow
 
Join Date: Jun 2004
Location: rude
Posts: 1,100
Quote:
Originally Posted by jmac698 View Post
And here's how to "execute" an Avisynth script without showing any frames:
http://forum.doom9.org/showthread.php?t=165528

You could wrap this all up into a program that processes text files, and never know it had anything to do with video. Rename it "sh.exe" and no one would be the wiser!
That still retrieves all frames, even if it just discards them immediately after retrieving them.

Last edited by TheFluff; 9th August 2012 at 00:51.
TheFluff is offline   Reply With Quote
Old 14th August 2012, 17:53   #32  |  Link
pbristow
Registered User
 
pbristow's Avatar
 
Join Date: Jun 2009
Location: UK
Posts: 263
Quote:
Originally Posted by turbine View Post
Fluff, As far as script execution goes you're arguing terminology -- I get it; it's event driven, the processing or "execution" of the various commands happens when a frame is requested.
Turbine, no he isn't! He's pointing out fundamental design concepts that have to do with achieving the best possible video processing performance on barely adequate hardware. Many of us are doing complex, heavyweight processing that absolutely dwarfs the CPU time and memory allocation required by a mere codec, and in that context, Avisynth's *fundamental design concept* of only processing the frames that will actually make a difference to the output is absolutely the right one *in most cases*. In the rare cases that it causes a problem, there are various workarounds available.

Avisynth has some flaws, sure, but "not being a totally different animal" isn't one of them!

I'm going to have to agree with the overall concensus here and say, if you want a tool that works in a completey different way to AviSynth, then use a tool that isn't AviSynth. If the tool you want doesn't exist yet, then start recruiting a team to create one. (Hint: Annoying the people who might very well be glad to join such a team by denigrating the work they've already done on another project is probably not conducive to succesful recruitment!).

If you can figure out how to make the new tool compatible with Avisynth plug-ins, you (and your users) would get the benefit of all the work that's already been done over the last decade in creating a huge variety of awesomely powerful video processing tools. You could even give it an Avisynth-like syntax, if you think that would be helpful... But you would probably find that designing an appropriate syntax to suit the way your new tool works would be better.

Good luck!
pbristow is offline   Reply With Quote
Old 7th September 2012, 09:41   #33  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,431
[Catching up on recent threads after a long absence]

Quote:
Originally Posted by StainlessS View Post
Code:
a=ImageSource("sm444.png")

Tmp = a.subtitle("not rendered").ImageWriter("not_rendered", type="png")

dummy = Tmp.FrameCount()
dummy = dummy - dummy

a.subtitle("rendered").ImageWriter("rendered",start=0+dummy, type="png")
Not tested but should I think work. (There are probably better ways)

EDIT: The dummy arg forces the 1st Imagewrite chain to be processed
as the output is reliant on both subtitled paths through the
graph ...
That doesn't work, since Framecount is known at compile time and does not require run-time access to frame data.
You need something that forces rendering of the frames, such as gyth's example:
Quote:
Originally Posted by gyth View Post
Code:
a = ImageSource("sm444.png")

a0 = a.subtitle("not rendered").ImageWriter("not_rendered", type="png")

a1 = a.subtitle("rendered").ImageWriter("rendered", type="png")

stackhorizontal(a1, a0).crop(0, 0, a1.width, a1.height)
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 7th September 2012, 19:45   #34  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Thank you Maestro,
glad you're back, think D9 was about to go into mourning.
__________________
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 September 2012, 15:51   #35  |  Link
Chikuzen
typo lover
 
Chikuzen's Avatar
 
Join Date: May 2009
Posts: 595
why don't you use ImmaAVS?
ImmaRead() has 'size_x' and 'size_y' options to resize/pad automatically to the size you specified.
__________________
my repositories
Chikuzen is offline   Reply With Quote
Reply

Tags
file i/o, frame, imagesource, imagewriter, metadata

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 13:31.


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