diff options
author | 2013-12-03 22:28:36 +0100 | |
---|---|---|
committer | 2013-12-04 00:07:39 +0100 | |
commit | 6a2eeedc4c89511938dd2aa727bc3a1898673578 (patch) | |
tree | 61e4523bcca15bfd9e83579ca114a3bb87d36421 | |
parent | ad950be4150d212252ea72fab724fe3342652d62 (diff) |
vf_noise: reroute to vf_lavfi
Unfortunately, this forces filtering both luma and chroma, because
otherwise we'd have to deal with libavfilter's vf_noise weird handling
of YUV vs. RGB formats. Would we e.g. filter luma only, it would filter
red in RGB mode only, because it goes by component and there's no way to
distinguish YUV and RGB by just using the filter's options.
-rw-r--r-- | DOCS/man/en/vf.rst | 31 | ||||
-rw-r--r-- | video/filter/vf_noise.c | 68 |
2 files changed, 62 insertions, 37 deletions
diff --git a/DOCS/man/en/vf.rst b/DOCS/man/en/vf.rst index c45e25bbf5..9ad8dfa07f 100644 --- a/DOCS/man/en/vf.rst +++ b/DOCS/man/en/vf.rst @@ -426,21 +426,30 @@ Available filters are: ``'--vf=lavfi=yadif:o="threads=2,thread_type=slice"'`` forces a specific threading configuration. -``noise[=luma[u][t|a][h][p]:chroma[u][t|a][h][p]]`` +``noise[=<strength>[:average][:pattern][:temporal][:uniform][:hq]`` Adds noise. - :<0-100>: luma noise - :<0-100>: chroma noise - :u: uniform noise (gaussian otherwise) - :t: temporal noise (noise pattern changes between frames) - :a: averaged temporal noise (smoother, but a lot slower) - :h: high quality (slightly better looking, slightly slower) - :p: mix random noise with a (semi)regular pattern + ``strength`` + Set the noise for all components. If you want different strength + values for luma and chroma, use libavfilter's noise filter directly + (using ``--vf=lavfi=[noise=...]``), or tell the libavfilter developers + to stop being stupid. - .. note:: + ``average`` + averaged temporal noise (smoother, but a lot slower) - Deprecated. Use libavfilter's ``noise`` filter through ``--vf=lavfi`` - instead. + ``pattern`` + mix random noise with a (semi)regular pattern + + ``temporal`` + temporal noise (noise pattern changes between frames) + + ``uniform`` + uniform noise (gaussian otherwise) + + ``hq`` + high quality (slightly better looking, slightly slower) - not available + when using libavfilter ``hqdn3d[=luma_spatial:chroma_spatial:luma_tmp:chroma_tmp]`` This filter aims to reduce image noise producing smooth images and making diff --git a/video/filter/vf_noise.c b/video/filter/vf_noise.c index 5e7bf75cd1..e47bd30a32 100644 --- a/video/filter/vf_noise.c +++ b/video/filter/vf_noise.c @@ -27,6 +27,7 @@ #include "config.h" #include "mpvcore/mp_msg.h" #include "mpvcore/cpudetect.h" +#include "mpvcore/m_option.h" #include "video/img_format.h" #include "video/mp_image.h" @@ -34,6 +35,8 @@ #include "video/memcpy_pic.h" #include "libavutil/mem.h" +#include "vf_lavfi.h" + #define MAX_NOISE 4096 #define MAX_SHIFT 1024 #define MAX_RES (MAX_NOISE-MAX_SHIFT) @@ -62,6 +65,13 @@ struct vf_priv_s { FilterParam lumaParam; FilterParam chromaParam; unsigned int outfmt; + int strength; + int averaged; + int pattern; + int temporal; + int uniform; + int hq; + struct vf_lw_opts *lw_opts; }; static int nonTempRandShift_init; @@ -369,26 +379,13 @@ static int query_format(struct vf_instance *vf, unsigned int fmt){ return 0; } -static void parse(FilterParam *fp, char* args){ - char *pos; - char *max= strchr(args, ':'); - - if(!max) max= args + strlen(args); - - fp->strength= atoi(args); - pos= strchr(args, 'u'); - if(pos && pos<max) fp->uniform=1; - pos= strchr(args, 't'); - if(pos && pos<max) fp->temporal=1; - pos= strchr(args, 'h'); - if(pos && pos<max) fp->quality=1; - pos= strchr(args, 'p'); - if(pos && pos<max) fp->pattern=1; - pos= strchr(args, 'a'); - if(pos && pos<max) { - fp->temporal=1; - fp->averaged=1; - } +static void parse(FilterParam *fp, struct vf_priv_s *p){ + fp->strength= p->strength; + fp->uniform=p->uniform; + fp->temporal=p->temporal; + fp->quality=p->hq; + fp->pattern=p->pattern; + fp->averaged=p->averaged; if(fp->strength) initNoise(fp); } @@ -403,15 +400,19 @@ static int vf_open(vf_instance_t *vf, char *args){ vf->filter=filter; vf->query_format=query_format; vf->uninit=uninit; - vf->priv=malloc(sizeof(struct vf_priv_s)); - memset(vf->priv, 0, sizeof(struct vf_priv_s)); - if(args) + +#define CH(f) ((f) ? '+' : '-') + struct vf_priv_s *p = vf->priv; + if (vf_lw_set_graph(vf, p->lw_opts, "noise", "-1:%d:%ca%cp%ct%cu", + p->strength, CH(p->averaged), CH(p->pattern), + CH(p->temporal), CH(p->uniform)) >= 0) { - char *arg2= strchr(args,':'); - if(arg2) parse(&vf->priv->chromaParam, arg2+1); - parse(&vf->priv->lumaParam, args); + return 1; } + parse(&vf->priv->lumaParam, vf->priv); + parse(&vf->priv->chromaParam, vf->priv); + // check csp: vf->priv->outfmt=vf_match_csp(&vf->next,fmt_list,IMGFMT_420P); if(!vf->priv->outfmt) @@ -435,10 +436,25 @@ static int vf_open(vf_instance_t *vf, char *args){ return 1; } +#define OPT_BASE_STRUCT struct vf_priv_s const vf_info_t vf_info_noise = { .description = "noise generator", .name = "noise", .open = vf_open, + .priv_size = sizeof(struct vf_priv_s), + .priv_defaults = &(const struct vf_priv_s){ + .strength = 2, + }, + .options = (const struct m_option[]){ + OPT_INTRANGE("strength", strength, 0, 0, 100), + OPT_FLAG("averaged", averaged, 0), + OPT_FLAG("pattern", pattern, 0), + OPT_FLAG("temporal", temporal, 0), + OPT_FLAG("uniform", uniform, 0), + OPT_FLAG("hq", hq, 0), + OPT_SUBSTRUCT("", lw_opts, vf_lw_conf, 0), + {0} + }, }; //===========================================================================// |