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. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <string.h>
  21. #include <limits.h>
  22. #include <math.h>
  23. #include "config.h"
  24. #include "mp_msg.h"
  25. #include "cpudetect.h"
  26. #include "libavutil/common.h"
  27. #include "mpbswap.h"
  28. #include "img_format.h"
  29. #include "mp_image.h"
  30. #include "vf.h"
  31. #include "libvo/fastmemcpy.h"
  32. const vf_info_t vf_info_divtc;
  33. struct vf_priv_s
  34. {
  35. int deghost, pass, phase, window, fcount, bcount, frameno, misscount,
  36. ocount, sum[5];
  37. double threshold;
  38. FILE *file;
  39. int8_t *bdata;
  40. unsigned int *csdata;
  41. int *history;
  42. };
  43. /*
  44. * diff_MMX and diff_C stolen from vf_decimate.c
  45. */
  46. #if HAVE_MMX && HAVE_EBX_AVAILABLE
  47. static int diff_MMX(unsigned char *old, unsigned char *new, int os, int ns)
  48. {
  49. volatile short out[4];
  50. __asm__ (
  51. "movl $8, %%ecx \n\t"
  52. "pxor %%mm4, %%mm4 \n\t"
  53. "pxor %%mm7, %%mm7 \n\t"
  54. ASMALIGN(4)
  55. "1: \n\t"
  56. "movq (%%"REG_S"), %%mm0 \n\t"
  57. "movq (%%"REG_S"), %%mm2 \n\t"
  58. "add %%"REG_a", %%"REG_S" \n\t"
  59. "movq (%%"REG_D"), %%mm1 \n\t"
  60. "add %%"REG_b", %%"REG_D" \n\t"
  61. "psubusb %%mm1, %%mm2 \n\t"
  62. "psubusb %%mm0, %%mm1 \n\t"
  63. "movq %%mm2, %%mm0 \n\t"
  64. "movq %%mm1, %%mm3 \n\t"
  65. "punpcklbw %%mm7, %%mm0 \n\t"
  66. "punpcklbw %%mm7, %%mm1 \n\t"
  67. "punpckhbw %%mm7, %%mm2 \n\t"
  68. "punpckhbw %%mm7, %%mm3 \n\t"
  69. "paddw %%mm0, %%mm4 \n\t"
  70. "paddw %%mm1, %%mm4 \n\t"
  71. "paddw %%mm2, %%mm4 \n\t"
  72. "paddw %%mm3, %%mm4 \n\t"
  73. "decl %%ecx \n\t"
  74. "jnz 1b \n\t"
  75. "movq %%mm4, (%%"REG_d") \n\t"
  76. "emms \n\t"
  77. :
  78. : "S" (old), "D" (new), "a" ((long)os), "b" ((long)ns), "d" (out)
  79. : "%ecx", "memory"
  80. );
  81. return out[0]+out[1]+out[2]+out[3];
  82. }
  83. #endif
  84. static int diff_C(unsigned char *old, unsigned char *new, int os, int ns)
  85. {
  86. int x, y, d=0;
  87. for(y=8; y; y--, new+=ns, old+=os)
  88. for(x=8; x; x--)
  89. d+=abs(new[x]-old[x]);
  90. return d;
  91. }
  92. static int (*diff)(unsigned char *, unsigned char *, int, int);
  93. static int diff_plane(unsigned char *old, unsigned char *new,
  94. int w, int h, int os, int ns, int arg)
  95. {
  96. int x, y, d, max=0, sum=0, n=0;
  97. for(y=0; y<h-7; y+=8)
  98. {
  99. for(x=0; x<w-7; x+=8)
  100. {
  101. d=diff(old+x+y*os, new+x+y*ns, os, ns);
  102. if(d>max) max=d;
  103. sum+=d;
  104. n++;
  105. }
  106. }
  107. return (sum+n*max)/2;
  108. }
  109. /*
  110. static unsigned int checksum_plane(unsigned char *p, unsigned char *z,
  111. int w, int h, int s, int zs, int arg)
  112. {
  113. unsigned int shift, sum;
  114. unsigned char *e;
  115. for(sum=0; h; h--, p+=s-w)
  116. for(e=p+w, shift=32; p<e;)
  117. sum^=(*p++)<<(shift=(shift-8)&31);
  118. return sum;
  119. }
  120. */
  121. static unsigned int checksum_plane(unsigned char *p, unsigned char *z,
  122. int w, int h, int s, int zs, int arg)
  123. {
  124. unsigned int shift;
  125. uint32_t sum, t;
  126. unsigned char *e, *e2;
  127. #if HAVE_FAST_64BIT
  128. typedef uint64_t wsum_t;
  129. #else
  130. typedef uint32_t wsum_t;
  131. #endif
  132. wsum_t wsum;
  133. for(sum=0; h; h--, p+=s-w)
  134. {
  135. for(shift=0, e=p+w; (int)p&(sizeof(wsum_t)-1) && p<e;)
  136. sum^=*p++<<(shift=(shift-8)&31);
  137. for(wsum=0, e2=e-sizeof(wsum_t)+1; p<e2; p+=sizeof(wsum_t))
  138. wsum^=*(wsum_t *)p;
  139. #if HAVE_FAST_64BIT
  140. t=be2me_32((uint32_t)(wsum>>32^wsum));
  141. #else
  142. t=be2me_32(wsum);
  143. #endif
  144. for(sum^=(t<<shift|t>>(32-shift)); p<e;)
  145. sum^=*p++<<(shift=(shift-8)&31);
  146. }
  147. return sum;
  148. }
  149. static int deghost_plane(unsigned char *d, unsigned char *s,
  150. int w, int h, int ds, int ss, int threshold)
  151. {
  152. int t;
  153. unsigned char *e;
  154. for(; h; h--, s+=ss-w, d+=ds-w)
  155. for(e=d+w; d<e; d++, s++)
  156. if(abs(*d-*s)>=threshold)
  157. *d=(t=(*d<<1)-*s)<0?0:t>255?255:t;
  158. return 0;
  159. }
  160. static int copyop(unsigned char *d, unsigned char *s, int bpl, int h, int dstride, int sstride, int dummy) {
  161. memcpy_pic(d, s, bpl, h, dstride, sstride);
  162. return 0;
  163. }
  164. static int imgop(int(*planeop)(unsigned char *, unsigned char *,
  165. int, int, int, int, int),
  166. mp_image_t *dst, mp_image_t *src, int arg)
  167. {
  168. if(dst->flags&MP_IMGFLAG_PLANAR)
  169. return planeop(dst->planes[0], src?src->planes[0]:0,
  170. dst->w, dst->h,
  171. dst->stride[0], src?src->stride[0]:0, arg)+
  172. planeop(dst->planes[1], src?src->planes[1]:0,
  173. dst->chroma_width, dst->chroma_height,
  174. dst->stride[1], src?src->stride[1]:0, arg)+
  175. planeop(dst->planes[2], src?src->planes[2]:0,
  176. dst->chroma_width, dst->chroma_height,
  177. dst->stride[2], src?src->stride[2]:0, arg);
  178. return planeop(dst->planes[0], src?src->planes[0]:0,
  179. dst->w*(dst->bpp/8), dst->h,
  180. dst->stride[0], src?src->stride[0]:0, arg);
  181. }
  182. /*
  183. * Find the phase in which the telecine pattern fits best to the
  184. * given 5 frame slice of frame difference measurements.
  185. *
  186. * If phase1 and phase2 are not negative, only the two specified
  187. * phases are tested.
  188. */
  189. static int match(struct vf_priv_s *p, int *diffs,
  190. int phase1, int phase2, double *strength)
  191. {
  192. static const int pattern1[]={ -4, 1, 1, 1, 1 },
  193. pattern2[]={ -2, -3, 4, 4, -3 }, *pattern;
  194. int f, m, n, t[5];
  195. pattern=p->deghost>0?pattern2:pattern1;
  196. for(f=0; f<5; f++)
  197. {
  198. if(phase1<0 || phase2<0 || f==phase1 || f==phase2)
  199. {
  200. for(n=t[f]=0; n<5; n++)
  201. t[f]+=diffs[n]*pattern[(n-f+5)%5];
  202. }
  203. else
  204. t[f]=INT_MIN;
  205. }
  206. /* find the best match */
  207. for(m=0, n=1; n<5; n++)
  208. if(t[n]>t[m]) m=n;
  209. if(strength)
  210. {
  211. /* the second best match */
  212. for(f=m?0:1, n=f+1; n<5; n++)
  213. if(n!=m && t[n]>t[f]) f=n;
  214. *strength=(t[m]>0?(double)(t[m]-t[f])/t[m]:0.0);
  215. }
  216. return m;
  217. }
  218. static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts)
  219. {
  220. mp_image_t *dmpi, *tmpi=0;
  221. int n, m, f, newphase;
  222. struct vf_priv_s *p=vf->priv;
  223. unsigned int checksum;
  224. double d;
  225. dmpi=vf_get_image(vf->next, mpi->imgfmt,
  226. MP_IMGTYPE_STATIC, MP_IMGFLAG_ACCEPT_STRIDE |
  227. MP_IMGFLAG_PRESERVE | MP_IMGFLAG_READABLE,
  228. mpi->width, mpi->height);
  229. vf_clone_mpi_attributes(dmpi, mpi);
  230. newphase=p->phase;
  231. switch(p->pass)
  232. {
  233. case 1:
  234. fprintf(p->file, "%08x %d\n",
  235. (unsigned int)imgop((void *)checksum_plane, mpi, 0, 0),
  236. p->frameno?imgop(diff_plane, dmpi, mpi, 0):0);
  237. break;
  238. case 2:
  239. if(p->frameno/5>p->bcount)
  240. {
  241. mp_msg(MSGT_VFILTER, MSGL_ERR,
  242. "\n%s: Log file ends prematurely! "
  243. "Switching to one pass mode.\n", vf->info->name);
  244. p->pass=0;
  245. break;
  246. }
  247. checksum=(unsigned int)imgop((void *)checksum_plane, mpi, 0, 0);
  248. if(checksum!=p->csdata[p->frameno])
  249. {
  250. for(f=0; f<100; f++)
  251. if(p->frameno+f<p->fcount && p->csdata[p->frameno+f]==checksum)
  252. break;
  253. else if(p->frameno-f>=0 && p->csdata[p->frameno-f]==checksum)
  254. {
  255. f=-f;
  256. break;
  257. }
  258. if(f<100)
  259. {
  260. mp_msg(MSGT_VFILTER, MSGL_INFO,
  261. "\n%s: Mismatch with pass-1: %+d frame(s).\n",
  262. vf->info->name, f);
  263. p->frameno+=f;
  264. p->misscount=0;
  265. }
  266. else if(p->misscount++>=30)
  267. {
  268. mp_msg(MSGT_VFILTER, MSGL_ERR,
  269. "\n%s: Sync with pass-1 lost! "
  270. "Switching to one pass mode.\n", vf->info->name);
  271. p->pass=0;
  272. break;
  273. }
  274. }
  275. n=(p->frameno)/5;
  276. if(n>=p->bcount) n=p->bcount-1;
  277. newphase=p->bdata[n];
  278. break;
  279. default:
  280. if(p->frameno)
  281. {
  282. int *sump=p->sum+p->frameno%5,
  283. *histp=p->history+p->frameno%p->window;
  284. *sump-=*histp;
  285. *sump+=(*histp=imgop(diff_plane, dmpi, mpi, 0));
  286. }
  287. m=match(p, p->sum, -1, -1, &d);
  288. if(d>=p->threshold)
  289. newphase=m;
  290. }
  291. n=p->ocount++%5;
  292. if(newphase!=p->phase && ((p->phase+4)%5<n)==((newphase+4)%5<n))
  293. {
  294. p->phase=newphase;
  295. mp_msg(MSGT_VFILTER, MSGL_STATUS,
  296. "\n%s: Telecine phase %d.\n", vf->info->name, p->phase);
  297. }
  298. switch((p->frameno++-p->phase+10)%5)
  299. {
  300. case 0:
  301. imgop(copyop, dmpi, mpi, 0);
  302. return 0;
  303. case 4:
  304. if(p->deghost>0)
  305. {
  306. tmpi=vf_get_image(vf->next, mpi->imgfmt,
  307. MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE |
  308. MP_IMGFLAG_READABLE,
  309. mpi->width, mpi->height);
  310. vf_clone_mpi_attributes(tmpi, mpi);
  311. imgop(copyop, tmpi, mpi, 0);
  312. imgop(deghost_plane, tmpi, dmpi, p->deghost);
  313. imgop(copyop, dmpi, mpi, 0);
  314. return vf_next_put_image(vf, tmpi, MP_NOPTS_VALUE);
  315. }
  316. }
  317. imgop(copyop, dmpi, mpi, 0);
  318. return vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE);
  319. }
  320. static int analyze(struct vf_priv_s *p)
  321. {
  322. int *buf=0, *bp, bufsize=0, n, b, f, i, j, m, s;
  323. unsigned int *cbuf=0, *cp;
  324. int8_t *pbuf;
  325. int8_t lbuf[256];
  326. int sum[5];
  327. double d;
  328. /* read the file */
  329. n=15;
  330. while(fgets(lbuf, 256, p->file))
  331. {
  332. if(n>=bufsize-19)
  333. {
  334. bufsize=bufsize?bufsize*2:30000;
  335. if((bp=realloc(buf, bufsize*sizeof *buf))) buf=bp;
  336. if((cp=realloc(cbuf, bufsize*sizeof *cbuf))) cbuf=cp;
  337. if(!bp || !cp)
  338. {
  339. mp_msg(MSGT_VFILTER, MSGL_FATAL, "%s: Not enough memory.\n",
  340. vf_info_divtc.name);
  341. free(buf);
  342. free(cbuf);
  343. return 0;
  344. }
  345. }
  346. sscanf(lbuf, "%x %d", cbuf+n, buf+n);
  347. n++;
  348. }
  349. if(!n)
  350. {
  351. mp_msg(MSGT_VFILTER, MSGL_FATAL, "%s: Empty 2-pass log file.\n",
  352. vf_info_divtc.name);
  353. free(buf);
  354. free(cbuf);
  355. return 0;
  356. }
  357. /* generate some dummy data past the beginning and end of the array */
  358. buf+=15, cbuf+=15;
  359. n-=15;
  360. memcpy(buf-15, buf, 15*sizeof *buf);
  361. memset(cbuf-15, 0, 15*sizeof *cbuf);
  362. while(n%5)
  363. buf[n]=buf[n-5], cbuf[n]=0, n++;
  364. memcpy(buf+n, buf+n-15, 15*sizeof *buf);
  365. memset(cbuf+n, 0, 15*sizeof *cbuf);
  366. p->csdata=cbuf;
  367. p->fcount=n;
  368. /* array with one slot for each slice of 5 frames */
  369. p->bdata=pbuf=malloc(p->bcount=b=(n/5));
  370. memset(pbuf, 255, b);
  371. /* resolve the automatic mode */
  372. if(p->deghost<0)
  373. {
  374. int deghost=-p->deghost;
  375. double s0=0.0, s1=0.0;
  376. for(f=0; f<n; f+=5)
  377. {
  378. p->deghost=0; match(p, buf+f, -1, -1, &d); s0+=d;
  379. p->deghost=1; match(p, buf+f, -1, -1, &d); s1+=d;
  380. }
  381. p->deghost=s1>s0?deghost:0;
  382. mp_msg(MSGT_VFILTER, MSGL_INFO,
  383. "%s: Deghosting %-3s (relative pattern strength %+.2fdB).\n",
  384. vf_info_divtc.name,
  385. p->deghost?"ON":"OFF",
  386. 10.0*log10(s1/s0));
  387. }
  388. /* analyze the data */
  389. for(f=0; f<5; f++)
  390. for(sum[f]=0, n=-15; n<20; n+=5)
  391. sum[f]+=buf[n+f];
  392. for(f=0; f<b; f++)
  393. {
  394. m=match(p, sum, -1, -1, &d);
  395. if(d>=p->threshold)
  396. pbuf[f]=m;
  397. if(f<b-1)
  398. for(n=0; n<5; n++)
  399. sum[n]=sum[n]-buf[5*(f-3)+n]+buf[5*(f+4)+n];
  400. }
  401. /* fill in the gaps */
  402. /* the beginning */
  403. for(f=0; f<b && pbuf[f]==-1; f++);
  404. if(f==b)
  405. {
  406. free(buf-15);
  407. mp_msg(MSGT_VFILTER, MSGL_FATAL, "%s: No telecine pattern found!\n",
  408. vf_info_divtc.name);
  409. return 0;
  410. }
  411. for(n=0; n<f; pbuf[n++]=pbuf[f]);
  412. /* the end */
  413. for(f=b-1; pbuf[f]==-1; f--);
  414. for(n=f+1; n<b; pbuf[n++]=pbuf[f]);
  415. /* the rest */
  416. for(f=0;;)
  417. {
  418. while(f<b && pbuf[f]!=-1) f++;
  419. if(f==b) break;
  420. for(n=f; pbuf[n]==-1; n++);
  421. if(pbuf[f-1]==pbuf[n])
  422. {
  423. /* just a gap */
  424. while(f<n) pbuf[f++]=pbuf[n];
  425. }
  426. else
  427. {
  428. /* phase change, reanalyze the original data in the gap with zero
  429. threshold for only the two phases that appear at the ends */
  430. for(i=0; i<5; i++)
  431. for(sum[i]=0, j=5*f-15; j<5*f; j+=5)
  432. sum[i]+=buf[i+j];
  433. for(i=f; i<n; i++)
  434. {
  435. pbuf[i]=match(p, sum, pbuf[f-1], pbuf[n], 0);
  436. for(j=0; j<5; j++)
  437. sum[j]=sum[j]-buf[5*(i-3)+j]+buf[5*(i+4)+j];
  438. }
  439. /* estimate the transition point by dividing the gap
  440. in the same proportion as the number of matches of each kind */
  441. for(i=f, m=f; i<n; i++)
  442. if(pbuf[i]==pbuf[f-1]) m++;
  443. /* find the transition of the right direction nearest to the
  444. estimated point */
  445. if(m>f && m<n)
  446. {
  447. for(j=m; j>f; j--)
  448. if(pbuf[j-1]==pbuf[f-1] && pbuf[j]==pbuf[n]) break;
  449. for(s=m; s<n; s++)
  450. if(pbuf[s-1]==pbuf[f-1] && pbuf[s]==pbuf[n]) break;
  451. m=(s-m<m-j)?s:j;
  452. }
  453. /* and rewrite the data to allow only this one transition */
  454. for(i=f; i<m; i++)
  455. pbuf[i]=pbuf[f-1];
  456. for(; i<n; i++)
  457. pbuf[i]=pbuf[n];
  458. f=n;
  459. }
  460. }
  461. free(buf-15);
  462. return 1;
  463. }
  464. static int query_format(struct vf_instance *vf, unsigned int fmt)
  465. {
  466. switch(fmt)
  467. {
  468. case IMGFMT_444P: case IMGFMT_IYUV: case IMGFMT_RGB24:
  469. case IMGFMT_422P: case IMGFMT_UYVY: case IMGFMT_BGR24:
  470. case IMGFMT_411P: case IMGFMT_YUY2: case IMGFMT_IF09:
  471. case IMGFMT_YV12: case IMGFMT_I420: case IMGFMT_YVU9:
  472. case IMGFMT_IUYV: case IMGFMT_Y800: case IMGFMT_Y8:
  473. return vf_next_query_format(vf,fmt);
  474. }
  475. return 0;
  476. }
  477. static void uninit(struct vf_instance *vf)
  478. {
  479. if(vf->priv)
  480. {
  481. if(vf->priv->file) fclose(vf->priv->file);
  482. if(vf->priv->csdata) free(vf->priv->csdata-15);
  483. free(vf->priv->bdata);
  484. free(vf->priv->history);
  485. free(vf->priv);
  486. }
  487. }
  488. static int vf_open(vf_instance_t *vf, char *args)
  489. {
  490. struct vf_priv_s *p;
  491. const char *filename="framediff.log";
  492. char *ap, *q, *a;
  493. if(args && !(args=av_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. };