tomisacat / videoprocesswithmetal Goto Github PK
View Code? Open in Web Editor NEWProcess video image data with Metal shading language
License: MIT License
Process video image data with Metal shading language
License: MIT License
I am using your code for motion blur effect via Metalkit, which works well, but now I want to create a filter as shown in the below video and I have modified a code also but it doesn't work as expected, so can you pls help?
How Filter I want?
https://drive.google.com/file/d/1oEcC0DMOfvuW9pkLBPZhJmgMrhaK_Jcp/view?usp=sharing
Code:
kernel void blurredMotion(texture2d<float, access::read> inTexture [[ texture(0) ]],
texture2d<float, access::write> outTexture [[ texture(1) ]],
texture2d<float, access::read> lastTexture [[ texture(2) ]],
device const float *time [[ buffer(0) ]],
uint2 gid [[ thread_position_in_grid ]])
{
float width = inTexture.get_width();
float height = inTexture.get_height();
float2 uv = float2(gid) / float2(width, height);
float4 buf = lastTexture.read(gid);
float4 bri = inTexture.read(gid);
float3 grayScaleColor = float3(1.0, 0.0, 0.0);
float myGrayScale = dot(bri.rgb, grayScaleColor);
float diff = ((bri.r - buf.r) + (bri.g - buf.g) + (bri.b - buf.b)) / 3;
float colR = inTexture.read(uint2(uv.x + diff, uv.y)).r * (1.0 - diff);
float colG = inTexture.read(uint2(uv.x - diff, uv.y)).r * (1.0 - diff);
float colB = inTexture.read(uint2(uv.x - diff, uv.y)).r * (1.0 - diff);
float scanline = abs(cos(uv.y * 500.));
scanline = smoothstep(0.0, 2.0, scanline);
float3 col = float3(1.0,0.0,0.0);
col -= (0.1 * scanline);
float3 blendColor = float3(colR, colG, colB) - (0.1 * scanline);
outTexture.write(float4(blendColor, 1.0), gid);
}
Can you pls help what I am missing here to achieve that?
in this declaration
when I make this code as it is
lazy var playerItemVideoOutput: AVPlayerItemVideoOutput = {
let attributes = [kCVPixelBufferPixelFormatTypeKey as String: Int(kCVPixelFormatType_32BGRA)]
return AVPlayerItemVideoOutput(pixelBufferAttributes: attributes)
}()
nothing is showin on the screen
I think It doesn't know how to make a texture from the CVPixelbuffer
but when I pass nil to the constructor
lazy var playerItemVideoOutput: AVPlayerItemVideoOutput = {
let attributes = [kCVPixelBufferPixelFormatTypeKey as String: Int(kCVPixelFormatType_32BGRA)]
return AVPlayerItemVideoOutput(pixelBufferAttributes: nil)
}()
it show like this
https://i.imgur.com/iWqu592.png
any help
@tomisacat
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.