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.
This commit is contained in:
wm4 2013-12-03 22:28:36 +01:00
parent ad950be415
commit 6a2eeedc4c
2 changed files with 62 additions and 37 deletions

View File

@ -426,21 +426,30 @@ Available filters are:
``'--vf=lavfi=yadif:o="threads=2,thread_type=slice"'`` ``'--vf=lavfi=yadif:o="threads=2,thread_type=slice"'``
forces a specific threading configuration. 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. Adds noise.
:<0-100>: luma noise ``strength``
:<0-100>: chroma noise Set the noise for all components. If you want different strength
:u: uniform noise (gaussian otherwise) values for luma and chroma, use libavfilter's noise filter directly
:t: temporal noise (noise pattern changes between frames) (using ``--vf=lavfi=[noise=...]``), or tell the libavfilter developers
:a: averaged temporal noise (smoother, but a lot slower) to stop being stupid.
:h: high quality (slightly better looking, slightly slower)
:p: mix random noise with a (semi)regular pattern
.. note:: ``average``
averaged temporal noise (smoother, but a lot slower)
Deprecated. Use libavfilter's ``noise`` filter through ``--vf=lavfi`` ``pattern``
instead. 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]`` ``hqdn3d[=luma_spatial:chroma_spatial:luma_tmp:chroma_tmp]``
This filter aims to reduce image noise producing smooth images and making This filter aims to reduce image noise producing smooth images and making

View File

@ -27,6 +27,7 @@
#include "config.h" #include "config.h"
#include "mpvcore/mp_msg.h" #include "mpvcore/mp_msg.h"
#include "mpvcore/cpudetect.h" #include "mpvcore/cpudetect.h"
#include "mpvcore/m_option.h"
#include "video/img_format.h" #include "video/img_format.h"
#include "video/mp_image.h" #include "video/mp_image.h"
@ -34,6 +35,8 @@
#include "video/memcpy_pic.h" #include "video/memcpy_pic.h"
#include "libavutil/mem.h" #include "libavutil/mem.h"
#include "vf_lavfi.h"
#define MAX_NOISE 4096 #define MAX_NOISE 4096
#define MAX_SHIFT 1024 #define MAX_SHIFT 1024
#define MAX_RES (MAX_NOISE-MAX_SHIFT) #define MAX_RES (MAX_NOISE-MAX_SHIFT)
@ -62,6 +65,13 @@ struct vf_priv_s {
FilterParam lumaParam; FilterParam lumaParam;
FilterParam chromaParam; FilterParam chromaParam;
unsigned int outfmt; 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; static int nonTempRandShift_init;
@ -369,26 +379,13 @@ static int query_format(struct vf_instance *vf, unsigned int fmt){
return 0; return 0;
} }
static void parse(FilterParam *fp, char* args){ static void parse(FilterParam *fp, struct vf_priv_s *p){
char *pos; fp->strength= p->strength;
char *max= strchr(args, ':'); fp->uniform=p->uniform;
fp->temporal=p->temporal;
if(!max) max= args + strlen(args); fp->quality=p->hq;
fp->pattern=p->pattern;
fp->strength= atoi(args); fp->averaged=p->averaged;
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;
}
if(fp->strength) initNoise(fp); if(fp->strength) initNoise(fp);
} }
@ -403,15 +400,19 @@ static int vf_open(vf_instance_t *vf, char *args){
vf->filter=filter; vf->filter=filter;
vf->query_format=query_format; vf->query_format=query_format;
vf->uninit=uninit; vf->uninit=uninit;
vf->priv=malloc(sizeof(struct vf_priv_s));
memset(vf->priv, 0, sizeof(struct vf_priv_s)); #define CH(f) ((f) ? '+' : '-')
if(args) 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,':'); return 1;
if(arg2) parse(&vf->priv->chromaParam, arg2+1);
parse(&vf->priv->lumaParam, args);
} }
parse(&vf->priv->lumaParam, vf->priv);
parse(&vf->priv->chromaParam, vf->priv);
// check csp: // check csp:
vf->priv->outfmt=vf_match_csp(&vf->next,fmt_list,IMGFMT_420P); vf->priv->outfmt=vf_match_csp(&vf->next,fmt_list,IMGFMT_420P);
if(!vf->priv->outfmt) if(!vf->priv->outfmt)
@ -435,10 +436,25 @@ static int vf_open(vf_instance_t *vf, char *args){
return 1; return 1;
} }
#define OPT_BASE_STRUCT struct vf_priv_s
const vf_info_t vf_info_noise = { const vf_info_t vf_info_noise = {
.description = "noise generator", .description = "noise generator",
.name = "noise", .name = "noise",
.open = vf_open, .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}
},
}; };
//===========================================================================// //===========================================================================//