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 > VapourSynth

Reply
 
Thread Tools Search this Thread Display Modes
Old 25th April 2024, 04:58   #1  |  Link
Adub
Fighting spam with a fish
 
Adub's Avatar
 
Join Date: Sep 2005
Posts: 2,709
Zsmooth - cross-platform smoothing functions written in Zig! (CURRENTLY IN ALPHA)

Hello Doom9!

After being part of this community for many years, I finally got the time to start writing my own plugins, and so today I present something I've been working on for the past few months.

Zsmooth - Cross-platform smoothing functions written in Zig

Current Version: 0.5

Currently implemented functions
  • TemporalMedian
  • TemporalSoften
  • RemoveGrain
  • FluxSmooth

All functions take 8-16bit integer, and 16-32 bit float clips, in RGB, YUV, and GRAY formats. Parameter scaling is optional, based on a 'scalep' parameter, so you can choose to pass 0-255 values or get more specific.

Every function has SIMD support on x86_64 and ARM processors, thanks to the power of Zig's Vectors. This means that every function should be as fast, if not faster than existing plugins, and it should be fast everywhere.

Note: 16bit float support is a work in progress. All functions take it, but some are very slow due to some compilation bugs. I'll be working on ironing these out over time.

Please feel free to test these functions out and report back! I've been testing these myself over the past few months, and I *think* I've ironed out the bugs, but please report back any issues that you find, or major drops in performance compared to existing plugins. Also, I've only been testing on Linux, so I'm honestly curious to hear how things are on Windows and Mac.

Benchmarks
Some initial benchmarks taken from my laptop, but I plan on running a full suite once I get some time. It just takes a while since there's so many bit depth + parameter combinations.

TemporalMedian (8 bit, Radius 10)
  • Zsmooth - 112.88 fps
  • Dubhater - 6.91 fps
  • Neo_Tmedian - 4.29 fps

TemporalSoften (8 bit, Radius 1)
  • Zsmooth - 506 fps
  • Dubhater (TemporalSoften2) - 413 fps

RemoveGrain (8 bit and 32 bit float, Mode 1)
  • Zsmooth (8 bit) - 757 fps
  • Zsmooth (32 bit) - 145 fps
  • RGVS - 433 fps
  • RGSF - 81 fps

FluxSmoothT (8 bit)
  • Zsmooth - 448 fps
  • Dubhater - 414 fps

FluxSmoothST (8 bit)
  • Zsmooth - 321 fps
  • Dubhater - 145 fps


Bugs / Feature Requests
Feel free to either open an issue on Github or post in this thread.

https://github.com/adworacz/zsmooth/issues

Downloads
All releases are on Github. I've provided pre-compiled Windows DLLs for now,
but Mac libraries *might* be possible as well (I need testers to volunteer).

The *best* approach is to simply compile things yourself. Zig makes this *really* easy, and I have compilation instructions in my projects README.

https://github.com/adworacz/zsmooth/releases

Last edited by Adub; 3rd May 2024 at 16:38.
Adub is offline   Reply With Quote
Old 25th April 2024, 05:39   #2  |  Link
Julek
Registered User
 
Julek's Avatar
 
Join Date: Dec 2020
Posts: 94
wow, incredible work!
Your code will help me a lot, since i'm still a beginner in the dev world,
I was working with RemoveGrain too, only @Vectors code, but i was stuck at mode 20 hahaha

If you happen to use Discord, we have a vapoursynth devs server:
https://discord.gg/XTpc6Fa9eB
it would be great to have you there
__________________
CPU: AMD 3700X | GPU: RTX 3070Ti | RAM: 32GB 3200MHz
GitHub
Julek is offline   Reply With Quote
Old 25th April 2024, 07:53   #3  |  Link
Myrsloik
Professional Code Monkey
 
Myrsloik's Avatar
 
Join Date: Jun 2003
Location: Kinnarps Chair
Posts: 2,572
Interesting. I would however request that you don't spread TemporalSoften(2) around. That function was only ever used with the maximum thresholds and was simply a cargoculted discount AverageFrames. Promotes bad scripts.

But very interesting to see zig used for things.
__________________
VapourSynth - proving that scripting languages and video processing isn't dead yet
Myrsloik is offline   Reply With Quote
Old 25th April 2024, 17:55   #4  |  Link
Julek
Registered User
 
Julek's Avatar
 
Join Date: Dec 2020
Posts: 94
About printf memory leak, you can avoid this by using bufPrintZ instead of allocPrintZ.
I've added a function to the zig module and updated the example, so you can import from vsh now.
__________________
CPU: AMD 3700X | GPU: RTX 3070Ti | RAM: 32GB 3200MHz
GitHub
Julek is offline   Reply With Quote
Old 25th April 2024, 18:51   #5  |  Link
Adub
Fighting spam with a fish
 
Adub's Avatar
 
Join Date: Sep 2005
Posts: 2,709
@Julek - Thank you for your comments, and help in creating the vapoursynth-zig project. It definitely made my work a lot easier, and I'm happy to contribute as well. I just opened a few issues that I noticed while looking at the code, and I can submit a PR with fixes once I get a spare moment.

Also, good call on the memory leak thing. I'll look at updating.

@Myrsloik - Good to know on TemporalSoften / AverageFrames. I have seen some uses of TemporalSoften with the threshold, but I'll keep in mind that AverageFrames exists as well.

