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

Closed Thread
 
Thread Tools Search this Thread Display Modes
Old 4th February 2017, 21:43   #2981  |  Link
DJATOM
Registered User
 
DJATOM's Avatar
 
Join Date: Sep 2010
Location: Ukraine, Bohuslav
Posts: 252
Quote:
Originally Posted by MysteryX View Post
oh... but on 32-bit, I could call ConvertToDoubleWidth twice; if it would convert 32-bit to 16-bit. Is there a simple script that would achieve that?

Code:
ConvertBits(32)
ConvertBits(16)
ConvertToDoubleWidth()
This would first discard 16-bit of the 32-bit, which is not what I'm looking for.
Lol, I just realized that I misread what pinterf said, so I was right about truerange. Set it 'false' and ConvertToDoubleWidth will work for 32 bit input.
DJATOM is offline  
Old 4th February 2017, 21:46   #2982  |  Link
pinterf
Registered User
 
Join Date: Jan 2014
Posts: 1,659
32 bit is float. 16 bit is integer. ConvertToDoublewidth is a hack to fake both the format and frame dimension.
pinterf is offline  
Old 4th February 2017, 21:55   #2983  |  Link
MysteryX
Soul Architect
 
MysteryX's Avatar
 
Join Date: Apr 2014
Posts: 2,209
How about integrating these conversion functions into the core DLL? In that way, plugin developers could write 16-bit code using the native format, and still support Stack16 by calling these standard conversion functions. Otherwise, I might as well copy and integrate that code into my DLL to avoid dependencies.

Basically, I keep the standard v2.6 conversion code, and on Avisynth+, I'm branching into another code that does it using the new functions -- and supports extra formats. The Stack16 conversion functions would be useful for any developer doing that. I also want to keep using DoubleWidth to preserve compatibility with v2.6
MysteryX is offline  
Old 4th February 2017, 22:08   #2984  |  Link
DJATOM
Registered User
 
DJATOM's Avatar
 
Join Date: Sep 2010
Location: Ukraine, Bohuslav
Posts: 252
Quote:
Originally Posted by pinterf View Post
32 bit is float. 16 bit is integer. ConvertToDoublewidth is a hack to fake both the format and frame dimension.
Indeed. But if we need to process our clip with filter which can process exposed 32-bit data, but does not support avs+ colorspaces, that will help.

Last edited by DJATOM; 4th February 2017 at 22:10.
DJATOM is offline  
Old 5th February 2017, 00:25   #2985  |  Link
MysteryX
Soul Architect
 
MysteryX's Avatar
 
Join Date: Apr 2014
Posts: 2,209
I would need a "ConvertToQuadripleWidth" if I want to allow someone to use AviSynthShader while allowing overflow values; as all other formats are INT. Again, I keep the double-width hack to maintain compatibility with AVS 2.6, and since I'm doing a data transfer to the GPU, it doesn't matter how the metadata is set.
MysteryX is offline  
Old 5th February 2017, 01:21   #2986  |  Link
real.finder
Registered User
 
Join Date: Jan 2012
Location: Mesopotamia
Posts: 1,836
Quote:
Originally Posted by MysteryX View Post
How about integrating these conversion functions into the core DLL? In that way, plugin developers could write 16-bit code using the native format, and still support Stack16 by calling these standard conversion functions. Otherwise, I might as well copy and integrate that code into my DLL to avoid dependencies.

Basically, I keep the standard v2.6 conversion code, and on Avisynth+, I'm branching into another code that does it using the new functions -- and supports extra formats. The Stack16 conversion functions would be useful for any developer doing that. I also want to keep using DoubleWidth to preserve compatibility with v2.6
no more hack please, and you can keep the lsb (Stack16) supports just like what pinterf did in mvtools
__________________
See My Avisynth Stuff
real.finder is offline  
Old 5th February 2017, 08:52   #2987  |  Link
real.finder
Registered User
 
Join Date: Jan 2012
Location: Mesopotamia
Posts: 1,836
Quote:
Originally Posted by Reel.Deel View Post
Reverted the changes


Code:
#rgtools # starting from v0.94, the plugin self registers the MT mode
SetFilterMTMode("removegrain",         MT_NICE_FILTER)
SetFilterMTMode("repair",              MT_NICE_FILTER)
SetFilterMTMode("verticalcleaner",     MT_NICE_FILTER)
SetFilterMTMode("clense",              MT_NICE_FILTER)
should

