10 #include "img_format.h"
14 #ifdef USE_LIBAVCODEC_SO
15 #include <ffmpeg/avcodec.h>
17 #include "libavcodec/avcodec.h"
20 extern int avcodec_inited
;
28 /* Support for avcodec's built-in deinterlacer.
32 //===========================================================================//
35 /* Convert mplayer's IMGFMT_* to avcodec's PIX_FMT_* for the supported
36 * IMGFMT's, and return -1 if the deinterlacer doesn't support
37 * that format (-1 because 0 is a valid PIX_FMT).
39 /* The deinterlacer supports planer 4:2:0, 4:2:2, and 4:4:4 YUV */
41 imgfmt_to_pixfmt (int imgfmt
)
45 /* I hope I got all the supported formats */
51 return PIX_FMT_YUV420P
;
65 return PIX_FMT_YUV422P
;
69 /* Are there any _planar_ YUV 4:4:4 formats? */
78 config (struct vf_instance_s
* vf
,
79 int width
, int height
, int d_width
, int d_height
,
80 unsigned int flags
, unsigned int outfmt
)
82 struct vf_priv_s
*priv
= vf
->priv
;
84 priv
->pix_fmt
= imgfmt_to_pixfmt(outfmt
);
85 if(priv
->pix_fmt
== -1)
88 /* The deinterlacer will fail if this is false */
89 if ((width
& 3) != 0 || (height
& 3) != 0)
92 /* If we get here, the deinterlacer is guaranteed not to fail */
95 priv
->height
= height
;
97 return vf_next_config(vf
,
104 put_image (struct vf_instance_s
* vf
, mp_image_t
*mpi
, double pts
)
106 struct vf_priv_s
*priv
= vf
->priv
;
109 AVPicture lavc_picture
;
111 lavc_picture
.data
[0] = mpi
->planes
[0];
112 lavc_picture
.data
[1] = mpi
->planes
[1];
113 lavc_picture
.data
[2] = mpi
->planes
[2];
114 lavc_picture
.linesize
[0] = mpi
->stride
[0];
115 lavc_picture
.linesize
[1] = mpi
->stride
[1];
116 lavc_picture
.linesize
[2] = mpi
->stride
[2];
118 dmpi
= vf_get_image(vf
->next
, mpi
->imgfmt
,
119 MP_IMGTYPE_TEMP
, MP_IMGFLAG_ACCEPT_STRIDE
,
120 priv
->width
, priv
->height
);
122 pic
.data
[0] = dmpi
->planes
[0];
123 pic
.data
[1] = dmpi
->planes
[1];
124 pic
.data
[2] = dmpi
->planes
[2];
125 pic
.linesize
[0] = dmpi
->stride
[0];
126 pic
.linesize
[1] = dmpi
->stride
[1];
127 pic
.linesize
[2] = dmpi
->stride
[2];
129 if (avpicture_deinterlace(&pic
, &lavc_picture
,
130 priv
->pix_fmt
, priv
->width
, priv
->height
) < 0)
132 /* This should not happen -- see config() */
136 return vf_next_put_image(vf
, dmpi
, pts
);
141 query_format (struct vf_instance_s
* vf
, unsigned int fmt
)
143 if(imgfmt_to_pixfmt(fmt
) == -1)
146 return vf_next_query_format(vf
,fmt
);
151 open (vf_instance_t
*vf
, char* args
)
153 /* We don't have any args */
157 vf
->put_image
= put_image
;
158 vf
->query_format
= query_format
;
159 vf
->priv
= malloc(sizeof(struct vf_priv_s
));
160 memset(vf
->priv
,0,sizeof(struct vf_priv_s
));
162 /* This may not technically be necessary just for a deinterlace,
163 * but it seems like a good idea.
168 avcodec_register_all();
176 const vf_info_t vf_info_lavcdeint
= {
177 "libavcodec's deinterlacing filter",
180 "libavcodec's internal deinterlacer, in case you don't like "
181 "the builtin ones (invoked with -pp or -npp)",
187 //===========================================================================//