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 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,753
Zsmooth - cross-platform smoothing functions written in Zig!

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.14

Currently implemented functions
  • CCD
  • Clense
  • DegrainMedian
  • FluxSmooth
  • InterQuartileMean
  • Median
  • RemoveGrain
  • Repair
  • SmartMedian
  • TemporalMedian
  • TemporalRepair
  • TemporalSoften
  • TTempSmooth
  • VerticalCleaner

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
https://github.com/adworacz/zsmooth/.../BENCHMARKS.md


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 binaries for Windows, Mac and Linux, with the latter offering x86_64 and aarch64 (ARM) binaries.

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

Last edited by Adub; 16th November 2025 at 20:36. Reason: Version 0.14
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: 100
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,647
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: 100
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,753
@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,753
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: 100
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,753
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,753
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,843
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, its own forum

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,753
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,843
Sadly it's still broken. (more details over at github)
__________________
Hybrid here in the forum, homepage, its own forum
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,753
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
Old 5th July 2024, 18:50   #14  |  Link
Adub
Fighting spam with a fish
 
Adub's Avatar
 
Join Date: Sep 2005
Posts: 2,753
Minor update: I'm working on a few updates for 0.6, mainly adding DegrainMedian support (mode 0 is *much* faster than the existing plugin), along with some minor dependency updates and Zig version bump.

After that I'll work on adding Dogway's IQMV (Inter Quartile Median) filters, and then maybe CCD after. I still need to finish the RemoveGrain functions (Repair and Cleanse) as well.
Adub is offline   Reply With Quote
Old 20th January 2025, 20:55   #15  |  Link
Adub
Fighting spam with a fish
 
Adub's Avatar
 
Join Date: Sep 2005
Posts: 2,753
Version 0.6 is now available, including prebuilt binaries for x86_64 and aarch64 Mac - https://github.com/adworacz/zsmooth/releases/tag/0.6

Quote:
* Add DegrainMedian implementation.
* Optimize TemporalMedian even more. Latest tests show a bump from 340fps to 413fps in
single core tests on my laptop. Essentially I heavily reduced branching calculations by
moving diameter calculations to comptime. This does blow up the size of the binary by about double,
from about 850kB to 1.6MB, but oh well.
* Refactored internal common code significantly, and introduced a helper type called Grid for operating on a 3x3
grid of pixels as either scalars or vectors.
* Added more testing to many of the common functions.
* Add generic builds for Mac OS, on x86_64 and aarch64 architectures.
Adub is offline   Reply With Quote
Old 21st January 2025, 04:08   #16  |  Link
Selur
Registered User
 
Selur's Avatar
 
Join Date: Oct 2001
Location: Germany
Posts: 7,843
Nice! Thanks for the update!
__________________
Hybrid here in the forum, homepage, its own forum
Selur is offline   Reply With Quote
Old 10th April 2025, 18:09   #17  |  Link
Adub
Fighting spam with a fish
 
Adub's Avatar
 
Join Date: Sep 2005
Posts: 2,753
Just so I don't pollute https://forum.doom9.org/showthread.php?t=186119, bit of a status update:

1. I've started my work on implementing Repair. It's going extremely well, with some pretty insane speedups over the older plugins, especially RGSF. We're talking a frequent 10-20x improvement. Again, not a typo.
2. Community members have requested that I change how Repair (and potentially RemoveGrain...) is implemented. Prior implementations of RG/Repair simply copy the edge pixels (so first/last row/column) to make the underlying algorithms easier to write. Since those plugins were written an alternative technique has arisen for filling in the requisite information for edges, which is "mirroring". I'll be experimenting with this approach as it makes sense and I should be able to implement it in the next version or two. More details can be found on the Github issue: https://github.com/adworacz/zsmooth/issues/6
3. As part of investigation into #2, I've uncovered some more speedups in RemoveGrain as part of a refactor I started. I'm seeing a good 10%+ improvement in RG speeds (and I think I'm bottlenecking on something else now so it could be even higher).
Adub is offline   Reply With Quote
Old 10th April 2025, 18:11   #18  |  Link
Selur
Registered User
 
Selur's Avatar
 
Join Date: Oct 2001
Location: Germany
Posts: 7,843
Looking forward to it, faster RemoveGrain and Repair would be nice.
__________________
Hybrid here in the forum, homepage, its own forum
Selur is offline   Reply With Quote
Old 12th April 2025, 08:11   #19  |  Link
Selur
Registered User
 
Selur's Avatar
 
Join Date: Oct 2001
Location: Germany
Posts: 7,843
btw. if possible would be nice if you could create Vapoursynth versions of TemporalRepair and AutoLevel which atm. lack any Vapoursynth port
__________________
Hybrid here in the forum, homepage, its own forum
Selur is offline   Reply With Quote
Old 12th April 2025, 17:30   #20  |  Link
Adub
Fighting spam with a fish
 
Adub's Avatar
 
Join Date: Sep 2005
Posts: 2,753
TemporalRepair seems reasonable. AutoLevel seems outside the scope of Zsmooth in particular, but I'll consider it for another plugin at some point.

I've added TemporalRepair to a pinned issue on Github, so feel free to up vote or add others there: https://github.com/adworacz/zsmooth/issues/7
Adub is offline   Reply With Quote
Reply

Thread Tools
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 23:22.


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