Code:
#rgtools # starting from v0.94, the plugin self registers the MT mode
SetFilterMTMode("removegrain",         MT_NICE_FILTER)
SetFilterMTMode("repair",              MT_NICE_FILTER)
SetFilterMTMode("verticalcleaner",     MT_NICE_FILTER)
#SetFilterMTMode("clense",              MT_NICE_FILTER)
it's better, cuz when reduceflicker is true, MULTI_INSTANCE MT mode is reported in RGtools
__________________
See My Avisynth Stuff
real.finder is offline  
Old 5th February 2017, 17:36   #2988  |  Link
MysteryX
Soul Architect
 
MysteryX's Avatar
 
Join Date: Apr 2014
Posts: 2,209
Is there a way to pass a format as a string and get the properties of that format? For example, a parameter "FormatOut" might be set to "YUVAP16", and in my code, I want to know a few things. Does that format have an alpha plane? What is BitsPerComponent?

Of course I can get it done with a bunch of IF, but the code then gets very clumsy especially with all the new formats.
MysteryX is offline  
Old 5th February 2017, 17:50   #2989  |  Link
pinterf
Registered User
 
Join Date: Jan 2014
Posts: 1,659
Quote:
Originally Posted by MysteryX View Post
Is there a way to pass a format as a string and get the properties of that format? For example, a parameter "FormatOut" might be set to "YUVAP16", and in my code, I want to know a few things. Does that format have an alpha plane? What is BitsPerComponent?

Of course I can get it done with a bunch of IF, but the code then gets very clumsy especially with all the new formats.
Declare a temporary VideoInfo variable, fill its pixel_type, now you can request all its properties.
pinterf is offline  
Old 5th February 2017, 19:17   #2990  |  Link
edcrfv94
Registered User
 
Join Date: Apr 2015
Posts: 78
I update r2420 from r1858, have a problem with MP_Pipeline.
Very high CPU usage and very slow.

r2420 1.6 fps 40-50% CPU usage
r1858 26 fps 16-20% CPU usage

Quote:
MP_Pipeline("""

SetMemoryMax(500)

input = "K:\test.m2ts"
LWLibavVideoSource(input, threads=1)

src = last

### export clip:src
### prefetch: 92,88
### ###

SetMemoryMax(2000)

src
kf_awarpFCB_test(depth=8, thresh=96, blur=3, lsb_in=true, lsb_out=true, YV12_out=false, cplace="MPEG2")
dither_out()

function kf_awarpFCB_test(clip src, int "depth", int "thresh", int "blur", bool "lsb_in", bool "lsb_out", bool "isYV24", bool "YV12_out", string "cplace")
{

depth = Default(depth, 6)
thresh = Default(thresh, 96)
blur = Default(blur, 3)

lsb_in = Default(lsb_in, false)
lsb_out = Default(lsb_out, true)
isYV24 = Default(isYV24, false)
YV12_out = Default(YV12_out, false)

w = width(src)
h = (lsb_in == false) ? height(src) : height(src)/2

src16 = (lsb_in == false) ? src.Dither_convert_8_to_16() : src

Y416 = src16.Dither_resize16(w, h, csp="YV24", kernel="bicubic", a1=0.6, a2=0.4, cplace=cplace)
YV24 = (isYV24 == false) ? Y416.DitherPost(mode=7) : (lsb_in == false) ? src : src.DitherPost(mode=7)
emask = YV24.ConvertToY8().aSobel(thresh, 1).aBlur(blur, 1, 1)
uv_fcb = YToUV(YV24.UToY8().awarp(emask, depth, 1), YV24.VToY8().awarp(emask, depth, 1), YV24)
Dither_limit_dif16(Y416, uv_fcb.Dither_convert_8_to_16(), thr=1.0, elast=2, y=2, u=3, v=3)

YV12_out ? last.Dither_resize16(w, h, csp="YV12", kernel="bicubic", a1=0, a2=0.5) : last

lsb_out ? last : last.DitherPost(mode=7)

return last
}

""")

Last edited by edcrfv94; 5th February 2017 at 20:55.
edcrfv94 is offline  
Old 7th February 2017, 11:16   #2991  |  Link
pinterf
Registered User
 
Join Date: Jan 2014
Posts: 1,659
Quote:
Originally Posted by edcrfv94 View Post
I update r2420 from r1858, have a problem with MP_Pipeline.
Very high CPU usage and very slow.

