PDA

View Full Version : ApplyMessage function


Gavino
11th October 2009, 18:03
Sometimes plugins require to write text on a frame, either as part of their basic functionality (eg DVInfo), or for error reporting or diagnostics. This can be done using Subtitle (via env->Invoke) to write the text but is quite slow, especially if the text needs to vary from frame to frame.

It would be useful if plugin writers had access to the internal function ApplyMessage, used internally by Avisynth for this purpose. The question of making it available was asked as long ago as 2003 (see here), but was never answered.

I think it could be done by providing a new function within IScriptEnvironment in avisynth.h, eg
void ApplyMessage(PVideoFrame* frame, const VideoInfo& vi, const char* message, int size,
int textcolor, int halocolor)
which would be a wrapper to call the 'real' ApplyMessage from new code in avisynth.cpp.
(Incidentally, the existing ApplyMessage has two arguments (bgcolor and env) which are not actually used.)

Currently, if you want to build your own ApplyMessage, you can use the relevant parts of the Avisynth source code in your plugin (subject to GPL of course), but this involves carving out parts of:
- text-overlay.h and .cpp : ApplyMessage, LoadFont and class Antialiaser
- convert.h : RGB2YUV
- internal.h : ScaledPixelClip, class _PixelClip, extern PixelClip
- focus.h : PixelClip definition (odd place for this to be!)

Being able to just write env->ApplyMessage(...) would be much more convenient.
I suppose one drawback is that plugins needing this prospective new function could not be used on earlier Avisynth versions, but by that argument you could never extend IScriptEnvronment at all.

Fizick
11th October 2009, 21:30
For simple text output we currently often use info.cpp with hardcoded font (see plugins by Graft and me)
// original IT0051 by thejam79
// add YV12 mode by minamina 2003/05/01

Internal option may be useful.

IanB
12th October 2009, 00:04
@Gavino,

ApplyMessage is every bit as slow as the rest of the text rendering routines. The slowness is in the creating the text to paint, not in the actual painting. Compare ShowFrameNumber(), which renders and paints new text every frame, with SubTitle(), which just paints the same text every frame, with an Animate() of a SubTitle() which also renders and paints new text every frame.

But, yes making ApplyMessage() available would be useful, but I am more inclined to expose Info() maybe I will do both or combine them somehow, it was already on the todo list just a fair way down.


@Fizick,

> // original IT0051 by thejam79
> // add YV12 mode by minamina 2003/05/01

Thanks, Sh0dan added Info to the code but lost the Genealogy, I will add back the rest of the attributions.