annotate libmpcodecs/vf_mcdeint.c @ 36199:25e1fb36262e

mcdeint: avoid uninited data read Do not read padding or out-of-buffer values when computing the output value for a pixel close to the image buffer edge. This avoids non visible artifacts which affected the output checksum. Patch by Stefano Sabatini, stefasab gmail
author cehoyos
date Sat, 01 Jun 2013 23:07:27 +0000
parents 8517826b0dbd
children 1294b0ff7e06
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18590
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
1 /*
26727
82601a38e2a7 Use standard license headers.
diego
parents: 25221
diff changeset
2 * Copyright (C) 2006 Michael Niedermayer <michaelni@gmx.at>
82601a38e2a7 Use standard license headers.
diego
parents: 25221
diff changeset
3 *
82601a38e2a7 Use standard license headers.
diego
parents: 25221
diff changeset
4 * This file is part of MPlayer.
82601a38e2a7 Use standard license headers.
diego
parents: 25221
diff changeset
5 *
82601a38e2a7 Use standard license headers.
diego
parents: 25221
diff changeset
6 * MPlayer is free software; you can redistribute it and/or modify
82601a38e2a7 Use standard license headers.
diego
parents: 25221
diff changeset
7 * it under the terms of the GNU General Public License as published by
82601a38e2a7 Use standard license headers.
diego
parents: 25221
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or
82601a38e2a7 Use standard license headers.
diego
parents: 25221
diff changeset
9 * (at your option) any later version.
82601a38e2a7 Use standard license headers.
diego
parents: 25221
diff changeset
10 *
82601a38e2a7 Use standard license headers.
diego
parents: 25221
diff changeset
11 * MPlayer is distributed in the hope that it will be useful,
82601a38e2a7 Use standard license headers.
diego
parents: 25221
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
82601a38e2a7 Use standard license headers.
diego
parents: 25221
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
82601a38e2a7 Use standard license headers.
diego
parents: 25221
diff changeset
14 * GNU General Public License for more details.
82601a38e2a7 Use standard license headers.
diego
parents: 25221
diff changeset
15 *
82601a38e2a7 Use standard license headers.
diego
parents: 25221
diff changeset
16 * You should have received a copy of the GNU General Public License along
82601a38e2a7 Use standard license headers.
diego
parents: 25221
diff changeset
17 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
82601a38e2a7 Use standard license headers.
diego
parents: 25221
diff changeset
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
82601a38e2a7 Use standard license headers.
diego
parents: 25221
diff changeset
19 */
18590
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
20
18592
500f57bf5c6f known issues and notes
michael
parents: 18590
diff changeset
21
500f57bf5c6f known issues and notes
michael
parents: 18590
diff changeset
22 /*
500f57bf5c6f known issues and notes
michael
parents: 18590
diff changeset
23 Known Issues:
500f57bf5c6f known issues and notes
michael
parents: 18590
diff changeset
24 * The motion estimation is somewhat at the mercy of the input, if the input
500f57bf5c6f known issues and notes
michael
parents: 18590
diff changeset
25 frames are created purely based on spatial interpolation then for example
500f57bf5c6f known issues and notes
michael
parents: 18590
diff changeset
26 a thin black line or another random and not interpolateable pattern
500f57bf5c6f known issues and notes
michael
parents: 18590
diff changeset
27 will cause problems
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29087
diff changeset
28 Note: completly ignoring the "unavailable" lines during motion estimation
18592
500f57bf5c6f known issues and notes
michael
parents: 18590
diff changeset
29 didnt look any better, so the most obvious solution would be to improve
500f57bf5c6f known issues and notes
michael
parents: 18590
diff changeset
30 tfields or penalize problematic motion vectors ...
500f57bf5c6f known issues and notes
michael
parents: 18590
diff changeset
31
500f57bf5c6f known issues and notes
michael
parents: 18590
diff changeset
32 * If non iterative ME is used then snow currently ignores the OBMC window
500f57bf5c6f known issues and notes
michael
parents: 18590
diff changeset
33 and as a result sometimes creates artifacts
500f57bf5c6f known issues and notes
michael
parents: 18590
diff changeset
34
500f57bf5c6f known issues and notes
michael
parents: 18590
diff changeset
35 * only past frames are used, we should ideally use future frames too, something
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29087
diff changeset
36 like filtering the whole movie in forward and then backward direction seems
18592
500f57bf5c6f known issues and notes
michael
parents: 18590
diff changeset
37 like a interresting idea but the current filter framework is FAR from
500f57bf5c6f known issues and notes
michael
parents: 18590
diff changeset
38 supporting such things
500f57bf5c6f known issues and notes
michael
parents: 18590
diff changeset
39
500f57bf5c6f known issues and notes
michael
parents: 18590
diff changeset
40 * combining the motion compensated image with the input image also isnt
500f57bf5c6f known issues and notes
michael
parents: 18590
diff changeset
41 as trivial as it seems, simple blindly taking even lines from one and
500f57bf5c6f known issues and notes
michael
parents: 18590
diff changeset
42 odd ones from the other doesnt work at all as ME/MC sometimes simple
500f57bf5c6f known issues and notes
michael
parents: 18590
diff changeset
43 has nothing in the previous frames which matches the current, the current
500f57bf5c6f known issues and notes
michael
parents: 18590
diff changeset
44 algo has been found by trial and error and almost certainly can be
500f57bf5c6f known issues and notes
michael
parents: 18590
diff changeset
45 improved ...
500f57bf5c6f known issues and notes
michael
parents: 18590
diff changeset
46 */
500f57bf5c6f known issues and notes
michael
parents: 18590
diff changeset
47
18590
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
48 #include <stdio.h>
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
49 #include <stdlib.h>
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
50 #include <string.h>
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
51 #include <inttypes.h>
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
52 #include <math.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
35712
d206960484fe Add a number of missing libavutil header #includes.
diego
parents: 34718
diff changeset
57 #include "libavutil/common.h"
28329
ed42e982e79f Fix compilation after DECLARE_ASM_CONST/DECLARE_ALIGNED moving within FFmpeg.
diego
parents: 26727
diff changeset
58 #include "libavutil/internal.h"
24977
1e25755bc0c4 Add missing header files, fixes the warnings:
diego
parents: 23373
diff changeset
59 #include "libavutil/intreadwrite.h"
18590
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
60 #include "libavcodec/avcodec.h"
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
61 #include "libavcodec/dsputil.h"
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
62
28329
ed42e982e79f Fix compilation after DECLARE_ASM_CONST/DECLARE_ALIGNED moving within FFmpeg.
diego
parents: 26727
diff changeset
63 #undef fprintf
ed42e982e79f Fix compilation after DECLARE_ASM_CONST/DECLARE_ALIGNED moving within FFmpeg.
diego
parents: 26727
diff changeset
64 #undef free
ed42e982e79f Fix compilation after DECLARE_ASM_CONST/DECLARE_ALIGNED moving within FFmpeg.
diego
parents: 26727
diff changeset
65 #undef malloc
ed42e982e79f Fix compilation after DECLARE_ASM_CONST/DECLARE_ALIGNED moving within FFmpeg.
diego
parents: 26727
diff changeset
66
18590
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
67 #include "img_format.h"
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
68 #include "mp_image.h"
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
69 #include "vf.h"
33871
30f5e5cd3676 Move code for setting up libav* logging callbacks from vd_ffmpeg to a
reimar
parents: 33343
diff changeset
70 #include "av_helpers.h"
18590
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
71
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
72 #define MIN(a,b) ((a) > (b) ? (b) : (a))
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
73 #define MAX(a,b) ((a) < (b) ? (b) : (a))
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
74 #define ABS(a) ((a) > 0 ? (a) : (-(a)))
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
75
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
76 //===========================================================================//
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
77
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
78 struct vf_priv_s {
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
79 int mode;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
80 int qp;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
81 int parity;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
82 #if 0
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
83 int temp_stride[3];
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
84 uint8_t *src[3];
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
85 int16_t *temp[3];
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
86 #endif
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
87 int outbuf_size;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
88 uint8_t *outbuf;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
89 AVCodecContext *avctx_enc;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
90 AVFrame *frame;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
91 AVFrame *frame_dec;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
92 };
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
93
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
94 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){
18657
26f54fad099c better spatial interpolation
michael
parents: 18648
diff changeset
95 int x, y, i;
18590
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
96
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
97 for(i=0; i<3; i++){
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
98 p->frame->data[i]= src[i];
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
99 p->frame->linesize[i]= src_stride[i];
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
100 }
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
101
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
102 p->avctx_enc->me_cmp=
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
103 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
104 p->frame->quality= p->qp*FF_QP2LAMBDA;
33343
847e0d6aa196 Remove unused variable for FFmpeg encode result.
reimar
parents: 32702
diff changeset
105 avcodec_encode_video(p->avctx_enc, p->outbuf, p->outbuf_size, p->frame);
18590
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
106 p->frame_dec = p->avctx_enc->coded_frame;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
107
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
108 for(i=0; i<3; i++){
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
109 int is_chroma= !!i;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
110 int w= width >>is_chroma;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
111 int h= height>>is_chroma;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
112 int fils= p->frame_dec->linesize[i];
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
113 int srcs= src_stride[i];
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
114
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
115 for(y=0; y<h; y++){
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
116 if((y ^ p->parity) & 1){
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
117 for(x=0; x<w; x++){
36199
25e1fb36262e mcdeint: avoid uninited data read
cehoyos
parents: 35715
diff changeset
118 if(y>0 && y<h-1){
25e1fb36262e mcdeint: avoid uninited data read
cehoyos
parents: 35715
diff changeset
119 int is_edge= x<3 || x>w-4;
18590
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
120 uint8_t *filp= &p->frame_dec->data[i][x + y*fils];
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
121 uint8_t *srcp= &src[i][x + y*srcs];
18647
c921020fd8bd improved mc+src merge code
michael
parents: 18592
diff changeset
122 int diff0= filp[-fils] - srcp[-srcs];
c921020fd8bd improved mc+src merge code
michael
parents: 18592
diff changeset
123 int diff1= filp[+fils] - srcp[+srcs];
18590
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
124 int temp= filp[0];
18647
c921020fd8bd improved mc+src merge code
michael
parents: 18592
diff changeset
125
36199
25e1fb36262e mcdeint: avoid uninited data read
cehoyos
parents: 35715
diff changeset
126 #define DELTA(j) av_clip(j, -x, w-1-x)
25e1fb36262e mcdeint: avoid uninited data read
cehoyos
parents: 35715
diff changeset
127
25e1fb36262e mcdeint: avoid uninited data read
cehoyos
parents: 35715
diff changeset
128 #define GET_SCORE_EDGE(j)\
25e1fb36262e mcdeint: avoid uninited data read
cehoyos
parents: 35715
diff changeset
129 ABS(srcp[-srcs+DELTA(-1+(j))] - srcp[+srcs+DELTA(-1-(j))])+\
25e1fb36262e mcdeint: avoid uninited data read
cehoyos
parents: 35715
diff changeset
130 ABS(srcp[-srcs+DELTA(j) ] - srcp[+srcs+DELTA( -(j))])+\
25e1fb36262e mcdeint: avoid uninited data read
cehoyos
parents: 35715
diff changeset
131 ABS(srcp[-srcs+DELTA(1+(j)) ] - srcp[+srcs+DELTA( 1-(j))])
25e1fb36262e mcdeint: avoid uninited data read
cehoyos
parents: 35715
diff changeset
132
25e1fb36262e mcdeint: avoid uninited data read
cehoyos
parents: 35715
diff changeset
133 #define GET_SCORE(j)\
25e1fb36262e mcdeint: avoid uninited data read
cehoyos
parents: 35715
diff changeset
134 ABS(srcp[-srcs-1+(j)] - srcp[+srcs-1-(j)])+\
25e1fb36262e mcdeint: avoid uninited data read
cehoyos
parents: 35715
diff changeset
135 ABS(srcp[-srcs +(j)] - srcp[+srcs -(j)])+\
25e1fb36262e mcdeint: avoid uninited data read
cehoyos
parents: 35715
diff changeset
136 ABS(srcp[-srcs+1+(j)] - srcp[+srcs+1-(j)])
25e1fb36262e mcdeint: avoid uninited data read
cehoyos
parents: 35715
diff changeset
137
25e1fb36262e mcdeint: avoid uninited data read
cehoyos
parents: 35715
diff changeset
138 #define CHECK_EDGE(j)\
25e1fb36262e mcdeint: avoid uninited data read
cehoyos
parents: 35715
diff changeset
139 { int score= GET_SCORE_EDGE(j);\
25e1fb36262e mcdeint: avoid uninited data read
cehoyos
parents: 35715
diff changeset
140 if(score < spatial_score){\
25e1fb36262e mcdeint: avoid uninited data read
cehoyos
parents: 35715
diff changeset
141 spatial_score= score;\
25e1fb36262e mcdeint: avoid uninited data read
cehoyos
parents: 35715
diff changeset
142 diff0= filp[-fils+DELTA(j)] - srcp[-srcs+DELTA(j)];\
25e1fb36262e mcdeint: avoid uninited data read
cehoyos
parents: 35715
diff changeset
143 diff1= filp[+fils+DELTA(-(j))] - srcp[+srcs+DELTA(-(j))];\
25e1fb36262e mcdeint: avoid uninited data read
cehoyos
parents: 35715
diff changeset
144
18657
26f54fad099c better spatial interpolation
michael
parents: 18648
diff changeset
145 #define CHECK(j)\
36199
25e1fb36262e mcdeint: avoid uninited data read
cehoyos
parents: 35715
diff changeset
146 { int score= GET_SCORE(j);\
18657
26f54fad099c better spatial interpolation
michael
parents: 18648
diff changeset
147 if(score < spatial_score){\
26f54fad099c better spatial interpolation
michael
parents: 18648
diff changeset
148 spatial_score= score;\
36199
25e1fb36262e mcdeint: avoid uninited data read
cehoyos
parents: 35715
diff changeset
149 diff0= filp[-fils+(j)] - srcp[-srcs+(j)];\
25e1fb36262e mcdeint: avoid uninited data read
cehoyos
parents: 35715
diff changeset
150 diff1= filp[+fils-(j)] - srcp[+srcs-(j)];\
18657
26f54fad099c better spatial interpolation
michael
parents: 18648
diff changeset
151
36199
25e1fb36262e mcdeint: avoid uninited data read
cehoyos
parents: 35715
diff changeset
152 if (is_edge) {
25e1fb36262e mcdeint: avoid uninited data read
cehoyos
parents: 35715
diff changeset
153 int spatial_score= GET_SCORE_EDGE(0)-1;
25e1fb36262e mcdeint: avoid uninited data read
cehoyos
parents: 35715
diff changeset
154 CHECK_EDGE(-1) CHECK_EDGE(-2) }} }}
25e1fb36262e mcdeint: avoid uninited data read
cehoyos
parents: 35715
diff changeset
155 CHECK_EDGE( 1) CHECK_EDGE( 2) }} }}
25e1fb36262e mcdeint: avoid uninited data read
cehoyos
parents: 35715
diff changeset
156 } else {
25e1fb36262e mcdeint: avoid uninited data read
cehoyos
parents: 35715
diff changeset
157 int spatial_score= GET_SCORE(0)-1;
25e1fb36262e mcdeint: avoid uninited data read
cehoyos
parents: 35715
diff changeset
158 CHECK(-1) CHECK(-2) }} }}
25e1fb36262e mcdeint: avoid uninited data read
cehoyos
parents: 35715
diff changeset
159 CHECK( 1) CHECK( 2) }} }}
25e1fb36262e mcdeint: avoid uninited data read
cehoyos
parents: 35715
diff changeset
160 }
18590
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
161 #if 0
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
162 if((diff0 ^ diff1) > 0){
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
163 int mindiff= ABS(diff0) > ABS(diff1) ? diff1 : diff0;
18647
c921020fd8bd improved mc+src merge code
michael
parents: 18592
diff changeset
164 temp-= mindiff;
18590
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
165 }
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
166 #elif 1
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
167 if(diff0 + diff1 > 0)
18647
c921020fd8bd improved mc+src merge code
michael
parents: 18592
diff changeset
168 temp-= (diff0 + diff1 - ABS( ABS(diff0) - ABS(diff1) )/2)/2;
18590
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
169 else
18647
c921020fd8bd improved mc+src merge code
michael
parents: 18592
diff changeset
170 temp-= (diff0 + diff1 + ABS( ABS(diff0) - ABS(diff1) )/2)/2;
18590
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
171 #else
18647
c921020fd8bd improved mc+src merge code
michael
parents: 18592
diff changeset
172 temp-= (diff0 + diff1)/2;
18590
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
173 #endif
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
174 #if 1
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
175 filp[0]=
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
176 dst[i][x + y*dst_stride[i]]= temp > 255U ? ~(temp>>31) : temp;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
177 #else
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
178 dst[i][x + y*dst_stride[i]]= filp[0];
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
179 filp[0]= temp > 255U ? ~(temp>>31) : temp;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
180 #endif
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
181 }else
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
182 dst[i][x + y*dst_stride[i]]= p->frame_dec->data[i][x + y*fils];
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
183 }
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
184 }
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
185 }
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
186 for(y=0; y<h; y++){
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
187 if(!((y ^ p->parity) & 1)){
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
188 for(x=0; x<w; x++){
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
189 #if 1
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
190 p->frame_dec->data[i][x + y*fils]=
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
191 dst[i][x + y*dst_stride[i]]= src[i][x + y*srcs];
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
192 #else
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
193 dst[i][x + y*dst_stride[i]]= p->frame_dec->data[i][x + y*fils];
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
194 p->frame_dec->data[i][x + y*fils]= src[i][x + y*srcs];
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
195 #endif
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
196 }
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
197 }
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
198 }
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
199 }
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
200 p->parity ^= 1;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
201
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
202 }
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
203
30642
a972c1a4a012 cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents: 30638
diff changeset
204 static int config(struct vf_instance *vf,
18590
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
205 int width, int height, int d_width, int d_height,
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 32537
diff changeset
206 unsigned int flags, unsigned int outfmt){
18590
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
207 int i;
35715
8517826b0dbd Replace CODEC_IDs their modern AV_-prefixed counterparts.
diego
parents: 35712
diff changeset
208 AVCodec *enc= avcodec_find_encoder(AV_CODEC_ID_SNOW);
18590
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
209
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
210 for(i=0; i<3; i++){
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
211 AVCodecContext *avctx_enc;
34718
8ef6e54892fa Ensure the AVDictionary is initialized.
reimar
parents: 34543
diff changeset
212 AVDictionary *opts = NULL;
18590
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
213 #if 0
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
214 int is_chroma= !!i;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
215 int w= ((width + 31) & (~31))>>is_chroma;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
216 int h= ((height + 31) & (~31))>>is_chroma;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
217
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
218 vf->priv->temp_stride[i]= w;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
219 vf->priv->temp[i]= malloc(vf->priv->temp_stride[i]*h*sizeof(int16_t));
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
220 vf->priv->src [i]= malloc(vf->priv->temp_stride[i]*h*sizeof(uint8_t));
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
221 #endif
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
222 avctx_enc=
34543
21caebba991b Switch to avcodec_alloc_context3.
reimar
parents: 34542
diff changeset
223 vf->priv->avctx_enc= avcodec_alloc_context3(enc);
18590
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
224 avctx_enc->width = width;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
225 avctx_enc->height = height;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
226 avctx_enc->time_base= (AVRational){1,25}; // meaningless
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
227 avctx_enc->gop_size = 300;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
228 avctx_enc->max_b_frames= 0;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
229 avctx_enc->pix_fmt = PIX_FMT_YUV420P;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
230 avctx_enc->flags = CODEC_FLAG_QSCALE | CODEC_FLAG_LOW_DELAY;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
231 avctx_enc->strict_std_compliance = FF_COMPLIANCE_EXPERIMENTAL;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
232 avctx_enc->global_quality= 1;
34542
814b6fcad4b3 Set memc_only via AVDictionary.
reimar
parents: 33871
diff changeset
233 av_dict_set(&opts, "memc_only", "1", 0);
18590
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
234 avctx_enc->me_cmp=
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
235 avctx_enc->me_sub_cmp= FF_CMP_SAD; //SSE;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
236 avctx_enc->mb_cmp= FF_CMP_SSE;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
237
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
238 switch(vf->priv->mode){
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
239 case 3:
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
240 avctx_enc->refs= 3;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
241 case 2:
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
242 avctx_enc->me_method= ME_ITER;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
243 case 1:
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
244 avctx_enc->flags |= CODEC_FLAG_4MV;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
245 avctx_enc->dia_size=2;
22283
bc9e95184521 cosmetics: Fix some common typos, sepErate --> sepArate, deciSSion --> deciSion.
diego
parents: 18821
diff changeset
246 // avctx_enc->mb_decision = MB_DECISION_RD;
18590
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
247 case 0:
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
248 avctx_enc->flags |= CODEC_FLAG_QPEL;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
249 }
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
250
34542
814b6fcad4b3 Set memc_only via AVDictionary.
reimar
parents: 33871
diff changeset
251 avcodec_open2(avctx_enc, enc, &opts);
814b6fcad4b3 Set memc_only via AVDictionary.
reimar
parents: 33871
diff changeset
252 av_dict_free(&opts);
18590
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
253
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
254 }
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
255 vf->priv->frame= avcodec_alloc_frame();
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
256
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
257 vf->priv->outbuf_size= width*height*10;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
258 vf->priv->outbuf= malloc(vf->priv->outbuf_size);
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
259
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 32537
diff changeset
260 return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
18590
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
261 }
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
262
30642
a972c1a4a012 cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents: 30638
diff changeset
263 static void get_image(struct vf_instance *vf, mp_image_t *mpi){
18590
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
264 if(mpi->flags&MP_IMGFLAG_PRESERVE) return; // don't change
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
265 return; //caused problems, dunno why
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
266 // ok, we can do pp in-place (or pp disabled):
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
267 vf->dmpi=vf_get_image(vf->next,mpi->imgfmt,
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
268 mpi->type, mpi->flags | MP_IMGFLAG_READABLE, mpi->width, mpi->height);
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
269 mpi->planes[0]=vf->dmpi->planes[0];
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
270 mpi->stride[0]=vf->dmpi->stride[0];
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
271 mpi->width=vf->dmpi->width;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
272 if(mpi->flags&MP_IMGFLAG_PLANAR){
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
273 mpi->planes[1]=vf->dmpi->planes[1];
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
274 mpi->planes[2]=vf->dmpi->planes[2];
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 32537
diff changeset
275 mpi->stride[1]=vf->dmpi->stride[1];
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 32537
diff changeset
276 mpi->stride[2]=vf->dmpi->stride[2];
18590
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
277 }
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
278 mpi->flags|=MP_IMGFLAG_DIRECT;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
279 }
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
280
30642
a972c1a4a012 cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents: 30638
diff changeset
281 static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){
18590
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
282 mp_image_t *dmpi;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
283
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
284 if(!(mpi->flags&MP_IMGFLAG_DIRECT)){
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
285 // no DR, so get a new image! hope we'll get DR buffer:
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
286 dmpi=vf_get_image(vf->next,mpi->imgfmt,
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
287 MP_IMGTYPE_TEMP,
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
288 MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_PREFER_ALIGNED_STRIDE,
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
289 mpi->width,mpi->height);
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
290 vf_clone_mpi_attributes(dmpi, mpi);
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
291 }else{
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
292 dmpi=vf->dmpi;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
293 }
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
294
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
295 filter(vf->priv, dmpi->planes, mpi->planes, dmpi->stride, mpi->stride, mpi->w, mpi->h);
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
296
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
297 return vf_next_put_image(vf,dmpi, pts);
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
298 }
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
299
30642
a972c1a4a012 cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents: 30638
diff changeset
300 static void uninit(struct vf_instance *vf){
18590
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
301 if(!vf->priv) return;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
302
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
303 #if 0
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
304 for(i=0; i<3; i++){
32537
8fa2f43cb760 Remove most of the NULL pointer check before free all over the code
cboesch
parents: 31959
diff changeset
305 free(vf->priv->temp[i]);
18590
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
306 vf->priv->temp[i]= NULL;
32537
8fa2f43cb760 Remove most of the NULL pointer check before free all over the code
cboesch
parents: 31959
diff changeset
307 free(vf->priv->src[i]);
18590
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
308 vf->priv->src[i]= NULL;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
309 }
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
310 #endif
18821
ac61a42feb47 Avoid crash in uninit-without-config case
reimar
parents: 18752
diff changeset
311 if (vf->priv->avctx_enc) {
18752
b1b3d79011b9 avcodec_close()
michael
parents: 18657
diff changeset
312 avcodec_close(vf->priv->avctx_enc);
18590
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
313 av_freep(&vf->priv->avctx_enc);
18821
ac61a42feb47 Avoid crash in uninit-without-config case
reimar
parents: 18752
diff changeset
314 }
18590
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
315
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
316 free(vf->priv->outbuf);
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
317 free(vf->priv);
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
318 vf->priv=NULL;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
319 }
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
320
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
321 //===========================================================================//
30642
a972c1a4a012 cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents: 30638
diff changeset
322 static int query_format(struct vf_instance *vf, unsigned int fmt){
18590
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
323 switch(fmt){
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 32537
diff changeset
324 case IMGFMT_YV12:
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 32537
diff changeset
325 case IMGFMT_I420:
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 32537
diff changeset
326 case IMGFMT_IYUV:
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 32537
diff changeset
327 case IMGFMT_Y800:
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 32537
diff changeset
328 case IMGFMT_Y8:
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 32537
diff changeset
329 return vf_next_query_format(vf,fmt);
18590
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
330 }
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
331 return 0;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
332 }
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
333
30638
a7b908875c14 Rename open() vf initialization function to vf_open().
diego
parents: 29263
diff changeset
334 static int vf_open(vf_instance_t *vf, char *args){
18590
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
335
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
336 vf->config=config;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
337 vf->put_image=put_image;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
338 vf->get_image=get_image;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
339 vf->query_format=query_format;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
340 vf->uninit=uninit;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
341 vf->priv=malloc(sizeof(struct vf_priv_s));
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
342 memset(vf->priv, 0, sizeof(struct vf_priv_s));
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
343
31959
f957f330aa6d Introduce init_avcodec function to avoid duplicated FFmpeg initializations.
diego
parents: 30642
diff changeset
344 init_avcodec();
18590
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
345
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
346 vf->priv->mode=0;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
347 vf->priv->parity= -1;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
348 vf->priv->qp=1;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
349
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
350 if (args) sscanf(args, "%d:%d:%d", &vf->priv->mode, &vf->priv->parity, &vf->priv->qp);
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
351
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
352 return 1;
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
353 }
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
354
25221
00fff9a3b735 Make all vf_info_t structs const
reimar
parents: 24977
diff changeset
355 const vf_info_t vf_info_mcdeint = {
18590
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
356 "motion compensating deinterlacer",
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
357 "mcdeint",
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
358 "Michael Niedermayer",
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
359 "",
30638
a7b908875c14 Rename open() vf initialization function to vf_open().
diego
parents: 29263
diff changeset
360 vf_open,
18590
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
361 NULL
2fa15de8806b Motion compensating deinterlacer
michael
parents:
diff changeset
362 };