mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-12-23 12:43:46 +02:00
lavfi: remove bad inverse telecine filters
Signed-off-by: Paul B Mahol <onemda@gmail.com>
This commit is contained in:
parent
a5ebd2d987
commit
f0a149e538
@ -4303,16 +4303,13 @@ the named filter.
|
||||
|
||||
The list of the currently supported filters follows:
|
||||
@table @var
|
||||
@item detc
|
||||
@item dint
|
||||
@item divtc
|
||||
@item down3dright
|
||||
@item eq2
|
||||
@item eq
|
||||
@item fil
|
||||
@item fspp
|
||||
@item ilpack
|
||||
@item ivtc
|
||||
@item mcdeint
|
||||
@item ow
|
||||
@item perspective
|
||||
|
@ -192,17 +192,13 @@ OBJS-$(CONFIG_NULLSINK_FILTER) += vsink_nullsink.o
|
||||
|
||||
OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/mp_image.o
|
||||
OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/img_format.o
|
||||
OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_detc.o
|
||||
OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_dint.o
|
||||
OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_divtc.o
|
||||
OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_down3dright.o
|
||||
OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_eq2.o
|
||||
OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_eq.o
|
||||
OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_fil.o
|
||||
#OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_filmdint.o
|
||||
OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_fspp.o
|
||||
OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_ilpack.o
|
||||
OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_ivtc.o
|
||||
OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_mcdeint.o
|
||||
OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_ow.o
|
||||
OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_perspective.o
|
||||
|
@ -1,453 +0,0 @@
|
||||
/*
|
||||
* This file is part of MPlayer.
|
||||
*
|
||||
* MPlayer is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* MPlayer is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "mp_msg.h"
|
||||
|
||||
#include "img_format.h"
|
||||
#include "mp_image.h"
|
||||
#include "vf.h"
|
||||
|
||||
#include "libvo/fastmemcpy.h"
|
||||
|
||||
struct metrics {
|
||||
int even;
|
||||
int odd;
|
||||
int noise;
|
||||
int temp;
|
||||
};
|
||||
|
||||
struct vf_priv_s {
|
||||
int frame;
|
||||
int drop, lastdrop;
|
||||
struct metrics pm;
|
||||
int thres[5];
|
||||
int inframes, outframes;
|
||||
int mode;
|
||||
int (*analyze)(struct vf_priv_s *, mp_image_t *, mp_image_t *);
|
||||
int needread;
|
||||
};
|
||||
|
||||
#define COMPE(a,b,e) (abs((a)-(b)) < (((a)+(b))>>(e)))
|
||||
#define COMPARABLE(a,b) COMPE((a),(b),2)
|
||||
#define VERYCLOSE(a,b) COMPE((a),(b),3)
|
||||
|
||||
#define OUTER_TC_NBHD(s) ( \
|
||||
COMPARABLE((s)[-1].m.even,(s)[-1].m.odd) && \
|
||||
COMPARABLE((s)[1].m.even,(s)[0].m.odd) && \
|
||||
COMPARABLE((s)[2].m.even,(s)[1].m.odd) && \
|
||||
COMPARABLE((s)[-1].m.noise,(s)[0].m.temp) && \
|
||||
COMPARABLE((s)[2].m.noise,(s)[2].m.temp) )
|
||||
|
||||
#define INNER_TC_NBHD(s,l,h) ( \
|
||||
COMPARABLE((s)[0].m.even,(l)) && \
|
||||
COMPARABLE((s)[2].m.odd,(l)) && ( \
|
||||
COMPARABLE((s)[0].m.noise,(h)) || \
|
||||
COMPARABLE((s)[1].m.noise,(h)) ) )
|
||||
|
||||
enum {
|
||||
TC_DROP,
|
||||
TC_PROG,
|
||||
TC_IL1,
|
||||
TC_IL2
|
||||
};
|
||||
|
||||
static void block_diffs(struct metrics *m, unsigned char *old, unsigned char *new, int os, int ns)
|
||||
{
|
||||
int x, y, even=0, odd=0, noise, temp;
|
||||
unsigned char *oldp, *newp;
|
||||
m->noise = m->temp = 0;
|
||||
for (x = 8; x; x--) {
|
||||
oldp = old++;
|
||||
newp = new++;
|
||||
noise = temp = 0;
|
||||
for (y = 4; y; y--) {
|
||||
even += abs(newp[0]-oldp[0]);
|
||||
odd += abs(newp[ns]-oldp[os]);
|
||||
noise += newp[ns]-newp[0];
|
||||
temp += oldp[os]-newp[0];
|
||||
oldp += os<<1;
|
||||
newp += ns<<1;
|
||||
}
|
||||
m->noise += abs(noise);
|
||||
m->temp += abs(temp);
|
||||
}
|
||||
m->even = even;
|
||||
m->odd = odd;
|
||||
}
|
||||
|
||||
static void diff_planes(struct metrics *m, unsigned char *old, unsigned char *new, int w, int h, int os, int ns)
|
||||
{
|
||||
int x, y, me=0, mo=0, mn=0, mt=0;
|
||||
struct metrics l;
|
||||
for (y = 0; y < h-7; y += 8) {
|
||||
for (x = 0; x < w-7; x += 8) {
|
||||
block_diffs(&l, old+x+y*os, new+x+y*ns, os, ns);
|
||||
if (l.even > me) me = l.even;
|
||||
if (l.odd > mo) mo = l.odd;
|
||||
if (l.noise > mn) mn = l.noise;
|
||||
if (l.temp > mt) mt = l.temp;
|
||||
}
|
||||
}
|
||||
m->even = me;
|
||||
m->odd = mo;
|
||||
m->noise = mn;
|
||||
m->temp = mt;
|
||||
}
|
||||
|
||||
static void diff_fields(struct metrics *metr, mp_image_t *old, mp_image_t *new)
|
||||
{
|
||||
struct metrics m, mu, mv;
|
||||
diff_planes(&m, old->planes[0], new->planes[0],
|
||||
new->w, new->h, old->stride[0], new->stride[0]);
|
||||
if (new->flags & MP_IMGFLAG_PLANAR) {
|
||||
diff_planes(&mu, old->planes[1], new->planes[1],
|
||||
new->chroma_width, new->chroma_height,
|
||||
old->stride[1], new->stride[1]);
|
||||
diff_planes(&mv, old->planes[2], new->planes[2],
|
||||
new->chroma_width, new->chroma_height,
|
||||
old->stride[2], new->stride[2]);
|
||||
if (mu.even > m.even) m.even = mu.even;
|
||||
if (mu.odd > m.odd) m.odd = mu.odd;
|
||||
if (mu.noise > m.noise) m.noise = mu.noise;
|
||||
if (mu.temp > m.temp) m.temp = mu.temp;
|
||||
if (mv.even > m.even) m.even = mv.even;
|
||||
if (mv.odd > m.odd) m.odd = mv.odd;
|
||||
if (mv.noise > m.noise) m.noise = mv.noise;
|
||||
if (mv.temp > m.temp) m.temp = mv.temp;
|
||||
}
|
||||
*metr = m;
|
||||
}
|
||||
|
||||
static void status(int f, struct metrics *m)
|
||||
{
|
||||
ff_mp_msg(MSGT_VFILTER, MSGL_V, "frame %d: e=%d o=%d n=%d t=%d\n",
|
||||
f, m->even, m->odd, m->noise, m->temp);
|
||||
}
|
||||
|
||||
static int analyze_fixed_pattern(struct vf_priv_s *p, mp_image_t *new, mp_image_t *old)
|
||||
{
|
||||
if (p->frame >= 0) p->frame = (p->frame+1)%5;
|
||||
ff_mp_msg(MSGT_VFILTER, MSGL_V, "frame %d\n", p->frame);
|
||||
switch (p->frame) {
|
||||
case -1: case 0: case 1: case 2:
|
||||
return TC_PROG;
|
||||
case 3:
|
||||
return TC_IL1;
|
||||
case 4:
|
||||
return TC_IL2;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int analyze_aggressive(struct vf_priv_s *p, mp_image_t *new, mp_image_t *old)
|
||||
{
|
||||
struct metrics m, pm;
|
||||
|
||||
if (p->frame >= 0) p->frame = (p->frame+1)%5;
|
||||
|
||||
diff_fields(&m, old, new);
|
||||
|
||||
status(p->frame, &m);
|
||||
|
||||
pm = p->pm;
|
||||
p->pm = m;
|
||||
|
||||
if (p->frame == 4) {
|
||||
/* We need to break at scene changes, but is this a valid test? */
|
||||
if ((m.even > p->thres[2]) && (m.odd > p->thres[2]) && (m.temp > p->thres[3])
|
||||
&& (m.temp > 5*pm.temp) && (m.temp*2 > m.noise)) {
|
||||
ff_mp_msg(MSGT_VFILTER, MSGL_V, "scene change breaking telecine!\n");
|
||||
p->frame = -1;
|
||||
return TC_DROP;
|
||||
}
|
||||
/* Thres. is to compensate for quantization errors when noise is low */
|
||||
if (m.noise - m.temp > -p->thres[4]) {
|
||||
if (COMPARABLE(m.even, pm.odd)) {
|
||||
//ff_mp_msg(MSGT_VFILTER, MSGL_V, "confirmed field match!\n");
|
||||
return TC_IL2;
|
||||
} else if ((m.even < p->thres[0]) && (m.odd < p->thres[0]) && VERYCLOSE(m.even, m.odd)
|
||||
&& VERYCLOSE(m.noise,m.temp) && VERYCLOSE(m.noise,pm.noise)) {
|
||||
ff_mp_msg(MSGT_VFILTER, MSGL_V, "interlaced frame appears in duplicate!!!\n");
|
||||
p->pm = pm; /* hack :) */
|
||||
p->frame = 3;
|
||||
return TC_IL1;
|
||||
}
|
||||
} else {
|
||||
ff_mp_msg(MSGT_VFILTER, MSGL_V, "mismatched telecine fields!\n");
|
||||
p->frame = -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (2*m.even*m.temp < m.odd*m.noise) {
|
||||
ff_mp_msg(MSGT_VFILTER, MSGL_V, "caught telecine sync!\n");
|
||||
p->frame = 3;
|
||||
return TC_IL1;
|
||||
}
|
||||
|
||||
if (p->frame < 3) {
|
||||
if (m.noise > p->thres[3]) {
|
||||
if (m.noise > 2*m.temp) {
|
||||
ff_mp_msg(MSGT_VFILTER, MSGL_V, "merging fields out of sequence!\n");
|
||||
return TC_IL2;
|
||||
}
|
||||
if ((m.noise > 2*pm.noise) && (m.even > p->thres[2]) && (m.odd > p->thres[2])) {
|
||||
ff_mp_msg(MSGT_VFILTER, MSGL_V, "dropping horrible interlaced frame!\n");
|
||||
return TC_DROP;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch (p->frame) {
|
||||
case -1:
|
||||
if (4*m.noise > 5*m.temp) {
|
||||
ff_mp_msg(MSGT_VFILTER, MSGL_V, "merging fields out of sequence!\n");
|
||||
return TC_IL2;
|
||||
}
|
||||
case 0:
|
||||
case 1:
|
||||
case 2:
|
||||
return TC_PROG;
|
||||
case 3:
|
||||
if ((m.even > p->thres[1]) && (m.even > m.odd) && (m.temp > m.noise)) {
|
||||
ff_mp_msg(MSGT_VFILTER, MSGL_V, "lost telecine tracking!\n");
|
||||
p->frame = -1;
|
||||
return TC_PROG;
|
||||
}
|
||||
return TC_IL1;
|
||||
case 4:
|
||||
return TC_IL2;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void copy_image(mp_image_t *dmpi, mp_image_t *mpi, int field)
|
||||
{
|
||||
switch (field) {
|
||||
case 0:
|
||||
my_memcpy_pic(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h/2,
|
||||
dmpi->stride[0]*2, mpi->stride[0]*2);
|
||||
if (mpi->flags & MP_IMGFLAG_PLANAR) {
|
||||
my_memcpy_pic(dmpi->planes[1], mpi->planes[1],
|
||||
mpi->chroma_width, mpi->chroma_height/2,
|
||||
dmpi->stride[1]*2, mpi->stride[1]*2);
|
||||
my_memcpy_pic(dmpi->planes[2], mpi->planes[2],
|
||||
mpi->chroma_width, mpi->chroma_height/2,
|
||||
dmpi->stride[2]*2, mpi->stride[2]*2);
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
my_memcpy_pic(dmpi->planes[0]+dmpi->stride[0],
|
||||
mpi->planes[0]+mpi->stride[0], mpi->w, mpi->h/2,
|
||||
dmpi->stride[0]*2, mpi->stride[0]*2);
|
||||
if (mpi->flags & MP_IMGFLAG_PLANAR) {
|
||||
my_memcpy_pic(dmpi->planes[1]+dmpi->stride[1],
|
||||
mpi->planes[1]+mpi->stride[1],
|
||||
mpi->chroma_width, mpi->chroma_height/2,
|
||||
dmpi->stride[1]*2, mpi->stride[1]*2);
|
||||
my_memcpy_pic(dmpi->planes[2]+dmpi->stride[2],
|
||||
mpi->planes[2]+mpi->stride[2],
|
||||
mpi->chroma_width, mpi->chroma_height/2,
|
||||
dmpi->stride[2]*2, mpi->stride[2]*2);
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
memcpy_pic(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h,
|
||||
dmpi->stride[0], mpi->stride[0]);
|
||||
if (mpi->flags & MP_IMGFLAG_PLANAR) {
|
||||
memcpy_pic(dmpi->planes[1], mpi->planes[1],
|
||||
mpi->chroma_width, mpi->chroma_height,
|
||||
dmpi->stride[1], mpi->stride[1]);
|
||||
memcpy_pic(dmpi->planes[2], mpi->planes[2],
|
||||
mpi->chroma_width, mpi->chroma_height,
|
||||
dmpi->stride[2], mpi->stride[2]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static int do_put_image(struct vf_instance *vf, mp_image_t *dmpi)
|
||||
{
|
||||
struct vf_priv_s *p = vf->priv;
|
||||
int dropflag;
|
||||
|
||||
switch (p->drop) {
|
||||
default:
|
||||
dropflag = 0;
|
||||
break;
|
||||
case 1:
|
||||
dropflag = (++p->lastdrop >= 5);
|
||||
break;
|
||||
case 2:
|
||||
dropflag = (++p->lastdrop >= 5) && (4*p->inframes <= 5*p->outframes);
|
||||
break;
|
||||
}
|
||||
|
||||
if (dropflag) {
|
||||
ff_mp_msg(MSGT_VFILTER, MSGL_V, "drop! [%d/%d=%g]\n",
|
||||
p->outframes, p->inframes, (float)p->outframes/p->inframes);
|
||||
p->lastdrop = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
p->outframes++;
|
||||
return ff_vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE);
|
||||
}
|
||||
|
||||
static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts)
|
||||
{
|
||||
int ret=0;
|
||||
mp_image_t *dmpi;
|
||||
struct vf_priv_s *p = vf->priv;
|
||||
|
||||
p->inframes++;
|
||||
|
||||
if (p->needread) dmpi = ff_vf_get_image(vf->next, mpi->imgfmt,
|
||||
MP_IMGTYPE_STATIC, MP_IMGFLAG_ACCEPT_STRIDE |
|
||||
MP_IMGFLAG_PRESERVE | MP_IMGFLAG_READABLE,
|
||||
mpi->width, mpi->height);
|
||||
/* FIXME: is there a good way to get rid of static type? */
|
||||
else dmpi = ff_vf_get_image(vf->next, mpi->imgfmt,
|
||||
MP_IMGTYPE_STATIC, MP_IMGFLAG_ACCEPT_STRIDE |
|
||||
MP_IMGFLAG_PRESERVE, mpi->width, mpi->height);
|
||||
|
||||
switch (p->analyze(p, mpi, dmpi)) {
|
||||
case TC_DROP:
|
||||
/* Don't copy anything unless we'll need to read it. */
|
||||
if (p->needread) copy_image(dmpi, mpi, 2);
|
||||
p->lastdrop = 0;
|
||||
break;
|
||||
case TC_PROG:
|
||||
/* Copy and display the whole frame. */
|
||||
copy_image(dmpi, mpi, 2);
|
||||
ret = do_put_image(vf, dmpi);
|
||||
break;
|
||||
case TC_IL1:
|
||||
/* Only copy bottom field unless we need to read. */
|
||||
if (p->needread) copy_image(dmpi, mpi, 2);
|
||||
else copy_image(dmpi, mpi, 1);
|
||||
p->lastdrop = 0;
|
||||
break;
|
||||
case TC_IL2:
|
||||
/* Copy top field and show frame, then copy bottom if needed. */
|
||||
copy_image(dmpi, mpi, 0);
|
||||
ret = do_put_image(vf, dmpi);
|
||||
if (p->needread) copy_image(dmpi, mpi, 1);
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int query_format(struct vf_instance *vf, unsigned int fmt)
|
||||
{
|
||||
/* FIXME - figure out which other formats work */
|
||||
switch (fmt) {
|
||||
case IMGFMT_YV12:
|
||||
case IMGFMT_IYUV:
|
||||
case IMGFMT_I420:
|
||||
return ff_vf_next_query_format(vf, fmt);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int config(struct vf_instance *vf,
|
||||
int width, int height, int d_width, int d_height,
|
||||
unsigned int flags, unsigned int outfmt)
|
||||
{
|
||||
return ff_vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
|
||||
}
|
||||
|
||||
static void uninit(struct vf_instance *vf)
|
||||
{
|
||||
free(vf->priv);
|
||||
}
|
||||
|
||||
static struct {
|
||||
const char *name;
|
||||
int (*func)(struct vf_priv_s *p, mp_image_t *new, mp_image_t *old);
|
||||
int needread;
|
||||
} anal_funcs[] = {
|
||||
{ "fixed", analyze_fixed_pattern, 0 },
|
||||
{ "aggressive", analyze_aggressive, 1 },
|
||||
{ NULL, NULL, 0 }
|
||||
};
|
||||
|
||||
#define STARTVARS if (0)
|
||||
#define GETVAR(str, name, out, func) \
|
||||
else if (!strncmp((str), name "=", sizeof(name))) \
|
||||
(out) = (func)((str) + sizeof(name))
|
||||
|
||||
static void parse_var(struct vf_priv_s *p, char *var)
|
||||
{
|
||||
STARTVARS;
|
||||
GETVAR(var, "dr", p->drop, atoi);
|
||||
GETVAR(var, "t0", p->thres[0], atoi);
|
||||
GETVAR(var, "t1", p->thres[1], atoi);
|
||||
GETVAR(var, "t2", p->thres[2], atoi);
|
||||
GETVAR(var, "t3", p->thres[3], atoi);
|
||||
GETVAR(var, "t4", p->thres[4], atoi);
|
||||
GETVAR(var, "fr", p->frame, atoi);
|
||||
GETVAR(var, "am", p->mode, atoi);
|
||||
}
|
||||
|
||||
static void parse_args(struct vf_priv_s *p, char *args)
|
||||
{
|
||||
char *next, *orig;
|
||||
for (args=orig=strdup(args); args; args=next) {
|
||||
next = strchr(args, ':');
|
||||
if (next) *next++ = 0;
|
||||
parse_var(p, args);
|
||||
}
|
||||
free(orig);
|
||||
}
|
||||
|
||||
static int vf_open(vf_instance_t *vf, char *args)
|
||||
{
|
||||
struct vf_priv_s *p;
|
||||
vf->config = config;
|
||||
vf->put_image = put_image;
|
||||
vf->query_format = query_format;
|
||||
vf->uninit = uninit;
|
||||
vf->default_reqs = VFCAP_ACCEPT_STRIDE;
|
||||
vf->priv = p = calloc(1, sizeof(struct vf_priv_s));
|
||||
p->frame = -1;
|
||||
p->thres[0] = 440;
|
||||
p->thres[1] = 720;
|
||||
p->thres[2] = 2500;
|
||||
p->thres[3] = 2500;
|
||||
p->thres[4] = 800;
|
||||
p->drop = 0;
|
||||
p->mode = 1;
|
||||
if (args) parse_args(p, args);
|
||||
p->analyze = anal_funcs[p->mode].func;
|
||||
p->needread = anal_funcs[p->mode].needread;
|
||||
return 1;
|
||||
}
|
||||
|
||||
const vf_info_t ff_vf_info_detc = {
|
||||
"de-telecine filter",
|
||||
"detc",
|
||||
"Rich Felker",
|
||||
"",
|
||||
vf_open,
|
||||
NULL
|
||||
};
|
@ -1,722 +0,0 @@
|
||||
/*
|
||||
* This file is part of MPlayer.
|
||||
*
|
||||
* MPlayer is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* MPlayer is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "mp_msg.h"
|
||||
#include "cpudetect.h"
|
||||
#include "libavutil/common.h"
|
||||
#include "libavutil/x86/asm.h"
|
||||
#include "mpbswap.h"
|
||||
|
||||
#include "img_format.h"
|
||||
#include "mp_image.h"
|
||||
#include "vf.h"
|
||||
|
||||
#include "libvo/fastmemcpy.h"
|
||||
|
||||
const vf_info_t ff_vf_info_divtc;
|
||||
|
||||
struct vf_priv_s
|
||||
{
|
||||
int deghost, pass, phase, window, fcount, bcount, frameno, misscount,
|
||||
ocount, sum[5];
|
||||
double threshold;
|
||||
FILE *file;
|
||||
int8_t *bdata;
|
||||
unsigned int *csdata;
|
||||
int *history;
|
||||
};
|
||||
|
||||
/*
|
||||
* diff_MMX and diff_C stolen from vf_decimate.c
|
||||
*/
|
||||
|
||||
#if HAVE_MMX && HAVE_EBX_AVAILABLE
|
||||
static int diff_MMX(unsigned char *old, unsigned char *new, int os, int ns)
|
||||
{
|
||||
volatile short out[4];
|
||||
__asm__ (
|
||||
"movl $8, %%ecx \n\t"
|
||||
"pxor %%mm4, %%mm4 \n\t"
|
||||
"pxor %%mm7, %%mm7 \n\t"
|
||||
|
||||
ASMALIGN(4)
|
||||
"1: \n\t"
|
||||
|
||||
"movq (%%"REG_S"), %%mm0 \n\t"
|
||||
"movq (%%"REG_S"), %%mm2 \n\t"
|
||||
"add %%"REG_a", %%"REG_S" \n\t"
|
||||
"movq (%%"REG_D"), %%mm1 \n\t"
|
||||
"add %%"REG_b", %%"REG_D" \n\t"
|
||||
"psubusb %%mm1, %%mm2 \n\t"
|
||||
"psubusb %%mm0, %%mm1 \n\t"
|
||||
"movq %%mm2, %%mm0 \n\t"
|
||||
"movq %%mm1, %%mm3 \n\t"
|
||||
"punpcklbw %%mm7, %%mm0 \n\t"
|
||||
"punpcklbw %%mm7, %%mm1 \n\t"
|
||||
"punpckhbw %%mm7, %%mm2 \n\t"
|
||||
"punpckhbw %%mm7, %%mm3 \n\t"
|
||||
"paddw %%mm0, %%mm4 \n\t"
|
||||
"paddw %%mm1, %%mm4 \n\t"
|
||||
"paddw %%mm2, %%mm4 \n\t"
|
||||
"paddw %%mm3, %%mm4 \n\t"
|
||||
|
||||
"decl %%ecx \n\t"
|
||||
"jnz 1b \n\t"
|
||||
"movq %%mm4, (%%"REG_d") \n\t"
|
||||
"emms \n\t"
|
||||
:
|
||||
: "S" (old), "D" (new), "a" ((long)os), "b" ((long)ns), "d" (out)
|
||||
: "%ecx", "memory"
|
||||
);
|
||||
return out[0]+out[1]+out[2]+out[3];
|
||||
}
|
||||
#endif
|
||||
|
||||
static int diff_C(unsigned char *old, unsigned char *new, int os, int ns)
|
||||
{
|
||||
int x, y, d=0;
|
||||
|
||||
for(y=8; y; y--, new+=ns, old+=os)
|
||||
for(x=8; x; x--)
|
||||
d+=abs(new[x]-old[x]);
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
static int (*diff)(unsigned char *, unsigned char *, int, int);
|
||||
|
||||
static int diff_plane(unsigned char *old, unsigned char *new,
|
||||
int w, int h, int os, int ns, int arg)
|
||||
{
|
||||
int x, y, d, max=0, sum=0, n=0;
|
||||
|
||||
for(y=0; y<h-7; y+=8)
|
||||
{
|
||||
for(x=0; x<w-7; x+=8)
|
||||
{
|
||||
d=diff(old+x+y*os, new+x+y*ns, os, ns);
|
||||
if(d>max) max=d;
|
||||
sum+=d;
|
||||
n++;
|
||||
}
|
||||
}
|
||||
|
||||
return (sum+n*max)/2;
|
||||
}
|
||||
|
||||
/*
|
||||
static unsigned int checksum_plane(unsigned char *p, unsigned char *z,
|
||||
int w, int h, int s, int zs, int arg)
|
||||
{
|
||||
unsigned int shift, sum;
|
||||
unsigned char *e;
|
||||
|
||||
for(sum=0; h; h--, p+=s-w)
|
||||
for(e=p+w, shift=32; p<e;)
|
||||
sum^=(*p++)<<(shift=(shift-8)&31);
|
||||
|
||||
return sum;
|
||||
}
|
||||
*/
|
||||
|
||||
static unsigned int checksum_plane(unsigned char *p, unsigned char *z,
|
||||
int w, int h, int s, int zs, int arg)
|
||||
{
|
||||
unsigned int shift;
|
||||
uint32_t sum, t;
|
||||
unsigned char *e, *e2;
|
||||
#if HAVE_FAST_64BIT
|
||||
typedef uint64_t wsum_t;
|
||||
#else
|
||||
typedef uint32_t wsum_t;
|
||||
#endif
|
||||
wsum_t wsum;
|
||||
|
||||
for(sum=0; h; h--, p+=s-w)
|
||||
{
|
||||
for(shift=0, e=p+w; (int)p&(sizeof(wsum_t)-1) && p<e;)
|
||||
sum^=*p++<<(shift=(shift-8)&31);
|
||||
|
||||
for(wsum=0, e2=e-sizeof(wsum_t)+1; p<e2; p+=sizeof(wsum_t))
|
||||
wsum^=*(wsum_t *)p;
|
||||
|
||||
#if HAVE_FAST_64BIT
|
||||
t=be2me_32((uint32_t)(wsum>>32^wsum));
|
||||
#else
|
||||
t=be2me_32(wsum);
|
||||
#endif
|
||||
|
||||
for(sum^=(t<<shift|t>>(32-shift)); p<e;)
|
||||
sum^=*p++<<(shift=(shift-8)&31);
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
static int deghost_plane(unsigned char *d, unsigned char *s,
|
||||
int w, int h, int ds, int ss, int threshold)
|
||||
{
|
||||
int t;
|
||||
unsigned char *e;
|
||||
|
||||
for(; h; h--, s+=ss-w, d+=ds-w)
|
||||
for(e=d+w; d<e; d++, s++)
|
||||
if(abs(*d-*s)>=threshold)
|
||||
*d=(t=(*d<<1)-*s)<0?0:t>255?255:t;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int copyop(unsigned char *d, unsigned char *s, int bpl, int h, int dstride, int sstride, int dummy) {
|
||||
memcpy_pic(d, s, bpl, h, dstride, sstride);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int imgop(int(*planeop)(unsigned char *, unsigned char *,
|
||||
int, int, int, int, int),
|
||||
mp_image_t *dst, mp_image_t *src, int arg)
|
||||
{
|
||||
if(dst->flags&MP_IMGFLAG_PLANAR)
|
||||
return planeop(dst->planes[0], src?src->planes[0]:0,
|
||||
dst->w, dst->h,
|
||||
dst->stride[0], src?src->stride[0]:0, arg)+
|
||||
planeop(dst->planes[1], src?src->planes[1]:0,
|
||||
dst->chroma_width, dst->chroma_height,
|
||||
dst->stride[1], src?src->stride[1]:0, arg)+
|
||||
planeop(dst->planes[2], src?src->planes[2]:0,
|
||||
dst->chroma_width, dst->chroma_height,
|
||||
dst->stride[2], src?src->stride[2]:0, arg);
|
||||
|
||||
return planeop(dst->planes[0], src?src->planes[0]:0,
|
||||
dst->w*(dst->bpp/8), dst->h,
|
||||
dst->stride[0], src?src->stride[0]:0, arg);
|
||||
}
|
||||
|
||||
/*
|
||||
* Find the phase in which the telecine pattern fits best to the
|
||||
* given 5 frame slice of frame difference measurements.
|
||||
*
|
||||
* If phase1 and phase2 are not negative, only the two specified
|
||||
* phases are tested.
|
||||
*/
|
||||
|
||||
static int match(struct vf_priv_s *p, int *diffs,
|
||||
int phase1, int phase2, double *strength)
|
||||
{
|
||||
static const int pattern1[]={ -4, 1, 1, 1, 1 },
|
||||
pattern2[]={ -2, -3, 4, 4, -3 }, *pattern;
|
||||
int f, m, n, t[5];
|
||||
|
||||
pattern=p->deghost>0?pattern2:pattern1;
|
||||
|
||||
for(f=0; f<5; f++)
|
||||
{
|
||||
if(phase1<0 || phase2<0 || f==phase1 || f==phase2)
|
||||
{
|
||||
for(n=t[f]=0; n<5; n++)
|
||||
t[f]+=diffs[n]*pattern[(n-f+5)%5];
|
||||
}
|
||||
else
|
||||
t[f]=INT_MIN;
|
||||
}
|
||||
|
||||
/* find the best match */
|
||||
for(m=0, n=1; n<5; n++)
|
||||
if(t[n]>t[m]) m=n;
|
||||
|
||||
if(strength)
|
||||
{
|
||||
/* the second best match */
|
||||
for(f=m?0:1, n=f+1; n<5; n++)
|
||||
if(n!=m && t[n]>t[f]) f=n;
|
||||
|
||||
*strength=(t[m]>0?(double)(t[m]-t[f])/t[m]:0.0);
|
||||
}
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts)
|
||||
{
|
||||
mp_image_t *dmpi, *tmpi=0;
|
||||
int n, m, f, newphase;
|
||||
struct vf_priv_s *p=vf->priv;
|
||||
unsigned int checksum;
|
||||
double d;
|
||||
|
||||
dmpi=ff_vf_get_image(vf->next, mpi->imgfmt,
|
||||
MP_IMGTYPE_STATIC, MP_IMGFLAG_ACCEPT_STRIDE |
|
||||
MP_IMGFLAG_PRESERVE | MP_IMGFLAG_READABLE,
|
||||
mpi->width, mpi->height);
|
||||
ff_vf_clone_mpi_attributes(dmpi, mpi);
|
||||
|
||||
newphase=p->phase;
|
||||
|
||||
switch(p->pass)
|
||||
{
|
||||
case 1:
|
||||
fprintf(p->file, "%08x %d\n",
|
||||
(unsigned int)imgop((void *)checksum_plane, mpi, 0, 0),
|
||||
p->frameno?imgop(diff_plane, dmpi, mpi, 0):0);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
if(p->frameno/5>p->bcount)
|
||||
{
|
||||
ff_mp_msg(MSGT_VFILTER, MSGL_ERR,
|
||||
"\n%s: Log file ends prematurely! "
|
||||
"Switching to one pass mode.\n", vf->info->name);
|
||||
p->pass=0;
|
||||
break;
|
||||
}
|
||||
|
||||
checksum=(unsigned int)imgop((void *)checksum_plane, mpi, 0, 0);
|
||||
|
||||
if(checksum!=p->csdata[p->frameno])
|
||||
{
|
||||
for(f=0; f<100; f++)
|
||||
if(p->frameno+f<p->fcount && p->csdata[p->frameno+f]==checksum)
|
||||
break;
|
||||
else if(p->frameno-f>=0 && p->csdata[p->frameno-f]==checksum)
|
||||
{
|
||||
f=-f;
|
||||
break;
|
||||
}
|
||||
|
||||
if(f<100)
|
||||
{
|
||||
ff_mp_msg(MSGT_VFILTER, MSGL_INFO,
|
||||
"\n%s: Mismatch with pass-1: %+d frame(s).\n",
|
||||
vf->info->name, f);
|
||||
|
||||
p->frameno+=f;
|
||||
p->misscount=0;
|
||||
}
|
||||
else if(p->misscount++>=30)
|
||||
{
|
||||
ff_mp_msg(MSGT_VFILTER, MSGL_ERR,
|
||||
"\n%s: Sync with pass-1 lost! "
|
||||
"Switching to one pass mode.\n", vf->info->name);
|
||||
p->pass=0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
n=(p->frameno)/5;
|
||||
if(n>=p->bcount) n=p->bcount-1;
|
||||
|
||||
newphase=p->bdata[n];
|
||||
break;
|
||||
|
||||
default:
|
||||
if(p->frameno)
|
||||
{
|
||||
int *sump=p->sum+p->frameno%5,
|
||||
*histp=p->history+p->frameno%p->window;
|
||||
|
||||
*sump-=*histp;
|
||||
*sump+=(*histp=imgop(diff_plane, dmpi, mpi, 0));
|
||||
}
|
||||
|
||||
m=match(p, p->sum, -1, -1, &d);
|
||||
|
||||
if(d>=p->threshold)
|
||||
newphase=m;
|
||||
}
|
||||
|
||||
n=p->ocount++%5;
|
||||
|
||||
if(newphase!=p->phase && ((p->phase+4)%5<n)==((newphase+4)%5<n))
|
||||
{
|
||||
p->phase=newphase;
|
||||
ff_mp_msg(MSGT_VFILTER, MSGL_STATUS,
|
||||
"\n%s: Telecine phase %d.\n", vf->info->name, p->phase);
|
||||
}
|
||||
|
||||
switch((p->frameno++-p->phase+10)%5)
|
||||
{
|
||||
case 0:
|
||||
imgop(copyop, dmpi, mpi, 0);
|
||||
return 0;
|
||||
|
||||
case 4:
|
||||
if(p->deghost>0)
|
||||
{
|
||||
tmpi=ff_vf_get_image(vf->next, mpi->imgfmt,
|
||||
MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE |
|
||||
MP_IMGFLAG_READABLE,
|
||||
mpi->width, mpi->height);
|
||||
ff_vf_clone_mpi_attributes(tmpi, mpi);
|
||||
|
||||
imgop(copyop, tmpi, mpi, 0);
|
||||
imgop(deghost_plane, tmpi, dmpi, p->deghost);
|
||||
imgop(copyop, dmpi, mpi, 0);
|
||||
return ff_vf_next_put_image(vf, tmpi, MP_NOPTS_VALUE);
|
||||
}
|
||||
}
|
||||
|
||||
imgop(copyop, dmpi, mpi, 0);
|
||||
return ff_vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE);
|
||||
}
|
||||
|
||||
static int analyze(struct vf_priv_s *p)
|
||||
{
|
||||
int *buf=0, *bp, bufsize=0, n, b, f, i, j, m, s;
|
||||
unsigned int *cbuf=0, *cp;
|
||||
int8_t *pbuf;
|
||||
int8_t lbuf[256];
|
||||
int sum[5];
|
||||
double d;
|
||||
|
||||
/* read the file */
|
||||
|
||||
n=15;
|
||||
while(fgets(lbuf, 256, p->file))
|
||||
{
|
||||
if(n>=bufsize-19)
|
||||
{
|
||||
bufsize=bufsize?bufsize*2:30000;
|
||||
if((bp=realloc(buf, bufsize*sizeof *buf))) buf=bp;
|
||||
if((cp=realloc(cbuf, bufsize*sizeof *cbuf))) cbuf=cp;
|
||||
|
||||
if(!bp || !cp)
|
||||
{
|
||||
ff_mp_msg(MSGT_VFILTER, MSGL_FATAL, "%s: Not enough memory.\n",
|
||||
ff_vf_info_divtc.name);
|
||||
free(buf);
|
||||
free(cbuf);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
sscanf(lbuf, "%x %d", cbuf+n, buf+n);
|
||||
n++;
|
||||
}
|
||||
|
||||
if(n <= 15)
|
||||
{
|
||||
ff_mp_msg(MSGT_VFILTER, MSGL_FATAL, "%s: Empty 2-pass log file.\n",
|
||||
ff_vf_info_divtc.name);
|
||||
free(buf);
|
||||
free(cbuf);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* generate some dummy data past the beginning and end of the array */
|
||||
|
||||
buf+=15, cbuf+=15;
|
||||
n-=15;
|
||||
|
||||
memcpy(buf-15, buf, 15*sizeof *buf);
|
||||
memset(cbuf-15, 0, 15*sizeof *cbuf);
|
||||
|
||||
while(n%5)
|
||||
buf[n]=buf[n-5], cbuf[n]=0, n++;
|
||||
|
||||
memcpy(buf+n, buf+n-15, 15*sizeof *buf);
|
||||
memset(cbuf+n, 0, 15*sizeof *cbuf);
|
||||
|
||||
p->csdata=cbuf;
|
||||
p->fcount=n;
|
||||
|
||||
/* array with one slot for each slice of 5 frames */
|
||||
|
||||
p->bdata=pbuf=malloc(p->bcount=b=(n/5));
|
||||
memset(pbuf, 255, b);
|
||||
|
||||
/* resolve the automatic mode */
|
||||
|
||||
if(p->deghost<0)
|
||||
{
|
||||
int deghost=-p->deghost;
|
||||
double s0=0.0, s1=0.0;
|
||||
|
||||
for(f=0; f<n; f+=5)
|
||||
{
|
||||
p->deghost=0; match(p, buf+f, -1, -1, &d); s0+=d;
|
||||
p->deghost=1; match(p, buf+f, -1, -1, &d); s1+=d;
|
||||
}
|
||||
|
||||
p->deghost=s1>s0?deghost:0;
|
||||
|
||||
ff_mp_msg(MSGT_VFILTER, MSGL_INFO,
|
||||
"%s: Deghosting %-3s (relative pattern strength %+.2fdB).\n",
|
||||
ff_vf_info_divtc.name,
|
||||
p->deghost?"ON":"OFF",
|
||||
10.0*log10(s1/s0));
|
||||
}
|
||||
|
||||
/* analyze the data */
|
||||
|
||||
for(f=0; f<5; f++)
|
||||
for(sum[f]=0, n=-15; n<20; n+=5)
|
||||
sum[f]+=buf[n+f];
|
||||
|
||||
for(f=0; f<b; f++)
|
||||
{
|
||||
m=match(p, sum, -1, -1, &d);
|
||||
|
||||
if(d>=p->threshold)
|
||||
pbuf[f]=m;
|
||||
|
||||
if(f<b-1)
|
||||
for(n=0; n<5; n++)
|
||||
sum[n]=sum[n]-buf[5*(f-3)+n]+buf[5*(f+4)+n];
|
||||
}
|
||||
|
||||
/* fill in the gaps */
|
||||
|
||||
/* the beginning */
|
||||
for(f=0; f<b && pbuf[f]==-1; f++);
|
||||
|
||||
if(f==b)
|
||||
{
|
||||
free(buf-15);
|
||||
ff_mp_msg(MSGT_VFILTER, MSGL_FATAL, "%s: No telecine pattern found!\n",
|
||||
ff_vf_info_divtc.name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
for(n=0; n<f; pbuf[n++]=pbuf[f]);
|
||||
|
||||
/* the end */
|
||||
for(f=b-1; pbuf[f]==-1; f--);
|
||||
for(n=f+1; n<b; pbuf[n++]=pbuf[f]);
|
||||
|
||||
/* the rest */
|
||||
for(f=0;;)
|
||||
{
|
||||
while(f<b && pbuf[f]!=-1) f++;
|
||||
if(f==b) break;
|
||||
for(n=f; pbuf[n]==-1; n++);
|
||||
|
||||
if(pbuf[f-1]==pbuf[n])
|
||||
{
|
||||
/* just a gap */
|
||||
while(f<n) pbuf[f++]=pbuf[n];
|
||||
}
|
||||
else
|
||||
{
|
||||
/* phase change, reanalyze the original data in the gap with zero
|
||||
threshold for only the two phases that appear at the ends */
|
||||
|
||||
for(i=0; i<5; i++)
|
||||
for(sum[i]=0, j=5*f-15; j<5*f; j+=5)
|
||||
sum[i]+=buf[i+j];
|
||||
|
||||
for(i=f; i<n; i++)
|
||||
{
|
||||
pbuf[i]=match(p, sum, pbuf[f-1], pbuf[n], 0);
|
||||
|
||||
for(j=0; j<5; j++)
|
||||
sum[j]=sum[j]-buf[5*(i-3)+j]+buf[5*(i+4)+j];
|
||||
}
|
||||
|
||||
/* estimate the transition point by dividing the gap
|
||||
in the same proportion as the number of matches of each kind */
|
||||
|
||||
for(i=f, m=f; i<n; i++)
|
||||
if(pbuf[i]==pbuf[f-1]) m++;
|
||||
|
||||
/* find the transition of the right direction nearest to the
|
||||
estimated point */
|
||||
|
||||
if(m>f && m<n)
|
||||
{
|
||||
for(j=m; j>f; j--)
|
||||
if(pbuf[j-1]==pbuf[f-1] && pbuf[j]==pbuf[n]) break;
|
||||
for(s=m; s<n; s++)
|
||||
if(pbuf[s-1]==pbuf[f-1] && pbuf[s]==pbuf[n]) break;
|
||||
|
||||
m=(s-m<m-j)?s:j;
|
||||
}
|
||||
|
||||
/* and rewrite the data to allow only this one transition */
|
||||
|
||||
for(i=f; i<m; i++)
|
||||
pbuf[i]=pbuf[f-1];
|
||||
|
||||
for(; i<n; i++)
|
||||
pbuf[i]=pbuf[n];
|
||||
|
||||
f=n;
|
||||
}
|
||||
}
|
||||
|
||||
free(buf-15);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int query_format(struct vf_instance *vf, unsigned int fmt)
|
||||
{
|
||||
switch(fmt)
|
||||
{
|
||||
case IMGFMT_444P: case IMGFMT_IYUV: case IMGFMT_RGB24:
|
||||
case IMGFMT_422P: case IMGFMT_UYVY: case IMGFMT_BGR24:
|
||||
case IMGFMT_411P: case IMGFMT_YUY2: case IMGFMT_IF09:
|
||||
case IMGFMT_YV12: case IMGFMT_I420: case IMGFMT_YVU9:
|
||||
case IMGFMT_IUYV: case IMGFMT_Y800: case IMGFMT_Y8:
|
||||
return ff_vf_next_query_format(vf,fmt);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void uninit(struct vf_instance *vf)
|
||||
{
|
||||
if(vf->priv)
|
||||
{
|
||||
if(vf->priv->file) fclose(vf->priv->file);
|
||||
if(vf->priv->csdata) free(vf->priv->csdata-15);
|
||||
free(vf->priv->bdata);
|
||||
free(vf->priv->history);
|
||||
free(vf->priv);
|
||||
}
|
||||
}
|
||||
|
||||
static int vf_open(vf_instance_t *vf, char *args)
|
||||
{
|
||||
struct vf_priv_s *p;
|
||||
const char *filename="framediff.log";
|
||||
char *ap, *q, *a;
|
||||
|
||||
if(args && !(args=strdup(args)))
|
||||
{
|
||||
nomem:
|
||||
ff_mp_msg(MSGT_VFILTER, MSGL_FATAL,
|
||||
"%s: Not enough memory.\n", vf->info->name);
|
||||
fail:
|
||||
uninit(vf);
|
||||
free(args);
|
||||
return 0;
|
||||
}
|
||||
|
||||
vf->put_image=put_image;
|
||||
vf->uninit=uninit;
|
||||
vf->query_format=query_format;
|
||||
vf->default_reqs=VFCAP_ACCEPT_STRIDE;
|
||||
if(!(vf->priv=p=calloc(1, sizeof(struct vf_priv_s))))
|
||||
goto nomem;
|
||||
|
||||
p->phase=5;
|
||||
p->threshold=0.5;
|
||||
p->window=30;
|
||||
|
||||
if((ap=args))
|
||||
while(*ap)
|
||||
{
|
||||
q=ap;
|
||||
if((ap=strchr(q, ':'))) *ap++=0; else ap=q+strlen(q);
|
||||
if((a=strchr(q, '='))) *a++=0; else a=q+strlen(q);
|
||||
|
||||
switch(*q)
|
||||
{
|
||||
case 0: break;
|
||||
case 'f': filename=a; break;
|
||||
case 't': p->threshold=atof(a); break;
|
||||
case 'w': p->window=5*(atoi(a)+4)/5; break;
|
||||
case 'd': p->deghost=atoi(a); break;
|
||||
case 'p':
|
||||
if(q[1]=='h') p->phase=atoi(a);
|
||||
else p->pass=atoi(a);
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
ff_mp_msg(MSGT_VFILTER, MSGL_INFO,
|
||||
"\n%s options:\n\n"
|
||||
"pass=1|2 - Use 2-pass mode.\n"
|
||||
"file=filename - Set the 2-pass log file name "
|
||||
"(default %s).\n"
|
||||
"threshold=value - Set the pattern recognition "
|
||||
"sensitivity (default %g).\n"
|
||||
"deghost=value - Select deghosting threshold "
|
||||
"(default %d).\n"
|
||||
"window=numframes - Set the statistics window "
|
||||
"for 1-pass mode (default %d).\n"
|
||||
"phase=0|1|2|3|4 - Set the initial phase "
|
||||
"for 1-pass mode (default %d).\n\n"
|
||||
"The option names can be abbreviated to the shortest "
|
||||
"unique prefix.\n\n",
|
||||
vf->info->name, filename, p->threshold, p->deghost,
|
||||
p->window, p->phase%5);
|
||||
break;
|
||||
|
||||
default:
|
||||
ff_mp_msg(MSGT_VFILTER, MSGL_FATAL,
|
||||
"%s: Unknown argument %s.\n", vf->info->name, q);
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
switch(p->pass)
|
||||
{
|
||||
case 1:
|
||||
if(!(p->file=fopen(filename, "w")))
|
||||
{
|
||||
ff_mp_msg(MSGT_VFILTER, MSGL_FATAL,
|
||||
"%s: Can't create file %s.\n", vf->info->name, filename);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 2:
|
||||
if(!(p->file=fopen(filename, "r")))
|
||||
{
|
||||
ff_mp_msg(MSGT_VFILTER, MSGL_FATAL,
|
||||
"%s: Can't open file %s.\n", vf->info->name, filename);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if(!analyze(p))
|
||||
goto fail;
|
||||
|
||||
fclose(p->file);
|
||||
p->file=0;
|
||||
break;
|
||||
}
|
||||
|
||||
if(p->window<5) p->window=5;
|
||||
if(!(p->history=calloc(sizeof *p->history, p->window)))
|
||||
goto nomem;
|
||||
|
||||
diff = diff_C;
|
||||
#if HAVE_MMX && HAVE_EBX_AVAILABLE
|
||||
if(ff_gCpuCaps.hasMMX) diff = diff_MMX;
|
||||
#endif
|
||||
|
||||
free(args);
|
||||
return 1;
|
||||
}
|
||||
|
||||
const vf_info_t ff_vf_info_divtc =
|
||||
{
|
||||
"inverse telecine for deinterlaced video",
|
||||
"divtc",
|
||||
"Ville Saari",
|
||||
"",
|
||||
vf_open,
|
||||
NULL
|
||||
};
|
File diff suppressed because it is too large
Load Diff
@ -1,550 +0,0 @@
|
||||
/*
|
||||
* This file is part of MPlayer.
|
||||
*
|
||||
* MPlayer is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* MPlayer is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "mp_msg.h"
|
||||
#include "cpudetect.h"
|
||||
|
||||
#include "img_format.h"
|
||||
#include "mp_image.h"
|
||||
#include "vf.h"
|
||||
#include "libavutil/x86/asm.h"
|
||||
#include "libvo/fastmemcpy.h"
|
||||
|
||||
|
||||
struct metrics {
|
||||
/* difference: total, even lines, odd lines */
|
||||
int d, e, o;
|
||||
/* noise: temporal, spacial (current), spacial (past) */
|
||||
int t, s, p;
|
||||
};
|
||||
|
||||
struct frameinfo {
|
||||
/* peak, relative, mean */
|
||||
struct metrics p, r, m;
|
||||
};
|
||||
|
||||
struct vf_priv_s {
|
||||
struct frameinfo fi[2];
|
||||
mp_image_t *dmpi;
|
||||
int first;
|
||||
int drop, lastdrop, dropnext;
|
||||
int inframes, outframes;
|
||||
};
|
||||
|
||||
enum {
|
||||
F_DROP,
|
||||
F_MERGE,
|
||||
F_NEXT,
|
||||
F_SHOW
|
||||
};
|
||||
|
||||
#if HAVE_MMX && HAVE_EBX_AVAILABLE
|
||||
static void block_diffs_MMX(struct metrics *m, unsigned char *old, unsigned char *new, int os, int ns)
|
||||
{
|
||||
int i;
|
||||
short out[24]; // output buffer for the partial metrics from the mmx code
|
||||
|
||||
__asm__ (
|
||||
"movl $4, %%ecx \n\t"
|
||||
"pxor %%mm4, %%mm4 \n\t" // 4 even difference sums
|
||||
"pxor %%mm5, %%mm5 \n\t" // 4 odd difference sums
|
||||
"pxor %%mm7, %%mm7 \n\t" // all zeros
|
||||
|
||||
ASMALIGN(4)
|
||||
"1: \n\t"
|
||||
|
||||
// Even difference
|
||||
"movq (%%"REG_S"), %%mm0 \n\t"
|
||||
"movq (%%"REG_S"), %%mm2 \n\t"
|
||||
"add %%"REG_a", %%"REG_S" \n\t"
|
||||
"movq (%%"REG_D"), %%mm1 \n\t"
|
||||
"add %%"REG_b", %%"REG_D" \n\t"
|
||||
"psubusb %%mm1, %%mm2 \n\t"
|
||||
"psubusb %%mm0, %%mm1 \n\t"
|
||||
"movq %%mm2, %%mm0 \n\t"
|
||||
"movq %%mm1, %%mm3 \n\t"
|
||||
"punpcklbw %%mm7, %%mm0 \n\t"
|
||||
"punpcklbw %%mm7, %%mm1 \n\t"
|
||||
"punpckhbw %%mm7, %%mm2 \n\t"
|
||||
"punpckhbw %%mm7, %%mm3 \n\t"
|
||||
"paddw %%mm0, %%mm4 \n\t"
|
||||
"paddw %%mm1, %%mm4 \n\t"
|
||||
"paddw %%mm2, %%mm4 \n\t"
|
||||
"paddw %%mm3, %%mm4 \n\t"
|
||||
|
||||
// Odd difference
|
||||
"movq (%%"REG_S"), %%mm0 \n\t"
|
||||
"movq (%%"REG_S"), %%mm2 \n\t"
|
||||
"add %%"REG_a", %%"REG_S" \n\t"
|
||||
"movq (%%"REG_D"), %%mm1 \n\t"
|
||||
"add %%"REG_b", %%"REG_D" \n\t"
|
||||
"psubusb %%mm1, %%mm2 \n\t"
|
||||
"psubusb %%mm0, %%mm1 \n\t"
|
||||
"movq %%mm2, %%mm0 \n\t"
|
||||
"movq %%mm1, %%mm3 \n\t"
|
||||
"punpcklbw %%mm7, %%mm0 \n\t"
|
||||
"punpcklbw %%mm7, %%mm1 \n\t"
|
||||
"punpckhbw %%mm7, %%mm2 \n\t"
|
||||
"punpckhbw %%mm7, %%mm3 \n\t"
|
||||
"paddw %%mm0, %%mm5 \n\t"
|
||||
"paddw %%mm1, %%mm5 \n\t"
|
||||
"paddw %%mm2, %%mm5 \n\t"
|
||||
"paddw %%mm3, %%mm5 \n\t"
|
||||
|
||||
"decl %%ecx \n\t"
|
||||
"jnz 1b \n\t"
|
||||
"movq %%mm4, (%%"REG_d") \n\t"
|
||||
"movq %%mm5, 8(%%"REG_d") \n\t"
|
||||
:
|
||||
: "S" (old), "D" (new), "a" (os), "b" (ns), "d" (out)
|
||||
: "memory"
|
||||
);
|
||||
m->e = out[0]+out[1]+out[2]+out[3];
|
||||
m->o = out[4]+out[5]+out[6]+out[7];
|
||||
m->d = m->e + m->o;
|
||||
|
||||
__asm__ (
|
||||
// First loop to measure first four columns
|
||||
"movl $4, %%ecx \n\t"
|
||||
"pxor %%mm4, %%mm4 \n\t" // Past spacial noise
|
||||
"pxor %%mm5, %%mm5 \n\t" // Temporal noise
|
||||
"pxor %%mm6, %%mm6 \n\t" // Current spacial noise
|
||||
|
||||
ASMALIGN(4)
|
||||
"2: \n\t"
|
||||
|
||||
"movq (%%"REG_S"), %%mm0 \n\t"
|
||||
"movq (%%"REG_S",%%"REG_a"), %%mm1 \n\t"
|
||||
"add %%"REG_a", %%"REG_S" \n\t"
|
||||
"add %%"REG_a", %%"REG_S" \n\t"
|
||||
"movq (%%"REG_D"), %%mm2 \n\t"
|
||||
"movq (%%"REG_D",%%"REG_b"), %%mm3 \n\t"
|
||||
"add %%"REG_b", %%"REG_D" \n\t"
|
||||
"add %%"REG_b", %%"REG_D" \n\t"
|
||||
"punpcklbw %%mm7, %%mm0 \n\t"
|
||||
"punpcklbw %%mm7, %%mm1 \n\t"
|
||||
"punpcklbw %%mm7, %%mm2 \n\t"
|
||||
"punpcklbw %%mm7, %%mm3 \n\t"
|
||||
"paddw %%mm1, %%mm4 \n\t"
|
||||
"paddw %%mm1, %%mm5 \n\t"
|
||||
"paddw %%mm3, %%mm6 \n\t"
|
||||
"psubw %%mm0, %%mm4 \n\t"
|
||||
"psubw %%mm2, %%mm5 \n\t"
|
||||
"psubw %%mm2, %%mm6 \n\t"
|
||||
|
||||
"decl %%ecx \n\t"
|
||||
"jnz 2b \n\t"
|
||||
|
||||
"movq %%mm0, %%mm1 \n\t"
|
||||
"movq %%mm0, %%mm2 \n\t"
|
||||
"movq %%mm0, %%mm3 \n\t"
|
||||
"pcmpgtw %%mm4, %%mm1 \n\t"
|
||||
"pcmpgtw %%mm5, %%mm2 \n\t"
|
||||
"pcmpgtw %%mm6, %%mm3 \n\t"
|
||||
"pxor %%mm1, %%mm4 \n\t"
|
||||
"pxor %%mm2, %%mm5 \n\t"
|
||||
"pxor %%mm3, %%mm6 \n\t"
|
||||
"psubw %%mm1, %%mm4 \n\t"
|
||||
"psubw %%mm2, %%mm5 \n\t"
|
||||
"psubw %%mm3, %%mm6 \n\t"
|
||||
"movq %%mm4, (%%"REG_d") \n\t"
|
||||
"movq %%mm5, 16(%%"REG_d") \n\t"
|
||||
"movq %%mm6, 32(%%"REG_d") \n\t"
|
||||
|
||||
"mov %%"REG_a", %%"REG_c" \n\t"
|
||||
"shl $3, %%"REG_c" \n\t"
|
||||
"sub %%"REG_c", %%"REG_S" \n\t"
|
||||
"mov %%"REG_b", %%"REG_c" \n\t"
|
||||
"shl $3, %%"REG_c" \n\t"
|
||||
"sub %%"REG_c", %%"REG_D" \n\t"
|
||||
|
||||
// Second loop for the last four columns
|
||||
"movl $4, %%ecx \n\t"
|
||||
"pxor %%mm4, %%mm4 \n\t"
|
||||
"pxor %%mm5, %%mm5 \n\t"
|
||||
"pxor %%mm6, %%mm6 \n\t"
|
||||
|
||||
ASMALIGN(4)
|
||||
"3: \n\t"
|
||||
|
||||
"movq (%%"REG_S"), %%mm0 \n\t"
|
||||
"movq (%%"REG_S",%%"REG_a"), %%mm1 \n\t"
|
||||
"add %%"REG_a", %%"REG_S" \n\t"
|
||||
"add %%"REG_a", %%"REG_S" \n\t"
|
||||
"movq (%%"REG_D"), %%mm2 \n\t"
|
||||
"movq (%%"REG_D",%%"REG_b"), %%mm3 \n\t"
|
||||
"add %%"REG_b", %%"REG_D" \n\t"
|
||||
"add %%"REG_b", %%"REG_D" \n\t"
|
||||
"punpckhbw %%mm7, %%mm0 \n\t"
|
||||
"punpckhbw %%mm7, %%mm1 \n\t"
|
||||
"punpckhbw %%mm7, %%mm2 \n\t"
|
||||
"punpckhbw %%mm7, %%mm3 \n\t"
|
||||
"paddw %%mm1, %%mm4 \n\t"
|
||||
"paddw %%mm1, %%mm5 \n\t"
|
||||
"paddw %%mm3, %%mm6 \n\t"
|
||||
"psubw %%mm0, %%mm4 \n\t"
|
||||
"psubw %%mm2, %%mm5 \n\t"
|
||||
"psubw %%mm2, %%mm6 \n\t"
|
||||
|
||||
"decl %%ecx \n\t"
|
||||
"jnz 3b \n\t"
|
||||
|
||||
"movq %%mm0, %%mm1 \n\t"
|
||||
"movq %%mm0, %%mm2 \n\t"
|
||||
"movq %%mm0, %%mm3 \n\t"
|
||||
"pcmpgtw %%mm4, %%mm1 \n\t"
|
||||
"pcmpgtw %%mm5, %%mm2 \n\t"
|
||||
"pcmpgtw %%mm6, %%mm3 \n\t"
|
||||
"pxor %%mm1, %%mm4 \n\t"
|
||||
"pxor %%mm2, %%mm5 \n\t"
|
||||
"pxor %%mm3, %%mm6 \n\t"
|
||||
"psubw %%mm1, %%mm4 \n\t"
|
||||
"psubw %%mm2, %%mm5 \n\t"
|
||||
"psubw %%mm3, %%mm6 \n\t"
|
||||
"movq %%mm4, 8(%%"REG_d") \n\t"
|
||||
"movq %%mm5, 24(%%"REG_d") \n\t"
|
||||
"movq %%mm6, 40(%%"REG_d") \n\t"
|
||||
|
||||
"emms \n\t"
|
||||
:
|
||||
: "S" (old), "D" (new), "a" ((long)os), "b" ((long)ns), "d" (out)
|
||||
: "memory"
|
||||
);
|
||||
m->p = m->t = m->s = 0;
|
||||
for (i=0; i<8; i++) {
|
||||
m->p += out[i];
|
||||
m->t += out[8+i];
|
||||
m->s += out[16+i];
|
||||
}
|
||||
//printf("e=%d o=%d d=%d p=%d t=%d s=%d\n", m->e, m->o, m->d, m->p, m->t, m->s);
|
||||
}
|
||||
#endif
|
||||
|
||||
//#define MAG(a) ((a)*(a))
|
||||
//#define MAG(a) (abs(a))
|
||||
#define MAG(a) (((a)^((a)>>31))-((a)>>31))
|
||||
|
||||
//#define LOWPASS(s) (((s)[-2] + 4*(s)[-1] + 6*(s)[0] + 4*(s)[1] + (s)[2])>>4)
|
||||
//#define LOWPASS(s) (((s)[-1] + 2*(s)[0] + (s)[1])>>2)
|
||||
#define LOWPASS(s) ((s)[0])
|
||||
|
||||
|
||||
static void block_diffs_C(struct metrics *m, unsigned char *old, unsigned char *new, int os, int ns)
|
||||
{
|
||||
int x, y, e=0, o=0, s=0, p=0, t=0;
|
||||
unsigned char *oldp, *newp;
|
||||
m->s = m->p = m->t = 0;
|
||||
for (x = 8; x; x--) {
|
||||
oldp = old++;
|
||||
newp = new++;
|
||||
s = p = t = 0;
|
||||
for (y = 4; y; y--) {
|
||||
e += MAG(newp[0]-oldp[0]);
|
||||
o += MAG(newp[ns]-oldp[os]);
|
||||
s += newp[ns]-newp[0];
|
||||
p += oldp[os]-oldp[0];
|
||||
t += oldp[os]-newp[0];
|
||||
oldp += os<<1;
|
||||
newp += ns<<1;
|
||||
}
|
||||
m->s += MAG(s);
|
||||
m->p += MAG(p);
|
||||
m->t += MAG(t);
|
||||
}
|
||||
m->e = e;
|
||||
m->o = o;
|
||||
m->d = e+o;
|
||||
}
|
||||
|
||||
static void (*block_diffs)(struct metrics *, unsigned char *, unsigned char *, int, int);
|
||||
|
||||
#define MAXUP(a,b) ((a) = ((a)>(b)) ? (a) : (b))
|
||||
|
||||
static void diff_planes(struct frameinfo *fi,
|
||||
unsigned char *old, unsigned char *new, int w, int h, int os, int ns)
|
||||
{
|
||||
int x, y;
|
||||
struct metrics l;
|
||||
struct metrics *peak=&fi->p, *rel=&fi->r, *mean=&fi->m;
|
||||
memset(peak, 0, sizeof(struct metrics));
|
||||
memset(rel, 0, sizeof(struct metrics));
|
||||
memset(mean, 0, sizeof(struct metrics));
|
||||
for (y = 0; y < h-7; y += 8) {
|
||||
for (x = 8; x < w-8-7; x += 8) {
|
||||
block_diffs(&l, old+x+y*os, new+x+y*ns, os, ns);
|
||||
mean->d += l.d;
|
||||
mean->e += l.e;
|
||||
mean->o += l.o;
|
||||
mean->s += l.s;
|
||||
mean->p += l.p;
|
||||
mean->t += l.t;
|
||||
MAXUP(peak->d, l.d);
|
||||
MAXUP(peak->e, l.e);
|
||||
MAXUP(peak->o, l.o);
|
||||
MAXUP(peak->s, l.s);
|
||||
MAXUP(peak->p, l.p);
|
||||
MAXUP(peak->t, l.t);
|
||||
MAXUP(rel->e, l.e-l.o);
|
||||
MAXUP(rel->o, l.o-l.e);
|
||||
MAXUP(rel->s, l.s-l.t);
|
||||
MAXUP(rel->p, l.p-l.t);
|
||||
MAXUP(rel->t, l.t-l.p);
|
||||
MAXUP(rel->d, l.t-l.s); /* hack */
|
||||
}
|
||||
}
|
||||
x = (w/8-2)*(h/8);
|
||||
mean->d /= x;
|
||||
mean->e /= x;
|
||||
mean->o /= x;
|
||||
mean->s /= x;
|
||||
mean->p /= x;
|
||||
mean->t /= x;
|
||||
}
|
||||
|
||||
static void diff_fields(struct frameinfo *fi, mp_image_t *old, mp_image_t *new)
|
||||
{
|
||||
diff_planes(fi, old->planes[0], new->planes[0],
|
||||
new->w, new->h, old->stride[0], new->stride[0]);
|
||||
}
|
||||
|
||||
static void stats(struct frameinfo *f)
|
||||
{
|
||||
ff_mp_msg(MSGT_VFILTER, MSGL_V, " pd=%d re=%d ro=%d rp=%d rt=%d rs=%d rd=%d pp=%d pt=%d ps=%d\r",
|
||||
f->p.d, f->r.e, f->r.o, f->r.p, f->r.t, f->r.s, f->r.d, f->p.p, f->p.t, f->p.s);
|
||||
}
|
||||
|
||||
static int foo(struct vf_priv_s *p, mp_image_t *new, mp_image_t *cur)
|
||||
{
|
||||
struct frameinfo *f = p->fi;
|
||||
|
||||
f[0] = f[1];
|
||||
diff_fields(&f[1], cur, new);
|
||||
stats(&f[1]);
|
||||
|
||||
// Immediately drop this frame if it's already been used.
|
||||
if (p->dropnext) {
|
||||
p->dropnext = 0;
|
||||
return F_DROP;
|
||||
}
|
||||
|
||||
// Sometimes a pulldown frame comes all by itself, so both
|
||||
// its top and bottom field are duplicates from the adjacent
|
||||
// two frames. We can just drop such a frame, but we
|
||||
// immediately show the next frame instead to keep the frame
|
||||
// drops evenly spaced during normal 3:2 pulldown sequences.
|
||||
if ((3*f[1].r.o < f[1].r.e) && (f[1].r.s < f[1].r.d)) {
|
||||
p->dropnext = 1;
|
||||
return F_NEXT;
|
||||
}
|
||||
|
||||
// If none of these conditions hold, we will consider the frame
|
||||
// progressive and just show it as-is.
|
||||
if (!( (3*f[0].r.e < f[0].r.o) ||
|
||||
((2*f[0].r.d < f[0].r.s) && (f[0].r.s > 1200)) ||
|
||||
((2*f[1].r.t < f[1].r.p) && (f[1].r.p > 1200)) ))
|
||||
return F_SHOW;
|
||||
|
||||
// Otherwise, we have to decide whether to merge or drop.
|
||||
// If the noise metric only increases minimally, we're off
|
||||
// to a good start...
|
||||
if (((2*f[1].r.t < 3*f[1].r.p) && (f[1].r.t < 3600)) ||
|
||||
(f[1].r.t < 900) || (f[1].r.d < 900)) {
|
||||
// ...and if noise decreases or the duplicate even field
|
||||
// is detected, we go ahead with the merge.
|
||||
if ((3*f[0].r.e < f[0].r.o) || (2*f[1].r.t < f[1].r.p)) {
|
||||
p->dropnext = 1;
|
||||
return F_MERGE;
|
||||
}
|
||||
}
|
||||
return F_DROP;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void copy_image(mp_image_t *dmpi, mp_image_t *mpi, int field)
|
||||
{
|
||||
switch (field) {
|
||||
case 0:
|
||||
my_memcpy_pic(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h/2,
|
||||
dmpi->stride[0]*2, mpi->stride[0]*2);
|
||||
if (mpi->flags & MP_IMGFLAG_PLANAR) {
|
||||
my_memcpy_pic(dmpi->planes[1], mpi->planes[1],
|
||||
mpi->chroma_width, mpi->chroma_height/2,
|
||||
dmpi->stride[1]*2, mpi->stride[1]*2);
|
||||
my_memcpy_pic(dmpi->planes[2], mpi->planes[2],
|
||||
mpi->chroma_width, mpi->chroma_height/2,
|
||||
dmpi->stride[2]*2, mpi->stride[2]*2);
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
my_memcpy_pic(dmpi->planes[0]+dmpi->stride[0],
|
||||
mpi->planes[0]+mpi->stride[0], mpi->w, mpi->h/2,
|
||||
dmpi->stride[0]*2, mpi->stride[0]*2);
|
||||
if (mpi->flags & MP_IMGFLAG_PLANAR) {
|
||||
my_memcpy_pic(dmpi->planes[1]+dmpi->stride[1],
|
||||
mpi->planes[1]+mpi->stride[1],
|
||||
mpi->chroma_width, mpi->chroma_height/2,
|
||||
dmpi->stride[1]*2, mpi->stride[1]*2);
|
||||
my_memcpy_pic(dmpi->planes[2]+dmpi->stride[2],
|
||||
mpi->planes[2]+mpi->stride[2],
|
||||
mpi->chroma_width, mpi->chroma_height/2,
|
||||
dmpi->stride[2]*2, mpi->stride[2]*2);
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
memcpy_pic(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h,
|
||||
dmpi->stride[0], mpi->stride[0]);
|
||||
if (mpi->flags & MP_IMGFLAG_PLANAR) {
|
||||
memcpy_pic(dmpi->planes[1], mpi->planes[1],
|
||||
mpi->chroma_width, mpi->chroma_height,
|
||||
dmpi->stride[1], mpi->stride[1]);
|
||||
memcpy_pic(dmpi->planes[2], mpi->planes[2],
|
||||
mpi->chroma_width, mpi->chroma_height,
|
||||
dmpi->stride[2], mpi->stride[2]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static int do_put_image(struct vf_instance *vf, mp_image_t *dmpi)
|
||||
{
|
||||
struct vf_priv_s *p = vf->priv;
|
||||
int dropflag=0;
|
||||
|
||||
if (!p->dropnext) switch (p->drop) {
|
||||
case 0:
|
||||
dropflag = 0;
|
||||
break;
|
||||
case 1:
|
||||
dropflag = (++p->lastdrop >= 5);
|
||||
break;
|
||||
case 2:
|
||||
dropflag = (++p->lastdrop >= 5) && (4*p->inframes <= 5*p->outframes);
|
||||
break;
|
||||
}
|
||||
|
||||
if (dropflag) {
|
||||
//ff_mp_msg(MSGT_VFILTER, MSGL_V, "drop! [%d/%d=%g]\n",
|
||||
// p->outframes, p->inframes, (float)p->outframes/p->inframes);
|
||||
ff_mp_msg(MSGT_VFILTER, MSGL_V, "!");
|
||||
p->lastdrop = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
p->outframes++;
|
||||
return ff_vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE);
|
||||
}
|
||||
|
||||
static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts)
|
||||
{
|
||||
int ret=0;
|
||||
struct vf_priv_s *p = vf->priv;
|
||||
|
||||
p->inframes++;
|
||||
|
||||
if (p->first) { /* hack */
|
||||
p->first = 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!p->dmpi) p->dmpi = ff_vf_get_image(vf->next, mpi->imgfmt,
|
||||
MP_IMGTYPE_STATIC, MP_IMGFLAG_ACCEPT_STRIDE |
|
||||
MP_IMGFLAG_PRESERVE | MP_IMGFLAG_READABLE,
|
||||
mpi->width, mpi->height);
|
||||
/* FIXME -- not correct, off by one frame! */
|
||||
p->dmpi->qscale = mpi->qscale;
|
||||
p->dmpi->qstride = mpi->qstride;
|
||||
p->dmpi->qscale_type = mpi->qscale_type;
|
||||
|
||||
switch (foo(p, mpi, p->dmpi)) {
|
||||
case F_DROP:
|
||||
copy_image(p->dmpi, mpi, 2);
|
||||
ret = 0;
|
||||
p->lastdrop = 0;
|
||||
ff_mp_msg(MSGT_VFILTER, MSGL_V, "DROP\n");
|
||||
break;
|
||||
case F_MERGE:
|
||||
copy_image(p->dmpi, mpi, 0);
|
||||
ret = do_put_image(vf, p->dmpi);
|
||||
copy_image(p->dmpi, mpi, 1);
|
||||
ff_mp_msg(MSGT_VFILTER, MSGL_V, "MERGE\n");
|
||||
p->dmpi = NULL;
|
||||
break;
|
||||
case F_NEXT:
|
||||
copy_image(p->dmpi, mpi, 2);
|
||||
ret = do_put_image(vf, p->dmpi);
|
||||
ff_mp_msg(MSGT_VFILTER, MSGL_V, "NEXT\n");
|
||||
p->dmpi = NULL;
|
||||
break;
|
||||
case F_SHOW:
|
||||
ret = do_put_image(vf, p->dmpi);
|
||||
copy_image(p->dmpi, mpi, 2);
|
||||
ff_mp_msg(MSGT_VFILTER, MSGL_V, "OK\n");
|
||||
p->dmpi = NULL;
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int query_format(struct vf_instance *vf, unsigned int fmt)
|
||||
{
|
||||
switch (fmt) {
|
||||
case IMGFMT_YV12:
|
||||
case IMGFMT_IYUV:
|
||||
case IMGFMT_I420:
|
||||
return ff_vf_next_query_format(vf, fmt);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void uninit(struct vf_instance *vf)
|
||||
{
|
||||
free(vf->priv);
|
||||
}
|
||||
|
||||
static int vf_open(vf_instance_t *vf, char *args)
|
||||
{
|
||||
struct vf_priv_s *p;
|
||||
vf->put_image = put_image;
|
||||
vf->query_format = query_format;
|
||||
vf->uninit = uninit;
|
||||
vf->default_reqs = VFCAP_ACCEPT_STRIDE;
|
||||
vf->priv = p = calloc(1, sizeof(struct vf_priv_s));
|
||||
p->drop = 0;
|
||||
p->first = 1;
|
||||
if (args) sscanf(args, "%d", &p->drop);
|
||||
block_diffs = block_diffs_C;
|
||||
#if HAVE_MMX && HAVE_EBX_AVAILABLE
|
||||
if(ff_gCpuCaps.hasMMX) block_diffs = block_diffs_MMX;
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
|
||||
const vf_info_t ff_vf_info_ivtc = {
|
||||
"inverse telecine, take 2",
|
||||
"ivtc",
|
||||
"Rich Felker",
|
||||
"",
|
||||
vf_open,
|
||||
NULL
|
||||
};
|
@ -30,7 +30,7 @@
|
||||
|
||||
#define LIBAVFILTER_VERSION_MAJOR 3
|
||||
#define LIBAVFILTER_VERSION_MINOR 56
|
||||
#define LIBAVFILTER_VERSION_MICRO 101
|
||||
#define LIBAVFILTER_VERSION_MICRO 102
|
||||
|
||||
#define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
|
||||
LIBAVFILTER_VERSION_MINOR, \
|
||||
|
@ -123,17 +123,13 @@ static const struct {
|
||||
{0, AV_PIX_FMT_NONE}
|
||||
};
|
||||
|
||||
extern const vf_info_t ff_vf_info_detc;
|
||||
extern const vf_info_t ff_vf_info_dint;
|
||||
extern const vf_info_t ff_vf_info_divtc;
|
||||
extern const vf_info_t ff_vf_info_down3dright;
|
||||
extern const vf_info_t ff_vf_info_eq2;
|
||||
extern const vf_info_t ff_vf_info_eq;
|
||||
extern const vf_info_t ff_vf_info_fil;
|
||||
//extern const vf_info_t ff_vf_info_filmdint;
|
||||
extern const vf_info_t ff_vf_info_fspp;
|
||||
extern const vf_info_t ff_vf_info_ilpack;
|
||||
extern const vf_info_t ff_vf_info_ivtc;
|
||||
extern const vf_info_t ff_vf_info_mcdeint;
|
||||
extern const vf_info_t ff_vf_info_ow;
|
||||
extern const vf_info_t ff_vf_info_perspective;
|
||||
@ -149,17 +145,13 @@ extern const vf_info_t ff_vf_info_uspp;
|
||||
|
||||
|
||||
static const vf_info_t* const filters[]={
|
||||
&ff_vf_info_detc,
|
||||
&ff_vf_info_dint,
|
||||
&ff_vf_info_divtc,
|
||||
&ff_vf_info_down3dright,
|
||||
&ff_vf_info_eq2,
|
||||
&ff_vf_info_eq,
|
||||
&ff_vf_info_fil,
|
||||
// &ff_vf_info_filmdint, cmmx.h vd.h ‘opt_screen_size_x’
|
||||
&ff_vf_info_fspp,
|
||||
&ff_vf_info_ilpack,
|
||||
&ff_vf_info_ivtc,
|
||||
&ff_vf_info_mcdeint,
|
||||
&ff_vf_info_ow,
|
||||
&ff_vf_info_perspective,
|
||||
|
Loading…
Reference in New Issue
Block a user