vf_divtc.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721
  1. /*
  2. * This file is part of MPlayer.
  3. *
  4. * MPlayer is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * MPlayer is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along
  15. * with MPlayer; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  17. */
  18. #define _BSD_SOURCE //strdup
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #include <string.h>
  22. #include <limits.h>
  23. #include <math.h>
  24. #include "config.h"
  25. #include "mp_msg.h"
  26. #include "cpudetect.h"
  27. #include "libavutil/common.h"
  28. #include "mpbswap.h"
  29. #include "img_format.h"
  30. #include "mp_image.h"
  31. #include "vf.h"
  32. #include "libvo/fastmemcpy.h"
  33. const vf_info_t vf_info_divtc;
  34. struct vf_priv_s
  35. {
  36. int deghost, pass, phase, window, fcount, bcount, frameno, misscount,
  37. ocount, sum[5];
  38. double threshold;
  39. FILE *file;
  40. char *bdata;
  41. unsigned int *csdata;
  42. int *history;
  43. };
  44. /*
  45. * diff_MMX and diff_C stolen from vf_decimate.c
  46. */
  47. #if HAVE_MMX && HAVE_EBX_AVAILABLE
  48. static int diff_MMX(unsigned char *old, unsigned char *new, int os, int ns)
  49. {
  50. volatile short out[4];
  51. __asm__ (
  52. "movl $8, %%ecx \n\t"
  53. "pxor %%mm4, %%mm4 \n\t"
  54. "pxor %%mm7, %%mm7 \n\t"
  55. ASMALIGN(4)
  56. "1: \n\t"
  57. "movq (%%"REG_S"), %%mm0 \n\t"
  58. "movq (%%"REG_S"), %%mm2 \n\t"
  59. "add %%"REG_a", %%"REG_S" \n\t"
  60. "movq (%%"REG_D"), %%mm1 \n\t"
  61. "add %%"REG_b", %%"REG_D" \n\t"
  62. "psubusb %%mm1, %%mm2 \n\t"
  63. "psubusb %%mm0, %%mm1 \n\t"
  64. "movq %%mm2, %%mm0 \n\t"
  65. "movq %%mm1, %%mm3 \n\t"
  66. "punpcklbw %%mm7, %%mm0 \n\t"
  67. "punpcklbw %%mm7, %%mm1 \n\t"
  68. "punpckhbw %%mm7, %%mm2 \n\t"
  69. "punpckhbw %%mm7, %%mm3 \n\t"
  70. "paddw %%mm0, %%mm4 \n\t"
  71. "paddw %%mm1, %%mm4 \n\t"
  72. "paddw %%mm2, %%mm4 \n\t"
  73. "paddw %%mm3, %%mm4 \n\t"
  74. "decl %%ecx \n\t"
  75. "jnz 1b \n\t"
  76. "movq %%mm4, (%%"REG_d") \n\t"
  77. "emms \n\t"
  78. :
  79. : "S" (old), "D" (new), "a" ((long)os), "b" ((long)ns), "d" (out)
  80. : "%ecx", "memory"
  81. );
  82. return out[0]+out[1]+out[2]+out[3];
  83. }
  84. #endif
  85. static int diff_C(unsigned char *old, unsigned char *new, int os, int ns)
  86. {
  87. int x, y, d=0;
  88. for(y=8; y; y--, new+=ns, old+=os)
  89. for(x=8; x; x--)
  90. d+=abs(new[x]-old[x]);
  91. return d;
  92. }
  93. static int (*diff)(unsigned char *, unsigned char *, int, int);
  94. static int diff_plane(unsigned char *old, unsigned char *new,
  95. int w, int h, int os, int ns, int arg)
  96. {
  97. int x, y, d, max=0, sum=0, n=0;
  98. for(y=0; y<h-7; y+=8)
  99. {
  100. for(x=0; x<w-7; x+=8)
  101. {
  102. d=diff(old+x+y*os, new+x+y*ns, os, ns);
  103. if(d>max) max=d;
  104. sum+=d;
  105. n++;
  106. }
  107. }
  108. return (sum+n*max)/2;
  109. }
  110. /*
  111. static unsigned int checksum_plane(unsigned char *p, unsigned char *z,
  112. int w, int h, int s, int zs, int arg)
  113. {
  114. unsigned int shift, sum;
  115. unsigned char *e;
  116. for(sum=0; h; h--, p+=s-w)
  117. for(e=p+w, shift=32; p<e;)
  118. sum^=(*p++)<<(shift=(shift-8)&31);
  119. return sum;
  120. }
  121. */
  122. static unsigned int checksum_plane(unsigned char *p, unsigned char *z,
  123. int w, int h, int s, int zs, int arg)
  124. {
  125. unsigned int shift;
  126. uint32_t sum, t;
  127. unsigned char *e, *e2;
  128. #if HAVE_FAST_64BIT
  129. typedef uint64_t wsum_t;
  130. #else
  131. typedef uint32_t wsum_t;
  132. #endif
  133. wsum_t wsum;
  134. for(sum=0; h; h--, p+=s-w)
  135. {
  136. for(shift=0, e=p+w; (int)p&(sizeof(wsum_t)-1) && p<e;)
  137. sum^=*p++<<(shift=(shift-8)&31);
  138. for(wsum=0, e2=e-sizeof(wsum_t)+1; p<e2; p+=sizeof(wsum_t))
  139. wsum^=*(wsum_t *)p;
  140. #if HAVE_FAST_64BIT
  141. t=be2me_32((uint32_t)(wsum>>32^wsum));
  142. #else
  143. t=be2me_32(wsum);
  144. #endif
  145. for(sum^=(t<<shift|t>>(32-shift)); p<e;)
  146. sum^=*p++<<(shift=(shift-8)&31);
  147. }
  148. return sum;
  149. }
  150. static int deghost_plane(unsigned char *d, unsigned char *s,
  151. int w, int h, int ds, int ss, int threshold)
  152. {
  153. int t;
  154. unsigned char *e;
  155. for(; h; h--, s+=ss-w, d+=ds-w)
  156. for(e=d+w; d<e; d++, s++)
  157. if(abs(*d-*s)>=threshold)
  158. *d=(t=(*d<<1)-*s)<0?0:t>255?255:t;
  159. return 0;
  160. }
  161. static int copyop(unsigned char *d, unsigned char *s, int bpl, int h, int dstride, int sstride, int dummy) {
  162. memcpy_pic(d, s, bpl, h, dstride, sstride);
  163. return 0;
  164. }
  165. static int imgop(int(*planeop)(unsigned char *, unsigned char *,
  166. int, int, int, int, int),
  167. mp_image_t *dst, mp_image_t *src, int arg)
  168. {
  169. if(dst->flags&MP_IMGFLAG_PLANAR)
  170. return planeop(dst->planes[0], src?src->planes[0]:0,
  171. dst->w, dst->h,
  172. dst->stride[0], src?src->stride[0]:0, arg)+
  173. planeop(dst->planes[1], src?src->planes[1]:0,
  174. dst->chroma_width, dst->chroma_height,
  175. dst->stride[1], src?src->stride[1]:0, arg)+
  176. planeop(dst->planes[2], src?src->planes[2]:0,
  177. dst->chroma_width, dst->chroma_height,
  178. dst->stride[2], src?src->stride[2]:0, arg);
  179. return planeop(dst->planes[0], src?src->planes[0]:0,
  180. dst->w*(dst->bpp/8), dst->h,
  181. dst->stride[0], src?src->stride[0]:0, arg);
  182. }
  183. /*
  184. * Find the phase in which the telecine pattern fits best to the
  185. * given 5 frame slice of frame difference measurements.
  186. *
  187. * If phase1 and phase2 are not negative, only the two specified
  188. * phases are tested.
  189. */
  190. static int match(struct vf_priv_s *p, int *diffs,
  191. int phase1, int phase2, double *strength)
  192. {
  193. static const int pattern1[]={ -4, 1, 1, 1, 1 },
  194. pattern2[]={ -2, -3, 4, 4, -3 }, *pattern;
  195. int f, m, n, t[5];
  196. pattern=p->deghost>0?pattern2:pattern1;
  197. for(f=0; f<5; f++)
  198. {
  199. if(phase1<0 || phase2<0 || f==phase1 || f==phase2)
  200. {
  201. for(n=t[f]=0; n<5; n++)
  202. t[f]+=diffs[n]*pattern[(n-f+5)%5];
  203. }
  204. else
  205. t[f]=INT_MIN;
  206. }
  207. /* find the best match */
  208. for(m=0, n=1; n<5; n++)
  209. if(t[n]>t[m]) m=n;
  210. if(strength)
  211. {
  212. /* the second best match */
  213. for(f=m?0:1, n=f+1; n<5; n++)
  214. if(n!=m && t[n]>t[f]) f=n;
  215. *strength=(t[m]>0?(double)(t[m]-t[f])/t[m]:0.0);
  216. }
  217. return m;
  218. }
  219. static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts)
  220. {
  221. mp_image_t *dmpi, *tmpi=0;
  222. int n, m, f, newphase;
  223. struct vf_priv_s *p=vf->priv;
  224. unsigned int checksum;
  225. double d;
  226. dmpi=vf_get_image(vf->next, mpi->imgfmt,
  227. MP_IMGTYPE_STATIC, MP_IMGFLAG_ACCEPT_STRIDE |
  228. MP_IMGFLAG_PRESERVE | MP_IMGFLAG_READABLE,
  229. mpi->width, mpi->height);
  230. vf_clone_mpi_attributes(dmpi, mpi);
  231. newphase=p->phase;
  232. switch(p->pass)
  233. {
  234. case 1:
  235. fprintf(p->file, "%08x %d\n",
  236. (unsigned int)imgop((void *)checksum_plane, mpi, 0, 0),
  237. p->frameno?imgop(diff_plane, dmpi, mpi, 0):0);
  238. break;
  239. case 2:
  240. if(p->frameno/5>p->bcount)
  241. {
  242. mp_msg(MSGT_VFILTER, MSGL_ERR,
  243. "\n%s: Log file ends prematurely! "
  244. "Switching to one pass mode.\n", vf->info->name);
  245. p->pass=0;
  246. break;
  247. }
  248. checksum=(unsigned int)imgop((void *)checksum_plane, mpi, 0, 0);
  249. if(checksum!=p->csdata[p->frameno])
  250. {
  251. for(f=0; f<100; f++)
  252. if(p->frameno+f<p->fcount && p->csdata[p->frameno+f]==checksum)
  253. break;
  254. else if(p->frameno-f>=0 && p->csdata[p->frameno-f]==checksum)
  255. {
  256. f=-f;
  257. break;
  258. }
  259. if(f<100)
  260. {
  261. mp_msg(MSGT_VFILTER, MSGL_INFO,
  262. "\n%s: Mismatch with pass-1: %+d frame(s).\n",
  263. vf->info->name, f);
  264. p->frameno+=f;
  265. p->misscount=0;
  266. }
  267. else if(p->misscount++>=30)
  268. {
  269. mp_msg(MSGT_VFILTER, MSGL_ERR,
  270. "\n%s: Sync with pass-1 lost! "
  271. "Switching to one pass mode.\n", vf->info->name);
  272. p->pass=0;
  273. break;
  274. }
  275. }
  276. n=(p->frameno)/5;
  277. if(n>=p->bcount) n=p->bcount-1;
  278. newphase=p->bdata[n];
  279. break;
  280. default:
  281. if(p->frameno)
  282. {
  283. int *sump=p->sum+p->frameno%5,
  284. *histp=p->history+p->frameno%p->window;
  285. *sump-=*histp;
  286. *sump+=(*histp=imgop(diff_plane, dmpi, mpi, 0));
  287. }
  288. m=match(p, p->sum, -1, -1, &d);
  289. if(d>=p->threshold)
  290. newphase=m;
  291. }
  292. n=p->ocount++%5;
  293. if(newphase!=p->phase && ((p->phase+4)%5<n)==((newphase+4)%5<n))
  294. {
  295. p->phase=newphase;
  296. mp_msg(MSGT_VFILTER, MSGL_STATUS,
  297. "\n%s: Telecine phase %d.\n", vf->info->name, p->phase);
  298. }
  299. switch((p->frameno++-p->phase+10)%5)
  300. {
  301. case 0:
  302. imgop(copyop, dmpi, mpi, 0);
  303. return 0;
  304. case 4:
  305. if(p->deghost>0)
  306. {
  307. tmpi=vf_get_image(vf->next, mpi->imgfmt,
  308. MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE |
  309. MP_IMGFLAG_READABLE,
  310. mpi->width, mpi->height);
  311. vf_clone_mpi_attributes(tmpi, mpi);
  312. imgop(copyop, tmpi, mpi, 0);
  313. imgop(deghost_plane, tmpi, dmpi, p->deghost);
  314. imgop(copyop, dmpi, mpi, 0);
  315. return vf_next_put_image(vf, tmpi, MP_NOPTS_VALUE);
  316. }
  317. }
  318. imgop(copyop, dmpi, mpi, 0);
  319. return vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE);
  320. }
  321. static int analyze(struct vf_priv_s *p)
  322. {
  323. int *buf=0, *bp, bufsize=0, n, b, f, i, j, m, s;
  324. unsigned int *cbuf=0, *cp;
  325. char *pbuf;
  326. char lbuf[256];
  327. int sum[5];
  328. double d;
  329. /* read the file */
  330. n=15;
  331. while(fgets(lbuf, 256, p->file))
  332. {
  333. if(n>=bufsize-19)
  334. {
  335. bufsize=bufsize?bufsize*2:30000;
  336. if((bp=realloc(buf, bufsize*sizeof *buf))) buf=bp;
  337. if((cp=realloc(cbuf, bufsize*sizeof *cbuf))) cbuf=cp;
  338. if(!bp || !cp)
  339. {
  340. mp_msg(MSGT_VFILTER, MSGL_FATAL, "%s: Not enough memory.\n",
  341. vf_info_divtc.name);
  342. free(buf);
  343. free(cbuf);
  344. return 0;
  345. }
  346. }
  347. sscanf(lbuf, "%x %d", cbuf+n, buf+n);
  348. n++;
  349. }
  350. if(!n)
  351. {
  352. mp_msg(MSGT_VFILTER, MSGL_FATAL, "%s: Empty 2-pass log file.\n",
  353. vf_info_divtc.name);
  354. free(buf);
  355. free(cbuf);
  356. return 0;
  357. }
  358. /* generate some dummy data past the beginning and end of the array */
  359. buf+=15, cbuf+=15;
  360. n-=15;
  361. memcpy(buf-15, buf, 15*sizeof *buf);
  362. memset(cbuf-15, 0, 15*sizeof *cbuf);
  363. while(n%5)
  364. buf[n]=buf[n-5], cbuf[n]=0, n++;
  365. memcpy(buf+n, buf+n-15, 15*sizeof *buf);
  366. memset(cbuf+n, 0, 15*sizeof *cbuf);
  367. p->csdata=cbuf;
  368. p->fcount=n;
  369. /* array with one slot for each slice of 5 frames */
  370. p->bdata=pbuf=malloc(p->bcount=b=(n/5));
  371. memset(pbuf, 255, b);
  372. /* resolve the automatic mode */
  373. if(p->deghost<0)
  374. {
  375. int deghost=-p->deghost;
  376. double s0=0.0, s1=0.0;
  377. for(f=0; f<n; f+=5)
  378. {
  379. p->deghost=0; match(p, buf+f, -1, -1, &d); s0+=d;
  380. p->deghost=1; match(p, buf+f, -1, -1, &d); s1+=d;
  381. }
  382. p->deghost=s1>s0?deghost:0;
  383. mp_msg(MSGT_VFILTER, MSGL_INFO,
  384. "%s: Deghosting %-3s (relative pattern strength %+.2fdB).\n",
  385. vf_info_divtc.name,
  386. p->deghost?"ON":"OFF",
  387. 10.0*log10(s1/s0));
  388. }
  389. /* analyze the data */
  390. for(f=0; f<5; f++)
  391. for(sum[f]=0, n=-15; n<20; n+=5)
  392. sum[f]+=buf[n+f];
  393. for(f=0; f<b; f++)
  394. {
  395. m=match(p, sum, -1, -1, &d);
  396. if(d>=p->threshold)
  397. pbuf[f]=m;
  398. if(f<b-1)
  399. for(n=0; n<5; n++)
  400. sum[n]=sum[n]-buf[5*(f-3)+n]+buf[5*(f+4)+n];
  401. }
  402. /* fill in the gaps */
  403. /* the beginning */
  404. for(f=0; f<b && pbuf[f]==-1; f++);
  405. if(f==b)
  406. {
  407. free(buf-15);
  408. mp_msg(MSGT_VFILTER, MSGL_FATAL, "%s: No telecine pattern found!\n",
  409. vf_info_divtc.name);
  410. return 0;
  411. }
  412. for(n=0; n<f; pbuf[n++]=pbuf[f]);
  413. /* the end */
  414. for(f=b-1; pbuf[f]==-1; f--);
  415. for(n=f+1; n<b; pbuf[n++]=pbuf[f]);
  416. /* the rest */
  417. for(f=0;;)
  418. {
  419. while(f<b && pbuf[f]!=-1) f++;
  420. if(f==b) break;
  421. for(n=f; pbuf[n]==-1; n++);
  422. if(pbuf[f-1]==pbuf[n])
  423. {
  424. /* just a gap */
  425. while(f<n) pbuf[f++]=pbuf[n];
  426. }
  427. else
  428. {
  429. /* phase change, reanalyze the original data in the gap with zero
  430. threshold for only the two phases that appear at the ends */
  431. for(i=0; i<5; i++)
  432. for(sum[i]=0, j=5*f-15; j<5*f; j+=5)
  433. sum[i]+=buf[i+j];
  434. for(i=f; i<n; i++)
  435. {
  436. pbuf[i]=match(p, sum, pbuf[f-1], pbuf[n], 0);
  437. for(j=0; j<5; j++)
  438. sum[j]=sum[j]-buf[5*(i-3)+j]+buf[5*(i+4)+j];
  439. }
  440. /* estimate the transition point by dividing the gap
  441. in the same proportion as the number of matches of each kind */
  442. for(i=f, m=f; i<n; i++)
  443. if(pbuf[i]==pbuf[f-1]) m++;
  444. /* find the transition of the right direction nearest to the
  445. estimated point */
  446. if(m>f && m<n)
  447. {
  448. for(j=m; j>f; j--)
  449. if(pbuf[j-1]==pbuf[f-1] && pbuf[j]==pbuf[n]) break;
  450. for(s=m; s<n; s++)
  451. if(pbuf[s-1]==pbuf[f-1] && pbuf[s]==pbuf[n]) break;
  452. m=(s-m<m-j)?s:j;
  453. }
  454. /* and rewrite the data to allow only this one transition */
  455. for(i=f; i<m; i++)
  456. pbuf[i]=pbuf[f-1];
  457. for(; i<n; i++)
  458. pbuf[i]=pbuf[n];
  459. f=n;
  460. }
  461. }
  462. free(buf-15);
  463. return 1;
  464. }
  465. static int query_format(struct vf_instance *vf, unsigned int fmt)
  466. {
  467. switch(fmt)
  468. {
  469. case IMGFMT_444P: case IMGFMT_IYUV: case IMGFMT_RGB24:
  470. case IMGFMT_422P: case IMGFMT_UYVY: case IMGFMT_BGR24:
  471. case IMGFMT_411P: case IMGFMT_YUY2: case IMGFMT_IF09:
  472. case IMGFMT_YV12: case IMGFMT_I420: case IMGFMT_YVU9:
  473. case IMGFMT_IUYV: case IMGFMT_Y800: case IMGFMT_Y8:
  474. return vf_next_query_format(vf,fmt);
  475. }
  476. return 0;
  477. }
  478. static void uninit(struct vf_instance *vf)
  479. {
  480. if(vf->priv)
  481. {
  482. if(vf->priv->file) fclose(vf->priv->file);
  483. if(vf->priv->csdata) free(vf->priv->csdata-15);
  484. free(vf->priv->bdata);
  485. free(vf->priv->history);
  486. free(vf->priv);
  487. }
  488. }
  489. static int vf_open(vf_instance_t *vf, char *args)
  490. {
  491. struct vf_priv_s *p;
  492. char *filename="framediff.log", *ap, *q, *a;
  493. if(args && !(args=strdup(args)))
  494. {
  495. nomem:
  496. mp_msg(MSGT_VFILTER, MSGL_FATAL,
  497. "%s: Not enough memory.\n", vf->info->name);
  498. fail:
  499. uninit(vf);
  500. free(args);
  501. return 0;
  502. }
  503. vf->put_image=put_image;
  504. vf->uninit=uninit;
  505. vf->query_format=query_format;
  506. vf->default_reqs=VFCAP_ACCEPT_STRIDE;
  507. if(!(vf->priv=p=calloc(1, sizeof(struct vf_priv_s))))
  508. goto nomem;
  509. p->phase=5;
  510. p->threshold=0.5;
  511. p->window=30;
  512. if((ap=args))
  513. while(*ap)
  514. {
  515. q=ap;
  516. if((ap=strchr(q, ':'))) *ap++=0; else ap=q+strlen(q);
  517. if((a=strchr(q, '='))) *a++=0; else a=q+strlen(q);
  518. switch(*q)
  519. {
  520. case 0: break;
  521. case 'f': filename=a; break;
  522. case 't': p->threshold=atof(a); break;
  523. case 'w': p->window=5*(atoi(a)+4)/5; break;
  524. case 'd': p->deghost=atoi(a); break;
  525. case 'p':
  526. if(q[1]=='h') p->phase=atoi(a);
  527. else p->pass=atoi(a);
  528. break;
  529. case 'h':
  530. mp_msg(MSGT_VFILTER, MSGL_INFO,
  531. "\n%s options:\n\n"
  532. "pass=1|2 - Use 2-pass mode.\n"
  533. "file=filename - Set the 2-pass log file name "
  534. "(default %s).\n"
  535. "threshold=value - Set the pattern recognition "
  536. "sensitivity (default %g).\n"
  537. "deghost=value - Select deghosting threshold "
  538. "(default %d).\n"
  539. "window=numframes - Set the statistics window "
  540. "for 1-pass mode (default %d).\n"
  541. "phase=0|1|2|3|4 - Set the initial phase "
  542. "for 1-pass mode (default %d).\n\n"
  543. "The option names can be abbreviated to the shortest "
  544. "unique prefix.\n\n",
  545. vf->info->name, filename, p->threshold, p->deghost,
  546. p->window, p->phase%5);
  547. break;
  548. default:
  549. mp_msg(MSGT_VFILTER, MSGL_FATAL,
  550. "%s: Unknown argument %s.\n", vf->info->name, q);
  551. goto fail;
  552. }
  553. }
  554. switch(p->pass)
  555. {
  556. case 1:
  557. if(!(p->file=fopen(filename, "w")))
  558. {
  559. mp_msg(MSGT_VFILTER, MSGL_FATAL,
  560. "%s: Can't create file %s.\n", vf->info->name, filename);
  561. goto fail;
  562. }
  563. break;
  564. case 2:
  565. if(!(p->file=fopen(filename, "r")))
  566. {
  567. mp_msg(MSGT_VFILTER, MSGL_FATAL,
  568. "%s: Can't open file %s.\n", vf->info->name, filename);
  569. goto fail;
  570. }
  571. if(!analyze(p))
  572. goto fail;
  573. fclose(p->file);
  574. p->file=0;
  575. break;
  576. }
  577. if(p->window<5) p->window=5;
  578. if(!(p->history=calloc(sizeof *p->history, p->window)))
  579. goto nomem;
  580. diff = diff_C;
  581. #if HAVE_MMX && HAVE_EBX_AVAILABLE
  582. if(gCpuCaps.hasMMX) diff = diff_MMX;
  583. #endif
  584. free(args);
  585. return 1;
  586. }
  587. const vf_info_t vf_info_divtc =
  588. {
  589. "inverse telecine for deinterlaced video",
  590. "divtc",
  591. "Ville Saari",
  592. "",
  593. vf_open,
  594. NULL
  595. };