annotate libmpcodecs/vf_mcdeint.c @ 18592:500f57bf5c6f

known issues and notes
author michael
date Tue, 06 Jun 2006 10:34:45 +0000
parents 2fa15de8806b
children c921020fd8bd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18590
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
1 /*
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
2 Copyright (C) 2006 Michael Niedermayer <michaelni@gmx.at>
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
3
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
4 This program is free software; you can redistribute it and/or modify
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
6 the Free Software Foundation; either version 2 of the License, or
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
7 (at your option) any later version.
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
8
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
12 GNU General Public License for more details.
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
13
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
15 along with this program; if not, write to the Free Software
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
17 */
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
18
18592
500f57bf5c6f known issues and notes
michael
parents: 18590
diff changeset
19
500f57bf5c6f known issues and notes
michael
parents: 18590
diff changeset
20 /*
500f57bf5c6f known issues and notes
michael
parents: 18590
diff changeset
21 Known Issues:
500f57bf5c6f known issues and notes
michael
parents: 18590
diff changeset
22 * The motion estimation is somewhat at the mercy of the input, if the input
500f57bf5c6f known issues and notes
michael
parents: 18590
diff changeset
23 frames are created purely based on spatial interpolation then for example
500f57bf5c6f known issues and notes
michael
parents: 18590
diff changeset
24 a thin black line or another random and not interpolateable pattern
500f57bf5c6f known issues and notes
michael
parents: 18590
diff changeset
25 will cause problems
500f57bf5c6f known issues and notes
michael
parents: 18590
diff changeset
26 Note: completly ignoring the "unavailable" lines during motion estimation
500f57bf5c6f known issues and notes
michael
parents: 18590
diff changeset
27 didnt look any better, so the most obvious solution would be to improve
500f57bf5c6f known issues and notes
michael
parents: 18590
diff changeset
28 tfields or penalize problematic motion vectors ...
500f57bf5c6f known issues and notes
michael
parents: 18590
diff changeset
29
500f57bf5c6f known issues and notes
michael
parents: 18590
diff changeset
30 * If non iterative ME is used then snow currently ignores the OBMC window
500f57bf5c6f known issues and notes
michael
parents: 18590
diff changeset
31 and as a result sometimes creates artifacts
500f57bf5c6f known issues and notes
michael
parents: 18590
diff changeset
32
500f57bf5c6f known issues and notes
michael
parents: 18590
diff changeset
33 * only past frames are used, we should ideally use future frames too, something
500f57bf5c6f known issues and notes
michael
parents: 18590
diff changeset
34 like filtering the whole movie in forward and then backward direction seems
500f57bf5c6f known issues and notes
michael
parents: 18590
diff changeset
35 like a interresting idea but the current filter framework is FAR from
500f57bf5c6f known issues and notes
michael
parents: 18590
diff changeset
36 supporting such things
500f57bf5c6f known issues and notes
michael
parents: 18590
diff changeset
37
500f57bf5c6f known issues and notes
michael
parents: 18590
diff changeset
38 * combining the motion compensated image with the input image also isnt
500f57bf5c6f known issues and notes
michael
parents: 18590
diff changeset
39 as trivial as it seems, simple blindly taking even lines from one and
500f57bf5c6f known issues and notes
michael
parents: 18590
diff changeset
40 odd ones from the other doesnt work at all as ME/MC sometimes simple
500f57bf5c6f known issues and notes
michael
parents: 18590
diff changeset
41 has nothing in the previous frames which matches the current, the current
500f57bf5c6f known issues and notes
michael
parents: 18590
diff changeset
42 algo has been found by trial and error and almost certainly can be
500f57bf5c6f known issues and notes
michael
parents: 18590
diff changeset
43 improved ...
500f57bf5c6f known issues and notes
michael
parents: 18590
diff changeset
44 */
500f57bf5c6f known issues and notes
michael
parents: 18590
diff changeset
45
18590
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
46 #include <stdio.h>
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
47 #include <stdlib.h>
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
48 #include <string.h>
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
49 #include <inttypes.h>
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
50 #include <math.h>
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
51
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
52 #include "config.h"
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
53
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
54 #include "mp_msg.h"
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
55 #include "cpudetect.h"
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
56
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
57 #include "libavcodec/avcodec.h"
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
58 #include "libavcodec/dsputil.h"
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
59
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
60 #ifdef HAVE_MALLOC_H
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
61 #include <malloc.h>
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
62 #endif
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
63
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
64 #include "img_format.h"
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
65 #include "mp_image.h"
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
66 #include "vf.h"
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
67 #include "libvo/fastmemcpy.h"
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
68
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
69 #define MIN(a,b) ((a) > (b) ? (b) : (a))
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
70 #define MAX(a,b) ((a) < (b) ? (b) : (a))
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
71 #define ABS(a) ((a) > 0 ? (a) : (-(a)))
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
72
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
73 //===========================================================================//
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
74
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
75 struct vf_priv_s {
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
76 int mode;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
77 int qp;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
78 int parity;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
79 #if 0
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
80 int temp_stride[3];
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
81 uint8_t *src[3];
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
82 int16_t *temp[3];
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
83 #endif
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
84 int outbuf_size;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
85 uint8_t *outbuf;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
86 AVCodecContext *avctx_enc;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
87 AVFrame *frame;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
88 AVFrame *frame_dec;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
89 };
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
90
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
91 static void filter(struct vf_priv_s *p, uint8_t *dst[3], uint8_t *src[3], int dst_stride[3], int src_stride[3], int width, int height){
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
92 int x, y, i;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
93 int out_size;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
94
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
95 for(i=0; i<3; i++){
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
96 p->frame->data[i]= src[i];
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
97 p->frame->linesize[i]= src_stride[i];
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
98 }
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
99
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
100 p->avctx_enc->me_cmp=
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
101 p->avctx_enc->me_sub_cmp= FF_CMP_SAD /*| (p->parity ? FF_CMP_ODD : FF_CMP_EVEN)*/;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
102 p->frame->quality= p->qp*FF_QP2LAMBDA;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
103 out_size = avcodec_encode_video(p->avctx_enc, p->outbuf, p->outbuf_size, p->frame);
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
104 p->frame_dec = p->avctx_enc->coded_frame;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
105
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
106 for(i=0; i<3; i++){
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
107 int is_chroma= !!i;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
108 int w= width >>is_chroma;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
109 int h= height>>is_chroma;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
110 int fils= p->frame_dec->linesize[i];
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
111 int srcs= src_stride[i];
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
112
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
113 for(y=0; y<h; y++){
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
114 if((y ^ p->parity) & 1){
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
115 for(x=0; x<w; x++){
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
116 if(x>0 && y>0 && x+1<w && y+1<h){
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
117 uint8_t *filp= &p->frame_dec->data[i][x + y*fils];
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
118 uint8_t *srcp= &src[i][x + y*srcs];
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
119 int diff0=
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
120 filp[-1-fils] + 2*filp[-fils] + filp[1-fils]
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
121 -srcp[-1-srcs] - 2*srcp[-srcs] - srcp[1-srcs];
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
122 int diff1=
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
123 +filp[-1+fils] + 2*filp[+fils] + filp[1+fils]
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
124 -srcp[-1+srcs] - 2*srcp[+srcs] - srcp[1+srcs];
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
125 int temp= filp[0];
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
126 #if 0
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
127 if((diff0 ^ diff1) > 0){
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
128 int mindiff= ABS(diff0) > ABS(diff1) ? diff1 : diff0;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
129 temp-= (mindiff + 2)>>2;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
130 }
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
131 #elif 1
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
132 if(diff0 + diff1 > 0)
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
133 temp-= (diff0 + diff1 - ABS( ABS(diff0) - ABS(diff1) )/2)/8;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
134 else
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
135 temp-= (diff0 + diff1 + ABS( ABS(diff0) - ABS(diff1) )/2)/8;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
136 #else
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
137 temp-= (diff0 + diff1)/8;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
138 #endif
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
139 #if 1
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
140 filp[0]=
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
141 dst[i][x + y*dst_stride[i]]= temp > 255U ? ~(temp>>31) : temp;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
142 #else
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
143 dst[i][x + y*dst_stride[i]]= filp[0];
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
144 filp[0]= temp > 255U ? ~(temp>>31) : temp;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
145 #endif
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
146 }else
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
147 dst[i][x + y*dst_stride[i]]= p->frame_dec->data[i][x + y*fils];
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
148 }
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
149 }
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
150 }
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
151 for(y=0; y<h; y++){
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
152 if(!((y ^ p->parity) & 1)){
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
153 for(x=0; x<w; x++){
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
154 #if 1
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
155 p->frame_dec->data[i][x + y*fils]=
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
156 dst[i][x + y*dst_stride[i]]= src[i][x + y*srcs];
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
157 #else
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
158 dst[i][x + y*dst_stride[i]]= p->frame_dec->data[i][x + y*fils];
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
159 p->frame_dec->data[i][x + y*fils]= src[i][x + y*srcs];
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
160 #endif
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
161 }
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
162 }
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
163 }
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
164 }
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
165 p->parity ^= 1;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
166
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
167 }
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
168
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
169 static int config(struct vf_instance_s* vf,
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
170 int width, int height, int d_width, int d_height,
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
171 unsigned int flags, unsigned int outfmt){
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
172 int i;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
173 AVCodec *enc= avcodec_find_encoder(CODEC_ID_SNOW);
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
174
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
175 for(i=0; i<3; i++){
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
176 AVCodecContext *avctx_enc;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
177 #if 0
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
178 int is_chroma= !!i;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
179 int w= ((width + 31) & (~31))>>is_chroma;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
180 int h= ((height + 31) & (~31))>>is_chroma;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
181
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
182 vf->priv->temp_stride[i]= w;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
183 vf->priv->temp[i]= malloc(vf->priv->temp_stride[i]*h*sizeof(int16_t));
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
184 vf->priv->src [i]= malloc(vf->priv->temp_stride[i]*h*sizeof(uint8_t));
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
185 #endif
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
186 avctx_enc=
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
187 vf->priv->avctx_enc= avcodec_alloc_context();
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
188 avctx_enc->width = width;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
189 avctx_enc->height = height;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
190 avctx_enc->time_base= (AVRational){1,25}; // meaningless
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
191 avctx_enc->gop_size = 300;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
192 avctx_enc->max_b_frames= 0;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
193 avctx_enc->pix_fmt = PIX_FMT_YUV420P;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
194 avctx_enc->flags = CODEC_FLAG_QSCALE | CODEC_FLAG_LOW_DELAY;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
195 avctx_enc->strict_std_compliance = FF_COMPLIANCE_EXPERIMENTAL;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
196 avctx_enc->global_quality= 1;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
197 avctx_enc->flags2= CODEC_FLAG2_MEMC_ONLY;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
198 avctx_enc->me_cmp=
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
199 avctx_enc->me_sub_cmp= FF_CMP_SAD; //SSE;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
200 avctx_enc->mb_cmp= FF_CMP_SSE;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
201
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
202 switch(vf->priv->mode){
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
203 case 3:
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
204 avctx_enc->refs= 3;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
205 case 2:
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
206 avctx_enc->me_method= ME_ITER;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
207 case 1:
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
208 avctx_enc->flags |= CODEC_FLAG_4MV;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
209 avctx_enc->dia_size=2;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
210 // avctx_enc->mb_decision = MB_DECISSION_RD;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
211 case 0:
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
212 avctx_enc->flags |= CODEC_FLAG_QPEL;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
213 }
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
214
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
215 avcodec_open(avctx_enc, enc);
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
216
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
217 }
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
218 vf->priv->frame= avcodec_alloc_frame();
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
219
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
220 vf->priv->outbuf_size= width*height*10;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
221 vf->priv->outbuf= malloc(vf->priv->outbuf_size);
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
222
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
223 return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
224 }
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
225
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
226 static void get_image(struct vf_instance_s* vf, mp_image_t *mpi){
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
227 if(mpi->flags&MP_IMGFLAG_PRESERVE) return; // don't change
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
228 return; //caused problems, dunno why
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
229 // ok, we can do pp in-place (or pp disabled):
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
230 vf->dmpi=vf_get_image(vf->next,mpi->imgfmt,
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
231 mpi->type, mpi->flags | MP_IMGFLAG_READABLE, mpi->width, mpi->height);
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
232 mpi->planes[0]=vf->dmpi->planes[0];
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
233 mpi->stride[0]=vf->dmpi->stride[0];
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
234 mpi->width=vf->dmpi->width;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
235 if(mpi->flags&MP_IMGFLAG_PLANAR){
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
236 mpi->planes[1]=vf->dmpi->planes[1];
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
237 mpi->planes[2]=vf->dmpi->planes[2];
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
238 mpi->stride[1]=vf->dmpi->stride[1];
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
239 mpi->stride[2]=vf->dmpi->stride[2];
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
240 }
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
241 mpi->flags|=MP_IMGFLAG_DIRECT;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
242 }
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
243
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
244 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi, double pts){
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
245 mp_image_t *dmpi;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
246
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
247 if(!(mpi->flags&MP_IMGFLAG_DIRECT)){
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
248 // no DR, so get a new image! hope we'll get DR buffer:
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
249 dmpi=vf_get_image(vf->next,mpi->imgfmt,
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
250 MP_IMGTYPE_TEMP,
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
251 MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_PREFER_ALIGNED_STRIDE,
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
252 mpi->width,mpi->height);
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
253 vf_clone_mpi_attributes(dmpi, mpi);
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
254 }else{
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
255 dmpi=vf->dmpi;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
256 }
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
257
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
258 filter(vf->priv, dmpi->planes, mpi->planes, dmpi->stride, mpi->stride, mpi->w, mpi->h);
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
259
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
260 return vf_next_put_image(vf,dmpi, pts);
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
261 }
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
262
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
263 static void uninit(struct vf_instance_s* vf){
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
264 if(!vf->priv) return;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
265
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
266 #if 0
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
267 for(i=0; i<3; i++){
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
268 if(vf->priv->temp[i]) free(vf->priv->temp[i]);
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
269 vf->priv->temp[i]= NULL;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
270 if(vf->priv->src[i]) free(vf->priv->src[i]);
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
271 vf->priv->src[i]= NULL;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
272 }
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
273 #endif
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
274 av_freep(&vf->priv->avctx_enc);
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
275
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
276 free(vf->priv->outbuf);
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
277 free(vf->priv);
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
278 vf->priv=NULL;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
279 }
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
280
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
281 //===========================================================================//
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
282 static int query_format(struct vf_instance_s* vf, unsigned int fmt){
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
283 switch(fmt){
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
284 case IMGFMT_YV12:
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
285 case IMGFMT_I420:
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
286 case IMGFMT_IYUV:
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
287 case IMGFMT_Y800:
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
288 case IMGFMT_Y8:
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
289 return vf_next_query_format(vf,fmt);
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
290 }
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
291 return 0;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
292 }
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
293
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
294 static int open(vf_instance_t *vf, char* args){
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
295
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
296 vf->config=config;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
297 vf->put_image=put_image;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
298 vf->get_image=get_image;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
299 vf->query_format=query_format;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
300 vf->uninit=uninit;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
301 vf->priv=malloc(sizeof(struct vf_priv_s));
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
302 memset(vf->priv, 0, sizeof(struct vf_priv_s));
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
303
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
304 avcodec_init();
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
305 avcodec_register_all();
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
306
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
307 vf->priv->mode=0;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
308 vf->priv->parity= -1;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
309 vf->priv->qp=1;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
310
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
311 if (args) sscanf(args, "%d:%d:%d", &vf->priv->mode, &vf->priv->parity, &vf->priv->qp);
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
312
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
313 return 1;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
314 }
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
315
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
316 vf_info_t vf_info_mcdeint = {
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
317 "motion compensating deinterlacer",
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
318 "mcdeint",
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
319 "Michael Niedermayer",
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
320 "",
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
321 open,
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
322 NULL
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
323 };