r2420 1.6 fps 40-50% CPU usage
r1858 26 fps 16-20% CPU usage
I think I found the reason. r2043 is ok, r2068 is slow.

Beginning from r2068 Eval-like and runtime functions are detected internally in order to apply an appropriate cache and MT behaviour for them.

But MP_Pipeline is an external Eval-like filter and the core is not able to detect it. In my test, when I have set a hardcoded line to apply this rule on MP_Pipeline, the speed returned to the original. I don't know yet how to detect such external filters automatically, from the core point of view it is a filter that takes a string parameter and returns a clip. Like a source filter.
Perhaps we have to introduce a registration command for this case, e.g. RegisterScriptFunction(string filter_name) (?)
pinterf is offline  
Old 8th February 2017, 13:44   #2992  |  Link
real.finder
Registered User
 
Join Date: Jan 2012
Location: Mesopotamia
Posts: 1,836
since there are no more than 8 bit in 411, then should convertbits show error Message, but it's not

if I use convertbits(16) in yv411 source it will work but with unsupported colour format
__________________
See My Avisynth Stuff
real.finder is offline  
Old 9th February 2017, 09:44   #2993  |  Link
pinterf
Registered User
 
Join Date: Jan 2014
Posts: 1,659
Quote:
Originally Posted by real.finder View Post
since there are no more than 8 bit in 411, then should convertbits show error Message, but it's not

if I use convertbits(16) in yv411 source it will work but with unsupported colour format
True. I expect to have increasing number of reports for 10+ bit stuff after reaching a critical mass in the number of non-8bit users and supporting scripts.

Currently under progress:
Integrate GScriptClip and co.
Better handling MP_Pipeline-like filters (speedwise)
Playing with masktools.
pinterf is offline  
Old 9th February 2017, 14:02   #2994  |  Link
tormento
Acid fr0g
 
tormento's Avatar
 
Join Date: May 2002
Location: Italy
Posts: 1,548
Quote:
Originally Posted by pinterf View Post
True. I expect to have increasing number of reports for 10+ bit stuff after reaching a critical mass in the number of non-8bit users and supporting scripts.
When every plugin we need will be 16 bit and we will work internally at 16 bit to output in 8 bit, I think you will be flooded
__________________
@turment on Telegram
tormento is offline  
Old 9th February 2017, 20:54   #2995  |  Link
MysteryX
Soul Architect
 
MysteryX's Avatar
 
Join Date: Apr 2014
Posts: 2,209
Pinterf, you're already flooded porting every plugin to 16-bit Now get to work
MysteryX is offline  
Old 10th February 2017, 00:25   #2996  |  Link
Reel.Deel
Registered User
 
Join Date: Mar 2012
Location: Texas
Posts: 1,177
Quote:
Originally Posted by MysteryX View Post
Pinterf, you're already flooded porting every plugin to 16-bit Now get to work
Since you're a programmer also, help him out
Reel.Deel is offline  
Old 10th February 2017, 03:59   #2997  |  Link
MysteryX
Soul Architect
 
MysteryX's Avatar
 
