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. |
|
![]() |
|
Thread Tools | Search this Thread | Display Modes |
![]() |
#1 | Link |
I might be autistic...
Join Date: Apr 2022
Location: 16-235
Posts: 34
|
Potentially stupid aomenc grain synthesis questions...
Is there any way to "trick" aomenc, or preferably aom-av1-psy, into utilizing grain synthesis by analyzing a grainy, untouched source but actually encoding video that was de-grained or de-noised externally?
I use --enable-dnl-denoising=0 with aom-av1-psy, per BlueSwordM and many others' suggestions, because the encoder's own denoising is a bit much, and having only 1 parameter to tune for it isn't enough. It leaves a lot to be desired. Something like SMDegrain with a KNLMeansCL pre-filter pass, and appropriate parameters for both, can output a de-grained/DNR video that is vastly superior to what sometimes seems like either completely automated or excessive "professionally done" smeary and waxy DNR present in finished Blu-Rays. Adding some dither noise back in after working in 16-bit color and optionally de-banding if needed can help prevent new banding, with any number of decent AVS/VapourSynth debanding filters. If I take video processed in this manner and pass it on through to aomenc with --enable-dnl-denoising=0, the grain synthesis function seems like it only acts on that dither noise, if it even acts at all. It doesn't know about the grain that I removed, because...well, how could it? It never saw the grain. If I try to crank --denoise-noise-level up, it starts to look like x265 does at slower presets with --psy-rdoq turned up too high: ugly artificial noise. Does the encoder make the grain synthesis "decisions" - or at least the pattern and strength, exclusively during the 1st pass? If so, would it be feasible to conduct the first pass pointed at an AVISynth/VapourSynth script that has all the de-band/de-grain processing commented out, and then pull the old switcheroo and actually encode the 2nd pass pointing at a fully pre-processed source? If that could work, would actually using --enable-dnl-denoising=1 during this jape of a first pass help it make better rate control decisions? Can --enable-dnl-denoising even be set differently on pass 1 and pass 2? I wouldn't want to actually encode the 2nd pass with it set to anything but =0, especially if I'm doing my own external filtering. If it can't be switched, forcing SMDegrain or KNLMeansCL to run with lower spatial filtering might leave a "static" grain "texture", albeit likely pretty blotchy, in the source that it could use? I hope that makes sense. I also thought of an alternative, ridiculous strategy, but it involves:
I tried searching for an answer, and all I could find was excitement about using photon grain synthesis. That doesn't seem to help with the idea of encoding externally filtered video but trying to use grain synthesis to mimic the original grain pattern and strength, unless I just can't make the connection there. |
![]() |
![]() |
![]() |
#2 | Link |
Registered User
Join Date: Feb 2003
Location: New York, NY (USA)
Posts: 111
|
Check examples/noise_model, it can create a grain table which represents the difference between a "noisy" and "denoised" source, and the resulting grain table can be input into aomenc using the --film-grain-table argument.
|
![]() |
![]() |
![]() |
#3 | Link | |
I might be autistic...
Join Date: Apr 2022
Location: 16-235
Posts: 34
|
Quote:
"/examples/noise_model.c"? Oh God, it's code! All joking aside, looking at the comments in the code (wow, this is really well documented...) this looks like exactly what I described! If I'm reading CMakeLists.txt correctly, I just need to make sure to add -DENABLE_EXAMPLES=1 to my cmake command. cmake .. -G "Visual Studio 16 2019" -DENABLE_EXAMPLES=1 and then cmake --build .. Easy enough, I'll have a noise_model.exe waiting for me in an "examples" subfolder in my build directory, right? Needing two .yuv inputs is definitely going to limit what I can do with this. Using ffmpeg itself to pipe .yuv is easy enough, but even then I'd still need to hog ~60 GB up (at least for what I want to test out) somewhere for keeping the degrained output around as raw .yuv. Normally if I needed to access filtered output twice I'd just use FFV1 or something, and it would save time to filter once and then re-use that same output for grain analysis and encoding, but that doesn't help me much. I'd still need a way to pipe FFV1 -> YUV to the grain analysis alongside source -> YUV. Now I can see why those x264/x265 mods that can read AviSynth input directly exist. |
|
![]() |
![]() |
![]() |
#5 | Link |
I might be autistic...
Join Date: Apr 2022
Location: 16-235
Posts: 34
|
Mods, if my choice of sample is problematic, please let me know. I deliberately chose a clip that Warner Bros has uploaded on one of their YouTube channels. https://youtu.be/bSDzrTgulms?t=6 It's a ~90 second excerpt of "Baseball Bugs" from 1946 - I might have included less than 1 second extra, as I cut the m2ts on a keyframe + scene-change before starting.
![]() Source Video Do note that there are several instances of what I thought was my DNR being too strong present in the source, like the screenshot above. I spent more time than I had to tweaking my script before I thought to check what it actually looked like, and I probably could've filtered more strongly as a result. It is very grainy on the Blu-Ray, and 20 Mbps seems like it wasn't enough, because at times it looks like grainy artifacts rather than grain. The YouTube clip is a good enough example for checking what a much higher level of compression does to video this grainy - the grain texture is gone entirely and it's just strobing artifacts. Perhaps they de-grained it before uploading it, but the few shorts I checked on Boomerang/Amazon Prime seemed to be from the same masters without any significant DNR, albeit at 25 fps. Probably an EU broadcast master. This is untouched from a Blu-Ray, other than AC3->AAC for the audio. Filtered + noise_model.exe generated table AV1 output It's not perfect, and I think noise_model might have latched onto some of the encoding artifacts instead of the grain itself at times, but it looks a lot better than I thought it would! If you pause, it falls apart rather quickly because you can easily see how/where the grain pattern repeats, whereas a still frame with the "actual" grain is far less offensive. 4 Mbps is a bit much though, q18 was probably too high. Seems like it would work better with a higher quality source. Debug output from noise_model is unfortunately only possible with 8pp. MEGA mirror. Filtered output (~1.5 GB FFV1) I am far from an expert with video filtering, and I'd rather not share my AVISynth script (because it's embarrassing, not because I think highly of it) but if you want to reproduce this, tweak SMDegrain, pre-filter with KNLMeansCL.your spatial smoother of choice, make use of "CClip" in SMDegrain, and maybe mfilter pointing at your prefiltered_clip.DFTTest/neo, with a very high sigma and a tbsize of 1. It ran like molasses, and feeding this script directly to AOMEnc would've actually had me waiting on the frame server rather than the encoder. noise_model.exe can't read from stdin, so no piping is possible at all. It ran at about 1.5-2 FPS (~20 minutes for 1m18sec, I didn't time it, stderr output showed time in seconds * 10000000) and is definitely single threaded. The noise table .tbl file looks like a bunch of arrays/matrices, you can open it just fine in a text editor. Command line plus the first two sets of sample output, and then the whole file: PHP Code:
aom-av1-psy command line: PHP Code:
It works! Last edited by BuccoBruce; 29th May 2022 at 05:03. Reason: MEGA can't hotlink AV1... |
![]() |
![]() |
![]() |
#6 | Link | |
Registered User
Join Date: Feb 2003
Location: New York, NY (USA)
Posts: 111
|
Quote:
[edit] But nice to hear you got it working! The output will indeed rely a lot on the quality of the filtering, so it'll never be quite perfect, but it has some significant advantages over R/D encoding of the grain. |
|
![]() |
![]() |
![]() |
#7 | Link | |
I might be autistic...
Join Date: Apr 2022
Location: 16-235
Posts: 34
|
Quote:
|
|
![]() |
![]() |
![]() |
Tags |
aomenc, av1, enable-dnl-denoising, grain, grain synthesis |
Thread Tools | Search this Thread |
Display Modes | |
|
|