10 #include "img_format.h"
13 #include "libavcodec/avcodec.h"
15 extern int avcodec_initialized
;
23 /* Support for avcodec's built-in deinterlacer.
27 //===========================================================================//
30 /* Convert mplayer's IMGFMT_* to avcodec's PIX_FMT_* for the supported
31 * IMGFMT's, and return -1 if the deinterlacer doesn't support
32 * that format (-1 because 0 is a valid PIX_FMT).
34 /* The deinterlacer supports planer 4:2:0, 4:2:2, and 4:4:4 YUV */
36 imgfmt_to_pixfmt (int imgfmt
)
40 /* I hope I got all the supported formats */
46 return PIX_FMT_YUV420P
;
60 return PIX_FMT_YUV422P
;
64 /* Are there any _planar_ YUV 4:4:4 formats? */
73 config (struct vf_instance_s
* vf
,
74 int width
, int height
, int d_width
, int d_height
,
75 unsigned int flags
, unsigned int outfmt
)
77 struct vf_priv_s
*priv
= vf
->priv
;
79 priv
->pix_fmt
= imgfmt_to_pixfmt(outfmt
);
80 if(priv
->pix_fmt
== -1)
83 /* The deinterlacer will fail if this is false */
84 if ((width
& 3) != 0 || (height
& 3) != 0)
87 /* If we get here, the deinterlacer is guaranteed not to fail */
90 priv
->height
= height
;
92 return vf_next_config(vf
,
99 put_image (struct vf_instance_s
* vf
, mp_image_t
*mpi
, double pts
)
101 struct vf_priv_s
*priv
= vf
->priv
;
104 AVPicture lavc_picture
;
106 lavc_picture
.data
[0] = mpi
->planes
[0];
107 lavc_picture
.data
[1] = mpi
->planes
[1];
108 lavc_picture
.data
[2] = mpi
->planes
[2];
109 lavc_picture
.linesize
[0] = mpi
->stride
[0];
110 lavc_picture
.linesize
[1] = mpi
->stride
[1];
111 lavc_picture
.linesize
[2] = mpi
->stride
[2];
113 dmpi
= vf_get_image(vf
->next
, mpi
->imgfmt
,
114 MP_IMGTYPE_TEMP
, MP_IMGFLAG_ACCEPT_STRIDE
,
115 priv
->width
, priv
->height
);
117 pic
.data
[0] = dmpi
->planes
[0];
118 pic
.data
[1] = dmpi
->planes
[1];
119 pic
.data
[2] = dmpi
->planes
[2];
120 pic
.linesize
[0] = dmpi
->stride
[0];
121 pic
.linesize
[1] = dmpi
->stride
[1];
122 pic
.linesize
[2] = dmpi
->stride
[2];
124 if (avpicture_deinterlace(&pic
, &lavc_picture
,
125 priv
->pix_fmt
, priv
->width
, priv
->height
) < 0)
127 /* This should not happen -- see config() */
131 return vf_next_put_image(vf
, dmpi
, pts
);
136 query_format (struct vf_instance_s
* vf
, unsigned int fmt
)
138 if(imgfmt_to_pixfmt(fmt
) == -1)
141 return vf_next_query_format(vf
,fmt
);
146 open (vf_instance_t
*vf
, char* args
)
148 /* We don't have any args */
152 vf
->put_image
= put_image
;
153 vf
->query_format
= query_format
;
154 vf
->priv
= malloc(sizeof(struct vf_priv_s
));
155 memset(vf
->priv
,0,sizeof(struct vf_priv_s
));
157 /* This may not technically be necessary just for a deinterlace,
158 * but it seems like a good idea.
160 if(!avcodec_initialized
)
163 avcodec_register_all();
164 avcodec_initialized
=1;
171 const vf_info_t vf_info_lavcdeint
= {
172 "libavcodec's deinterlacing filter",
175 "libavcodec's internal deinterlacer, in case you don't like "
176 "the builtin ones (invoked with -pp or -npp)",
182 //===========================================================================//