| Version 33 (modified by , 2 years ago) ( diff ) |
|---|
Wouldn't it make sense to combine this page with https://trac.ffmpeg.org/wiki/denoise ?
[ MasterQuestionable:
͏ Perhaps.
͏ While that one is more academic focused.
͏ And has more rigorous standard on content quality. ]
Denoise Examples
A denoise process will destructively and irreversibly modify a source. Common use-cases for denoise processing are:
- make the content more subjectively pleasing to the ear or eye
- remove digital noise
- remove noise inherited from an analog digitization
- remove hard-to-compress data to improve compression efficiency, at the cost of video fidelity.
Contents
Video Denoise Filters
FFmpeg has multiple possible filters for video denoise:
- atadenoise, Adaptive Temporal-Averaging denoiser
- bm3d, Block-Matching 3D denoiser
- chromanr, Reduces chrominance noise
- dctdnoiz, Discrete Cosine Transform 2D denoiser
- fftdnoiz, Fast Fourier Transform 3D denoiser
- hqdn3d, High-quality 3D denoiser
- nlmeans, Non-Local Means denoiser
- owdenoise, Overcomplete-wavelet denoiser
- removegrain, Spatial denoiser for progressive video
- tmedian, Reduces noise by picking median pixels from several successive input video frames
- tmix, Reduces noise by mixing successive video frames
- vaguedenoiser, Wavelet-based denoiser
(sorted alphabetically)
This document does not offer direct recommendations for denoise video algorithm selection, since the expected quality and performance is entirely subjective and all sources differ.
- Users are encouraged to start with default values selected by the developer.
- Users are encouraged to preview and compare filters.
- Users are encouraged to preview on the type of device, resolution and environment where the content will most likely be consumed. It is noted that many televisions include runtime-denoise functions. If a digital television is the primary target device, users are encouraged to preview with and without television runtime-denoise processing enabled.
[ Such TV tend to screw up, regardless. ]
The quality of runtime-denoise algorithms in consumer electronics vary significantly in quality of implementation, and may interfere with comparative testing.
Testing and Comparing Denoise filters
Identifying planes containing noise
Prior to applying a denoise filter, a user is encouraged to separate and preview the individual planes and identify whether the source of the noise is in any particular plane.
For example, when an analog source is digitized, there may be a disproportionate amount of noise in the chroma plane.
The following command will produce a 4x4 mosaic containing
{original, luma, Cb, Cr}planes, similar to plane preview-scopes in tools such as Neat Video noise-preview. Frames are converted to yuv444p (or yuv444p10le for 10-bit) in order to remove chroma-subsampling of a yuv422p or yuv420p source, where chroma-planes are encoded at a lower resolution.
$ ffplay -f 'lavfi' "movie='${In}', \ format=pix_fmts='yuv444p',split=2[split1][split2]; \ [split2]extractplanes='y+u+v'[y][u][v]; \ [split1][y][u][v]xstack=inputs=4:grid='2x2'[out]"
Some denoise filters allow the user to select which planes are processed. Planes are typically decimal notation, which may be confusing to a new user. This notation is not unique to avuy formats, it is also used for abgr formats.
Decimal avuy Plane ------------------------------------------------- 15 1111 all planes, including alpha 7 0111 all planes, excluding alpha 6 0110 chroma planes 1 0001 luma plane only
Visualizing and comparing filters
The visual effect of a denoise filter is subjective. A user is encouraged to compare the visual effects of denoise filters.
The following command will provide a split-screen comparison between
null(no-operation) filter on the left of the player window with thehqdn3dfilter (with default options) on the right of the vertical center-line.
The same methodology can be used to compare the visual effects of two different denoise filters, or two different options of the same filter.
$ ffplay -f 'lavfi' "movie='${In}', \ split=2[split1][split2]; \ [split1]null[split1]; \ [split2]hqdn3d[split2]; \ [split1]crop=out_w='(iw/2)':x=0[split1]; \ [split2]crop=out_w='(iw/2)':x='(iw/2)'[split2]; \ [split1][split2]xstack=inputs=2:grid='2x1'[out]"
It is possible to extend the above command to cycle through the
{ combined, luma, Cb, Cr }planes using FFplay's "cycle video filters or show modes" using thewkey.
$ ffplay -f 'lavfi' "movie='${In}', \ split=2[split1][split2]; \ [split1]null[split1]; \ [split2]hqdn3d[split2]; \ [split1]crop=out_w='(iw/2)':x=0[split1]; \ [split2]crop=out_w='(iw/2)':x='(iw/2)'[split2]; \ [split1][split2]xstack=inputs=2:grid='2x1',format=pix_fmts='yuv444p'[out]" \ -vf 'null' \ -vf extractplanes=planes='y' \ -vf extractplanes=planes='u' \ -vf extractplanes=planes='v'
Benchmarking the relative performance of denoise filters
The performance of denoise filters varies depending on a number of factors, including algorithm, patch size, number of planes being processed, hardware etc. A user can measure and compare the relative performance of a denoise filter and the selected options using the ͏"latency" benchmarking filter.
For example, here is a comparison of the relative performance of the
hqdn3dand thenlmeansfilters across 1000 video frames. These comparisons and values are not recommendations, but are to demonstrate how algorithm and options selection can have a major impact on performance.
$ ffmpeg -an -dn -sn -i "${In}" -filter:v hqdn3d,latency,trim=end_frame=1000 -f null - [Parsed_latency] Min latency: 156 bitrate=N/A speed=14.1x $ ffmpeg -an -dn -sn -i "${In}" -filter:v nlmeans,latency,trim=end_frame=1000 -f null - [Parsed_latency] Min latency: 136 bitrate=N/A speed=0.087x $ ffmpeg -an -dn -sn -i "${In}" -filter:v nlmeans=s=1.00:p=5:pc=5:r=7:rc=7,latency,trim=end_frame=1000 -f null - [Parsed_latency] Min latency: 136 bitrate=N/A speed=0.387x $ ffmpeg -an -dn -sn -i "${In}" -filter:v nlmeans=s=1.00:p=15:pc=15:r=31:rc=31,latency,trim=end_frame=1000 -f null - [Parsed_latency] Min latency: 133 bitrate=N/A speed=0.0179x
This relative performance gauge can be used to benchmark the impact of filter (and options) selection.
Example command lines for various denoise filters
atadenoise
Process video frames using the Adaptive Temporal Averaging (atadenoise) Denoise filter.
Simple usage with default options...
$ ffmpeg -i "${In}" -vf atadenoise "${Out}" $ ffplay "${In}" -vf "atadenoise" -vf "null" # Press 【W】 to cycle filters.
Advanced options usage...
$ ffmpeg -i "${In}" \ -filter:v "atadenoise=0a=0.02:0b=0.04:1a=0.02:1b=0.04:2a=0.02:2b=0.04:s=9:p=7:a='p':0s=32767:1s=32767:2s=32767" \ -codec:v 'libx264' -pix_fmt:v 'yuv420p' \ -codec:a 'copy' \ "${Out}"
Command-line help is available at the terminal prompt...
$ ffmpeg -hide_banner -h filter=atadenoise
Official FFmpeg online documentation is available at https://ffmpeg.org/ffmpeg-filters.html#atadenoise
bm3d
Process video frames using the Block-Matching 3D (bm3d) denoise filter.
Simple usage with default options...
$ ffmpeg -i "${In}" -vf bm3d "${Out}" $ ffplay "${In}" -vf "bm3d" -vf "null" # Press 【W】 to cycle filters.
Advanced options usage...
$ ffmpeg -i "${In}" \ -filter:v "bm3d=sigma=1.0:block=8:bstep=4:group=1:range=9:mstep=1:thmse=0:hdthr=2.70:estim='basic':ref='disabled':planes=7" \ -codec:v 'libx264' -pix_fmt:v 'yuv420p' \ -codec:a 'copy' \ "${Out}"
Command-line help is available at the terminal prompt...
$ ffmpeg -hide_banner -h filter=bm3d
Official FFmpeg online documentation is available at https://ffmpeg.org/ffmpeg-filters.html#bm3d
dctdnoiz
͏ Process video frames using the Discrete Cosine Transform (DCT) 2D denoise filter.
͏ Note it's noted in the documentation that "is not designed for real time" use: mostly due to performance cause.
͏ [ ^ Likely implementation issue: this should be similar (or simpler) [1] comparing to "fftdnoiz". ]
͏ Might worth notice to who considering performance in selection of denoise algorithms.
[ [1]
͏ Unsure if "fftdnoiz" uses DCT or DFT:
͏ FFT may compute both. ]
Simple usage with default options...
$ ffmpeg -i "${In}" -vf dctdnoiz "${Out}" $ ffplay "${In}" -vf "dctdnoiz" -vf "null" # Press 【W】 to cycle filters.
Advanced options usage...
$ ffmpeg -i "${In}" \ -filter:v "dctdnoiz=sigma=0:overlap=-1:n=3" \ -codec:v 'libx264' -pix_fmt:v 'yuv420p' \ -codec:a 'copy' \ "${Out}"
Command-line help is available at the terminal prompt...
$ ffmpeg -hide_banner -h filter=dctdnoiz
Official FFmpeg online documentation is available at https://ffmpeg.org/ffmpeg-filters.html#dctdnoiz
fftdnoiz
͏ Process video frames using the 3D Fast Fourier Transform (FFT) denoise filter.
͏ "3D" here just means it additionally considers the time domain: i.e. use of temporal frames. (in addition to "2D")
Simple usage with default options...
$ ffmpeg -i "${In}" -vf fftdnoiz "${Out}" $ ffplay "${In}" -vf "fftdnoiz" -vf "null" # Press 【W】 to cycle filters.
Advanced options usage...
$ ffmpeg -i "${In}" \ -filter:v "fftdnoiz=sigma=1:amount=1:block=32:overlap=0.5:method='wiener':prev=0:next=0:planes=7:window='hann'" \ -codec:v 'libx264' -pix_fmt:v 'yuv420p' \ -codec:a 'copy' \ "${Out}"
Command-line help is available at the terminal prompt...
$ ffmpeg -hide_banner -h filter=fftdnoiz
Official FFmpeg online documentation is available at https://ffmpeg.org/ffmpeg-filters.html#fftdnoiz
hqdn3d
Process video frames using the High-quality 3D denoise filter.
The hqdn3d filter is useful for removing shimmer by applying temporal denoise, especially on sources with excessive temporal noise in the chroma plane.
Simple usage with default options...
$ ffmpeg -i "${In}" -vf hqdn3d "${Out}" $ ffplay "${In}" -vf "hqdn3d" -vf "null" # Press 【W】 to cycle filters.
Advanced options...
$ ffmpeg -i "${In}" \ -filter:v "hqdn3d=hqdn3d=luma_spatial=4.00:chroma_spatial=3.00:luma_tmp=6.00:chroma_tmp=4.5" \ -codec:v 'libx264' -pix_fmt:v 'yuv420p' \ -codec:a 'copy' \ "${Out}"
Command-line help is available at the terminal prompt...
$ ffmpeg -hide_banner -h filter=hqdn3d
Note:
͏ At the time of writing (FFmpeg 7.0.1), the command-line interface help suggests that all options default to 0. The Official FFmpeg online documentation suggests that the default value of luma_spacial is 4.0 and all other default values are solved-for. The contradiction in documentation is noted.
Official FFmpeg online documentation is available at https://ffmpeg.org/ffmpeg-filters.html#hqdn3d
nlmeans
Process video frames using the Non-local means denoise filter.
nlmeans is also available as a hardware-accelerated filter through nlmeans_opencl and nlmeans_vulcan
͏ Dirk Farin writes of the nlmeans filter... "It is also interesting to note that one can simply apply the filter on interlaced material. The algorithm itself is robust enough to handle this nicely without artifacts." [Ref]
͏ It's suggesting that in Farin's opinion nlmeans can successfully denoise interlaced material without significantly affecting the interlaced structure of which.
͏ .
͏ For theoretical best quality, don't use such general purpose denoiser for deinterlacing.
͏ Use dedicated deinterlacer first then apply denoise.
͏ Farin is not suggesting that nlmeans be used as deinterlacer, rather that nlmeans is robust enough to be applied in fully-interlaced end-to-end workflow.
͏ .
͏ For this purpose, and best quality:
͏ First deinterlace after processing then reinterlace: must it be interlaced. (doesn't make much sense though)
Simple usage with default options...
$ ffmpeg -i "${In}" -vf nlmeans "${Out}" $ ffplay "${In}" -vf "nlmeans" -vf "null" # Press 【W】 to cycle filters.
Advanced options usage...
$ ffmpeg -i "${In}" \ -filter:v "nlmeans=s=1.00:p=7:pc=0:r=15:rc=0" \ -codec:v 'libx264' -pix_fmt:v 'yuv420p' \ -codec:a 'copy' \ "${Out}"
Command-line help is available at the terminal prompt...
$ ffmpeg -hide_banner -h filter=nlmeans $ ffmpeg -hide_banner -h filter=nlmeans_opencl $ ffmpeg -hide_banner -h filter=nlmeans_vulkan
Official FFmpeg online documentation is available at:
- https://ffmpeg.org/ffmpeg-filters.html#nlmeans
- https://ffmpeg.org/ffmpeg-filters.html#nlmeans_005fopencl
- https://ffmpeg.org/ffmpeg-filters.html#nlmeans_005fvulkan
See also:
- https://www.dirk-farin.net/projects/nlmeans/
Dirk Farin claims the authors (A. Buades, B. Coll, J.M. Morel) of "Image data processing method by reducing image noise, and camera integrating means for implementing said method", EP Patent 1,749,278 (Feb. 7), 2007 granted permission to release the filter under GPL. - https://git.videolan.org/?p=ffmpeg.git;a=blob;f=libavfilter/vf_nlmeans.c
owdenoise
Process video frames using the Overcomplete Wavelet denoiser.
Simple usage with default options...
$ ffmpeg -i "${In}" -vf owdenoise "${Out}" $ ffplay "${In}" -vf "owdenoise" -vf "null" # Press 【W】 to cycle filters.
Advanced options usage...
$ ffmpeg -i "${In}" \ -filter:v "fftdnoiz=owdenoise=depth=8:luma_strength=1:chroma_strength=1 " \ -codec:v 'libx264' -pix_fmt:v 'yuv420p' \ -codec:a 'copy' \ "${Out}"
Command-line help is available at the terminal prompt...
$ ffmpeg -hide_banner -h filter=owdenoise
Official FFmpeg online documentation is available at https://ffmpeg.org/ffmpeg-filters.html#owdenoise
vaguedenoiser
Process video frames using the wavelet-based vaguedenoise denoise filter.
Simple usage with default options...
$ ffmpeg -i "${In}" -vf vaguedenoiser "${Out}" $ ffplay "${In}" -vf "vaguedenoiser" -vf "null" # Press 【W】 to cycle filters.
Advanced options usage...
$ ffmpeg -i "${In}" \ -filter:v "vaguedenoiser=threshold=2:method='garrote':nsteps=6:percent=85:planes=7:type='universal'" \ -codec:v 'libx264' -pix_fmt:v 'yuv420p' \ -codec:a 'copy' \ "${Out}"
Command-line help is available at the terminal prompt...
$ ffmpeg -hide_banner -h filter=vaguedenoiser
Official FFmpeg online documentation is available at https://ffmpeg.org/ffmpeg-filters.html#vaguedenoiser
Codec-specific denoisers
͏ It is noted that some encoders include denoise functions as private codec options.
͏ Such denoisers tend to be typical ones simulatable with FFmpeg's.
For example, the external x264 encoder supports the
--nroption, where a user may specify a value in the range of {0...65536}, with the default being 0 (disabled).
$ x264 --nr 200 -o "${Out}" "${In}" $ ffmpeg -i "${In}" -codec:v 'libx264' -x264opts 'nr=200' "${Out}"
FFmpeg's range of denoise filters have the advantage of being codec-independent: can be evaluated independent of a transcode and offer a wider selection of algorithms.