Join Date: Apr 2014
Posts: 2,209
Quote:
Originally Posted by Reel.Deel View Post
Since you're a programmer also, help him out
I got a lot of priorities to focus on already (but I guess that also applies to most of us). For now I must get 16-bit to work with AviSynthShader (somehow I'm having a hard time to get that simple task done), and release the next version of Natural Grounding Player as the YouTube downloader doesn't work anymore with the currently released version. And even more importantly... working on my business instead of putting too much time on Open Source projects, and publishing some more books.

There's the Floyd-Steinberg Dithering I could work on, but then, it would only be a CPU version. Someone else would have to write it in assembly. I can write a C# 432hz Music Player and playlist manager in a few hours, but C++ is much harder for me.

So yeah... first must empty the pipeline of work to do.
MysteryX is offline  
Old 10th February 2017, 18:32   #2998  |  Link
MysteryX
Soul Architect
 
MysteryX's Avatar
 
Join Date: Apr 2014
Posts: 2,209
Quote:
Originally Posted by pinterf View Post
Declare a temporary VideoInfo variable, fill its pixel_type, now you can request all its properties.
Except that pixel_type is an int, not a string. In C# I could easily convert a string to its enumeration value but that won't work in C++. It seems the only way is to create a map with all the possible values and get the int matching the string from the map. A standard function to accomplish that would be nice. Is it possible to include such a function in the header file so that it also works with older versions of Avisynth? Actually I'll need to call such a function from the script so I'll need to create a custom filter for it anyway, unless I'm missing something.

So there are 2 tasks:
1. Get current format as a string so the script can use it.
2. Get VideoInfo from string to know the properties of specified format.

Formats were quite easy to handle in Avisynth 2.6 because there were only a few pixel formats. With the new version, however, the amount of formats increased exponentially.

The best might be to create a map and use it for both tasks.

Last edited by MysteryX; 10th February 2017 at 18:50.
MysteryX is offline  
Old 10th February 2017, 19:36   #2999  |  Link
MysteryX
Soul Architect
 
MysteryX's Avatar
 
Join Date: Apr 2014
Posts: 2,209
I believe code like this should do the job to convert back and forth between INT and STRING format types. It might be useful to have something similar in the header.

Code:
#pragma once
#include <map>
#include <string>
#include "avisynth.h"

class PixelFormatParser {
	typedef std::map<std::string, int> my_map;
	my_map enumMap;
public:
	PixelFormatParser();

	int GetPixelFormatAsInt(std::string format) {
		my_map::const_iterator iValue = enumMap.find(format);
		if (iValue == enumMap.end())
			return 0;
		return iValue->second;
	}

	std::string GetPixelFormatAsString(int pixel_type) {
		int key = 0;
		std::string Result = std::string("");
		for (auto &i : enumMap) {
			if (i.second == pixel_type) {
				Result = i.first;
				// If format ends with P8, continue searching to return the other name variant.
				if (i.first.length() < 3 || i.first.substr(i.first.length() - 2, 2) != std::string("P8"))
					break;
			}
		}
		return Result;
	}

	VideoInfo GetVideoInfo(int pixel_type) {
		VideoInfo Result;
		Result.pixel_type = pixel_type;
		return Result;
	}

	VideoInfo GetVideoInfo(std::string format) {
		VideoInfo Result;
		Result.pixel_type = GetPixelFormatAsInt(format);
		return Result;
	}
};

PixelFormatParser::PixelFormatParser() {
	enumMap["RGB24"] = VideoInfo::CS_BGR24;
	enumMap["RGB32"] = VideoInfo::CS_BGR32;
	enumMap["YUY2"] = VideoInfo::CS_YUY2;
	enumMap["RAW32"] = VideoInfo::CS_RAW32;
	enumMap["YV24"] = VideoInfo::CS_YV24;
	enumMap["YV16"] = VideoInfo::CS_YV16;
	enumMap["YV12"] = VideoInfo::CS_YV12;
	enumMap["I420"] = VideoInfo::CS_I420;
	enumMap["IYUV"] = VideoInfo::CS_IYUV;
	enumMap["YUV9"] = VideoInfo::CS_YUV9;
	enumMap["YV411"] = VideoInfo::CS_YV411;
	enumMap["Y8"] = VideoInfo::CS_Y8;
	enumMap["YUV444P8"] = VideoInfo::CS_YV24;
	enumMap["YUV422P8"] = VideoInfo::CS_YV16;
	enumMap["YUV420P8"] = VideoInfo::CS_YV12;
	enumMap["YUV444P10"] = VideoInfo::CS_YUV444P10;
	enumMap["YUV422P10"] = VideoInfo::CS_YUV422P10;
	enumMap["YUV420P10"] = VideoInfo::CS_YUV420P10;
	enumMap["Y10"] = VideoInfo::CS_Y10;
	enumMap["YUV444P12"] = VideoInfo::CS_YUV444P12;
	enumMap["YUV422P12"] = VideoInfo::CS_YUV422P12;
	enumMap["YUV420P12"] = VideoInfo::CS_YUV420P12;
	enumMap["Y12"] = VideoInfo::CS_Y12;
	enumMap["YUV444P14"] = VideoInfo::CS_YUV444P14;
	enumMap["YUV422P14"] = VideoInfo::CS_YUV422P14;
	enumMap["YUV420P14"] = VideoInfo::CS_YUV420P14;
	enumMap["Y14"] = VideoInfo::CS_Y14;
	enumMap["YUV444P16"] = VideoInfo::CS_YUV444P16;
	enumMap["YUV422P16"] = VideoInfo::CS_YUV422P16;
	enumMap["YUV420P16"] = VideoInfo::CS_YUV420P16;
	enumMap["Y16"] = VideoInfo::CS_Y16;
	enumMap["YUV444PS"] = VideoInfo::CS_YUV444PS;
	enumMap["YUV422PS"] = VideoInfo::CS_YUV422PS;
	enumMap["YUV420PS"] = VideoInfo::CS_YUV420PS;
	enumMap["Y32"] = VideoInfo::CS_Y32;
	enumMap["RGB48"] = VideoInfo::CS_BGR48;
	enumMap["RGB64"] = VideoInfo::CS_BGR64;
	enumMap["RGBP"] = VideoInfo::CS_RGBP;
	enumMap["RGBP8"] = VideoInfo::CS_RGBP;
	enumMap["RGBP10"] = VideoInfo::CS_RGBP10;
	enumMap["RGBP12"] = VideoInfo::CS_RGBP12;
	enumMap["RGBP14"] = VideoInfo::CS_RGBP14;
	enumMap["RGBP16"] = VideoInfo::CS_RGBP16;
	enumMap["RGBPS"] = VideoInfo::CS_RGBPS;
	enumMap["RGBAP"] = VideoInfo::CS_RGBAP;
	enumMap["RGBAP8"] = VideoInfo::CS_RGBAP;
	enumMap["RGBAP10"] = VideoInfo::CS_RGBAP10;
	enumMap["RGBAP12"] = VideoInfo::CS_RGBAP12;
	enumMap["RGBAP14"] = VideoInfo::CS_RGBAP14;
	enumMap["RGBAP16"] = VideoInfo::CS_RGBAP16;
	enumMap["RGBAPS"] = VideoInfo::CS_RGBAPS;
	enumMap["YUVA444"] = VideoInfo::CS_YUVA444;
	enumMap["YUVA422"] = VideoInfo::CS_YUVA422;
	enumMap["YUVA420"] = VideoInfo::CS_YUVA420;
	enumMap["YUVA444P8"] = VideoInfo::CS_YUVA444;
	enumMap["YUVA422P8"] = VideoInfo::CS_YUVA422;
	enumMap["YUVA420P8"] = VideoInfo::CS_YUVA420;
	enumMap["YUVA444P10"] = VideoInfo::CS_YUVA444P10;
	enumMap["YUVA422P10"] = VideoInfo::CS_YUVA422P10;
	enumMap["YUVA420P10"] = VideoInfo::CS_YUVA420P10;
	enumMap["YUVA444P12"] = VideoInfo::CS_YUVA444P12;
	enumMap["YUVA422P12"] = VideoInfo::CS_YUVA422P12;
	enumMap["YUVA420P12"] = VideoInfo::CS_YUVA420P12;
	enumMap["YUVA444P14"] = VideoInfo::CS_YUVA444P14;
	enumMap["YUVA422P14"] = VideoInfo::CS_YUVA422P14;
	enumMap["YUVA420P14"] = VideoInfo::CS_YUVA420P14;
	enumMap["YUVA444P16"] = VideoInfo::CS_YUVA444P16;
	enumMap["YUVA422P16"] = VideoInfo::CS_YUVA422P16;
	enumMap["YUVA420P16"] = VideoInfo::CS_YUVA420P16;
	enumMap["YUVA444PS"] = VideoInfo::CS_YUVA444PS;
	enumMap["YUVA422PS"] = VideoInfo::CS_YUVA422PS;
	enumMap["YUVA420PS"] = VideoInfo::CS_YUVA420PS;
}
Then I could write a GetFormat function like this.

Code:
AVSValue __cdecl Create_GetFormat(AVSValue args, void* user_data, IScriptEnvironment* env) {
	VideoInfo vi = args[0].AsClip()->GetVideoInfo();
	static PixelFormatParser pfp;
	std::string Result = pfp.GetPixelFormatAsString(vi.pixel_type);
	return AVSValue(env->SaveString(Result.c_str(), Result.length() + 1));
}

Last edited by MysteryX; 10th February 2017 at 22:03.
MysteryX is offline  
Old 10th February 2017, 20:54   #3000  |  Link
JoeyMonco
Registered User
 
Join Date: Jan 2017
Posts: 24
Why do you need a whole class simply to write a utility function? Just write a simple function that just uses a switch statement to return the value based on the integer.
JoeyMonco is offline  
Closed Thread

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 21:29.


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