And yeah, Zig is a surprisingly excellent language for video processing filters, in my opinion. The C-interop, compile-time language execution, native SIMD vector support, comptime type passing, f16 support, etc etc etc make for a really nice development environment.
Adub is offline   Reply With Quote
Old 25th April 2024, 21:32   #6  |  Link
Adub
Fighting spam with a fish
 
Adub's Avatar
 
Join Date: Sep 2005
Posts: 2,709
FYI - Selur has already found a bug (thank you!) in TemporalMedian:

https://github.com/adworacz/zsmooth/issues/1

I suspect I know the issue, and will be testing/fixing over the next day or so.
Adub is offline   Reply With Quote
Old 25th April 2024, 22:19   #7  |  Link
Julek
Registered User
 
Julek's Avatar
 
Join Date: Dec 2020
Posts: 94
Quote:
Originally Posted by Adub View Post
It definitely made my work a lot easier, and I'm happy to contribute as well. I just opened a few issues that I noticed while looking at the code, and I can submit a PR with fixes once I get a spare moment.
I'm glad my code was useful for something, I was making a zig module for AVS too, but this one is much more complicated because AVS include is a mess, I'll have to turn the enums into variables because they have repeated values inside the same enum and Zig doesn't allow this.
I'll wait for your PRs

A question about the benchmark, how was your RGVS compiled? Is the SSE code active? Because in my tests the zig version has pretty much the same speed.
My RGVS code in zig was also getting the same performance as the c++ plugin with SSE.
__________________
CPU: AMD 3700X | GPU: RTX 3070Ti | RAM: 32GB 3200MHz
GitHub
Julek is offline   Reply With Quote
Old 27th April 2024, 20:11   #8  |  Link
Adub
Fighting spam with a fish
 
Adub's Avatar
 
Join Date: Sep 2005
Posts: 2,709
Version 0.3 is up: https://github.com/adworacz/zsmooth/releases/tag/0.3

This should fix all stride + vector related handling (turns out I had a few bugs wrt non-mod 32 handling).
Adub is offline   Reply With Quote
Old 27th April 2024, 20:15   #9  |  Link
Adub
Fighting spam with a fish
 
Adub's Avatar
 
Join Date: Sep 2005
Posts: 2,709
Quote:
Originally Posted by Julek View Post
I'm glad my code was useful for something, I was making a zig module for AVS too, but this one is much more complicated because AVS include is a mess, I'll have to turn the enums into variables because they have repeated values inside the same enum and Zig doesn't allow this.
I'll wait for your PRs

A question about the benchmark, how was your RGVS compiled? Is the SSE code active? Because in my tests the zig version has pretty much the same speed.
My RGVS code in zig was also getting the same performance as the c++ plugin with SSE.
Good to know that you're working on an Avisynth version! I really appreciate your efforts here, it will make writing "dualsynth" filters that much easier.

I'll work in a PR with fixes to vapoursynth-zig in the next day or so.

As for my RG benchmarks - I simply compiled my version locally using "zig build -Doptimize=ReleaseFast". I've noticed that the performance difference can really depend on the CPU in use. On my laptop I see a massive speedup, but on my desktop the performance difference between Zsmooth's version of RG and RGVS seems negligible. Floating point is still generally faster with Zsmooth due to using single precision vs RGSF's double precision.
Adub is offline   Reply With Quote
Old 27th April 2024, 20:39   #10  |  Link
Selur
Registered User
 
Selur's Avatar
 
Join Date: Oct 2001
Location: Germany
Posts: 7,335
Quote:
This should fix all stride + vector related handling (turns out I had a few bugs wrt non-mod 32 handling).
still broken, just in another way now (see details on github)
__________________
Hybrid here in the forum, homepage

Last edited by Selur; 27th April 2024 at 20:53.
Selur is offline   Reply With Quote
Old 27th April 2024, 23:31   #11  |  Link
Adub
Fighting spam with a fish
 
Adub's Avatar
 
Join Date: Sep 2005
Posts: 2,709
Version 0.4 is up: https://github.com/adworacz/zsmooth/releases/tag/0.4

Should have fixes for all bit depths, and now uses Zig slices for array bounds checking in debug mode. Also added unit tests to assert the stride handling behavior as a double check.

I've tested with RGB, YUV420, YUV422, and YUV444, and I can't replicate any more artifacts (green pixels or black bars).

Hopefully everything is fixed this time. Thank you for bearing with me as I iron out these kinks.
Adub is offline   Reply With Quote
Old 28th April 2024, 08:04   #12  |  Link
Selur
Registered User
 
Selur's Avatar
 
Join Date: Oct 2001
Location: Germany
Posts: 7,335
Sadly it's still broken. (more details over at github)
__________________
Hybrid here in the forum, homepage
Selur is offline   Reply With Quote
Old 3rd May 2024, 16:40   #13  |  Link
Adub
Fighting spam with a fish
 
Adub's Avatar
 
Join Date: Sep 2005
Posts: 2,709
Version 0.5 is out with the last of the stride fixes - https://github.com/adworacz/zsmooth/releases/tag/0.5

Big thank you to NSQY, Selur, and Julek for testing and helping to diagnose the issue.
Adub is offline   Reply With Quote
Reply

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 12:51.


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