Log in

View Full Version : Can I Pass Clip Metadata Between Filters


MysteryX
10th October 2015, 01:44
Is it possible to pass metadata from one filter to the next?

Here's what I want to do. Instead of this... (which if you tried SuperRes/Shader, you'll see it is very expensive on memory)

input = input.Shader("YuvToRgb.cso")
diff1 = input.Shader("DiffA.cso")
diff2 = input.Shader("DiffB.cso")
diff3 = input.Shader("DiffC.cso")
input = diff1.Shader("Merge.cso", clip2=diff2, clip3=diff3)
input = input.Shader("RgbToYuv.cso")

I want to do this

input = input.Shader("YuvToRgb.cso")
diff1 = input.Shader("DiffA.cso", output=2)
diff2 = input.Shader("DiffB.cso", output=3)
diff3 = input.Shader("DiffC.cso", output=4)
input = input.Shader("Merge.cso", clip1=2, clip2=3, clip3=4)
input = input.Shader("RgbToYuv.cso")
input = input.ShaderExecute()

Basically, if the Shader commands could simply add metadata to the clip, then ShaderExecute could execute all the commands in the chain at once, saving tremendous memory and threads.

Is it possible?

Well... yes it is possible, worse case scenario I could store the metadata as a struct within the input video's memory but that would be VERY ugly programming. Is there a better way to pass metadata from one filter to the next?

feisty2
10th October 2015, 03:46
Check the source code of MSuper

MysteryX
10th October 2015, 05:26
OK. It wouldn't be doing the hack of storing in vi.num_audio_samples if it was possible to pass parameters. I'd need to pass more data than that, too.

So I guess the only way to do it would be to encode the structure as a byte array to replace the frame data.

In .NET, serializing data in such a way is easy. In C++, however, I'm not sure how I would do it. String data would be especially complicated to serialize. That's when I wish I was using C#...

Is there an easy way in C++ to convert an array of structures into binary, when it contains strings and each item in the list has a different length?

wonkey_monkey
10th October 2015, 11:07
Is there an easy way in C++ to convert an array of structures into binary, when it contains strings and each item in the list has a different length?

If you mean C++ structs, they are a fixed size. A string in a struct is either fixed length or a fixed length pointer to an externally stored string.

struct my_struct x[100];
memcpy(storage, x, 100*sizeof(my_object));

...

struct my_struct y[100];
memcpy(y, storage, 100*sizeof(my_object));

MysteryX
10th October 2015, 16:16
Yeah I know what a struct is and how to store it.

I just realized. I'm not serializing data to the hard drive or over the network or something like that. I'm only storing it in memory to read it afterwards. Truth is, by simply passing a pointer into any field of VideoInfo, we could pass unlimited data.

Since it's only storing it in memory to read it afterwards, simply passing pointers to the strings should be good enough. Simple regular structs then. Flushing the video data, and storing one struct per line. Each call to Shader would add one row to the clip.