Log in

View Full Version : Writing text on a frame


jpsdr
10th May 2018, 10:18
Is there an "easy" way to display/write information on a frame, for analysis/working purpose.

For exemple, my filter would compute some datas on each frame, and after, i would like to write/display the results on the frame, so the displayed text would be something like that :
Frame number : xxxxx
Data1 : wwww
Data2 : yyyyy
etc....

Is it possible ? Easy ? Is there some filters which already do that i can look at the code to see how it's done ?

:thanks:

StainlessS
10th May 2018, 10:51
DDigit supports color, horizontal and vertical print @ character or pixel coords (Standard avs 2.6 colorspaces only).
DDigit:- https://forum.doom9.org/showthread.php?t=156888

See also included Info.h and InfoF.h (white text print only, as often used in metrics, Standard avs 2.6 colorspaces only)
The Info.h of May 2013 is included with this package (together with a
companion header, InfoF.h, providing Info.h with layout format printing).


The DDigitTest.cpp source provides demo source for using InfoF.h together with Info.h, and
"Avisynth CPP Interface for C Programmers" thread, has demo stub source.:- https://forum.doom9.org/showthread.php?p=1538557#post1538557

// DrawFStr() Draw a Formatted string of text at character position, a user defined member function.
// As with all class members defined outside of the class, it is preceded by the class name and scope operator.

void __stdcall INTERNALNAME::DrawFStr(PVideoFrame &dst,int x,int y,const char *format, ...)
{
// This member function added in v0.2, adds BOTH string and screen/layout formatting,
// eg '%f' for string and '\n' for screen/layout.

// Firstly, string formatting, into the buffer implemented in the class instance, formatted_buf[FMT_BUFSZ].
va_list args;
va_start(args, format);
_vsnprintf(formatted_buf,FMT_BUFSZ-1, format, args);
va_end(args);
// The above allows you to use this member function in the same way as eg printf("test=%d",i) ie DrawFStr(dst,x,y,"test=%d",i)

// The DrawFStrXXX fn's are implemented in the InfoF.h file and provide screen/layout formatting, eg '\'n and '\t'.
// As string formatting has already been done above (eg floats etc turned to character strings), and the below
// DrawFStrXXX functions provide screen/layout formatting, so full formatting is achieved on the video frame.
//
// Formatting control codes (as provided by InfoF.h):-
// '\n', Newline, positioning cursor 1 line down and at left edge of screen.
// '\r', Newline Special, moves 1 line down and positions cursor at on-entry X position.
// '\b', Backspace, obvious, not sure how useful this will be.
// '\f', Forward Space, again obvious, re-uses formfeed code for this. Again, maybe not so useful.
// '\t', Tab, @ character positions, every 4 characters.(relative screen LHS).
//
if(vi.IsPlanar()) DrawFStrPlanar(dst,x,y,formatted_buf);
else if(vi.IsYUY2()) DrawFStrYUY2(dst,x,y,formatted_buf);
else if(vi.IsRGB32()) DrawFStrRGB32(dst,x,y,formatted_buf);
else if(vi.IsRGB24()) DrawFStrRGB24(dst,x,y,formatted_buf);
}


EDIT: DDigit:

Names
https://s20.postimg.cc/a9e4myxkt/Col3_zpsytqlpfm5.jpg (https://postimg.cc/image/48gfpwayh/)

One Pixel at a time
https://s20.postimg.cc/9l9vhro8t/Col5_zpseayjyr9n.jpg (https://postimg.cc/image/sqd4rj2wp/)

Info.h/InfoF.h
Full Character Set
https://s20.postimg.cc/wue3k0yv1/Col0_zpscgsuxgex.jpg (https://postimg.cc/image/4hiltkd4p/)

Info.h/InfoF.h, FULL string + Screen formatting example. (bottom part of frame)

DrawFStr(dst,2,voff+2, // NOTE, DIFFERENT CALL ie DrawFStr()
"EVERYTHING BELOW (incl this) is 1 single printed string.\r"
"Combines both string (eg %%f) and screen (eg '\\n') formatting.\r\r"
"Frame: %-7u( Red / Green / Blue )\r"
" Fred: (%7.2f /%7.2f /%7.2f )\r"
" Ted: (%7.2f /%7.2f /%7.2f )\r"
" Bill: ( %3d / %3d / %3d )\r"
" Ben: ( %3d / %3d / %3d )\r"
" Jack: ( %3d / %3d / %3d )\r"
" Jill: ( %3d / %3d / %3d )\r"
"\t\t\t\tDATA is RANDOM ONLY\n\n"
,n,
rand()*255.0/RAND_MAX,rand()*255.0/RAND_MAX,rand()*255.0/RAND_MAX,
rand()*255.0/RAND_MAX,rand()*255.0/RAND_MAX,rand()*255.0/RAND_MAX,
rand()&255,rand()&255,rand()&255,rand()&255,rand()&255,rand()&255,
rand()&255,rand()&255,rand()&255,rand()&255,rand()&255,rand()&255
);

https://s20.postimg.cc/9t23s0ol9/Example_plugin.jpg (https://postimg.cc/image/u0fjkbm2h/)

EDIT: Convenient debug output stuff,

// Use as in:- dprintf("Hello %s",__DATE__); // Produces eg "Hello Oct 23 2017".
int __cdecl dprintf(char* fmt, ...) {
char printString[2048]="FDecimate2: "; // Must be null termed, eg "Test: " or ""
char *p=printString;
for(;*p++;);
--p; // @ null term
va_list argp;
va_start(argp, fmt);
vsprintf(p, fmt, argp);
va_end(argp);
for(;*p++;);
--p; // @ null term
if(printString == p || p[-1] != '\n') {
p[0]='\n'; // append n/l if not there already
p[1]='\0';
}
OutputDebugString(printString);
return int(p-printString); // strlen printString
}



EDIT: For AVS Script use, can use RT_Stats RT_Subtitle() which uses DDigit with optional color and formatting [Vertical print not implemented].

RT_Subtitle(clip source,string format,dat1,...,datn,int "align",int "x","y",bool "vcent"=false,bool "expx"=false,bool "expy"=false,int "esc"=1)
:- https://forum.doom9.org/showthread.php?t=165479&highlight=RT_Stats

For AVS script formatted File Writing, RT_Stats RT_WriteFile,
RT_WriteFile(String FileName, string format,dat1,...,datn,bool "Append"=False)

For AVS script formatted Debug output [for DebugView (Google)]
RT_DebugF(string format,dat1,...,datn,string "name"="RT_DebugF:",int "TabSz"=4)

StainlessS
30th May 2018, 12:27
jpsdr,
Did above post fix you up, just curious.
If did, then perhaps you would like to add high bit depth support to Info.h and/or DDigit,
me guesses that it would come in handy for the new plugs being implemented.

jpsdr
30th May 2018, 14:12
Thanks for this answer, sorry, i should have reply soonner indeed. I am just for now in gathering information stage. I've downloaded the code to use.
I'm not using it right now, but i will when i'll begin to work on my next project, because i'll need to have several frame datas displayed on it, to figure out how things are, etc..., usual needs when you're designing thing, i think you get the picture.
I don't think i'll need high bit depth, but if it's the case, i'll see then.