6859
|
1 #include <stdio.h>
|
|
2 #include <stdlib.h>
|
|
3 #include <string.h>
|
|
4 #include <inttypes.h>
|
|
5
|
|
6 #include "../config.h"
|
|
7 #include "../mp_msg.h"
|
|
8 #include "../help_mp.h"
|
|
9
|
|
10 #ifdef USE_LIBAVCODEC
|
|
11
|
|
12 #include "img_format.h"
|
|
13 #include "mp_image.h"
|
|
14 #include "vf.h"
|
|
15
|
|
16 //#include "../libvo/fastmemcpy.h"
|
|
17
|
|
18 #ifdef USE_LIBAVCODEC_SO
|
|
19 #include <libffmpeg/avcodec.h>
|
|
20 #else
|
|
21 #include "libavcodec/avcodec.h"
|
|
22 #endif
|
|
23
|
|
24 extern int avcodec_inited;
|
|
25
|
|
26 struct vf_priv_s
|
|
27 {
|
|
28 int width, height;
|
|
29 int pix_fmt;
|
|
30 };
|
|
31
|
|
32 #define lavc_venc_context (vf->priv->context)
|
|
33
|
|
34
|
|
35 /* Support for avcodec's built-in deinterlacer.
|
|
36 * Based on vf_lavc.c
|
|
37 */
|
|
38
|
|
39 //===========================================================================//
|
|
40
|
|
41
|
|
42 /* Convert mplayer's IMGFMT_* to avcodec's PIX_FMT_* for the supported
|
|
43 * IMGFMT's, and return -1 if the deinterlacer doesn't support
|
|
44 * that format (-1 because 0 is a valid PIX_FMT).
|
|
45 */
|
|
46 /* The deinterlacer supports planer 4:2:0, 4:2:2, and 4:4:4 YUV */
|
|
47 static int
|
|
48 imgfmt_to_pixfmt (int imgfmt)
|
|
49 {
|
|
50 switch(imgfmt)
|
|
51 {
|
|
52 /* I hope I got all the supported formats */
|
|
53
|
|
54 /* 4:2:0 */
|
|
55 case IMGFMT_YV12:
|
|
56 case IMGFMT_I420:
|
|
57 case IMGFMT_IYUV:
|
|
58 return PIX_FMT_YUV420P;
|
|
59 break;
|
|
60
|
6860
|
61 #if 0
|
6859
|
62 /* 4:2:2 */
|
|
63 case IMGFMT_UYVY:
|
|
64 case IMGFMT_UYNV:
|
|
65 case IMGFMT_Y422:
|
|
66 case IMGFMT_YUY2:
|
|
67 case IMGFMT_YUNV:
|
|
68 case IMGFMT_YVYU:
|
|
69 case IMGFMT_Y42T:
|
|
70 case IMGFMT_V422:
|
|
71 case IMGFMT_V655:
|
|
72 return PIX_FMT_YUV422P;
|
|
73 break;
|
6860
|
74 #endif
|
6859
|
75
|
|
76 /* Are there any _planar_ YUV 4:4:4 formats? */
|
|
77
|
|
78 default:
|
|
79 return -1;
|
|
80 }
|
|
81 }
|
|
82
|
|
83
|
|
84 static int
|
|
85 config (struct vf_instance_s* vf,
|
|
86 int width, int height, int d_width, int d_height,
|
|
87 unsigned int flags, unsigned int outfmt)
|
|
88 {
|
|
89 struct vf_priv_s *priv = vf->priv;
|
|
90
|
|
91 priv->pix_fmt = imgfmt_to_pixfmt(outfmt);
|
|
92 if(priv->pix_fmt == -1)
|
|
93 return 0;
|
|
94
|
|
95 /* The deinterlacer will fail if this is false */
|
|
96 if ((width & 1) != 0 || (height & 3) != 0)
|
|
97 return 0;
|
|
98
|
|
99 /* If we get here, the deinterlacer is guaranteed not to fail */
|
|
100
|
|
101 priv->width = width;
|
|
102 priv->height = height;
|
|
103
|
|
104 return vf_next_config(vf,
|
|
105 width, height,
|
|
106 d_width, d_height,
|
|
107 flags, outfmt);
|
|
108 }
|
|
109
|
|
110 static void
|
|
111 put_image (struct vf_instance_s* vf, mp_image_t *mpi)
|
|
112 {
|
|
113 struct vf_priv_s *priv = vf->priv;
|
|
114 mp_image_t* dmpi;
|
6860
|
115 AVPicture pic;
|
6859
|
116 AVPicture lavc_picture;
|
|
117
|
|
118 lavc_picture.data[0] = mpi->planes[0];
|
|
119 lavc_picture.data[1] = mpi->planes[1];
|
|
120 lavc_picture.data[2] = mpi->planes[2];
|
|
121 lavc_picture.linesize[0] = mpi->stride[0];
|
|
122 lavc_picture.linesize[1] = mpi->stride[1];
|
|
123 lavc_picture.linesize[2] = mpi->stride[2];
|
|
124
|
6860
|
125 dmpi = vf_get_image(vf->next, mpi->imgfmt,
|
|
126 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
|
|
127 priv->width, priv->height);
|
6859
|
128
|
6860
|
129 pic.data[0] = dmpi->planes[0];
|
|
130 pic.data[1] = dmpi->planes[1];
|
|
131 pic.data[2] = dmpi->planes[2];
|
|
132 pic.linesize[0] = dmpi->stride[0];
|
|
133 pic.linesize[1] = dmpi->stride[1];
|
|
134 pic.linesize[2] = dmpi->stride[2];
|
6859
|
135
|
6860
|
136 if (avpicture_deinterlace(&pic, &lavc_picture,
|
6859
|
137 priv->pix_fmt, priv->width, priv->height) < 0)
|
|
138 {
|
|
139 /* This should not happen -- see config() */
|
|
140 return;
|
|
141 }
|
|
142
|
|
143 vf_next_put_image(vf, dmpi);
|
|
144 }
|
|
145
|
|
146
|
|
147 static int
|
|
148 query_format (struct vf_instance_s* vf, unsigned int fmt)
|
|
149 {
|
|
150 if(imgfmt_to_pixfmt(fmt) == -1)
|
|
151 return 0;
|
|
152
|
|
153 return vf_next_query_format(vf,fmt);
|
|
154 }
|
|
155
|
|
156
|
|
157 static int
|
|
158 open (vf_instance_t *vf, char* args)
|
|
159 {
|
|
160 /* We don't have any args */
|
|
161 (void) args;
|
|
162
|
|
163 vf->config = config;
|
|
164 vf->put_image = put_image;
|
|
165 vf->query_format = query_format;
|
|
166 vf->priv = malloc(sizeof(struct vf_priv_s));
|
|
167 memset(vf->priv,0,sizeof(struct vf_priv_s));
|
|
168
|
|
169 /* This may not technically be necessary just for a deinterlace,
|
|
170 * but it seems like a good idea.
|
|
171 */
|
|
172 if(!avcodec_inited)
|
|
173 {
|
|
174 avcodec_init();
|
|
175 avcodec_register_all();
|
|
176 avcodec_inited=1;
|
|
177 }
|
|
178
|
|
179 return 1;
|
|
180 }
|
|
181
|
|
182
|
|
183 vf_info_t vf_info_lavcdeint = {
|
|
184 "libavcodec's deinterlacing filter",
|
|
185 "lavcdeint",
|
|
186 "Joe Rabinoff",
|
|
187 "libavcodec's internal deinterlacer, in case you don't like "
|
|
188 "the builtin ones (invoked with -pp or -npp)",
|
|
189 open
|
|
190 };
|
|
191
|
|
192
|
|
193 //===========================================================================//
|
|
194
|
|
195 #endif /* USE_LIBAVCODEC */
|
|
196
|