1 /*****************************************************************************
2 * video filter: video filter doing chroma conversion and resizing
3 * using the ffmpeg library
4 *****************************************************************************
5 * Copyright (C) 1999-2001 the VideoLAN team
8 * Authors: Gildas Bazin <gbazin@videolan.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
32 #include <vlc_common.h>
33 #include <vlc_codec.h>
34 #include <vlc_filter.h>
37 #ifdef HAVE_LIBAVCODEC_AVCODEC_H
38 # include <libavcodec/avcodec.h>
39 #elif defined(HAVE_FFMPEG_AVCODEC_H)
40 # include <ffmpeg/avcodec.h>
47 static picture_t *Deinterlace( filter_t *p_filter, picture_t *p_pic );
49 /*****************************************************************************
50 * filter_sys_t : filter descriptor
51 *****************************************************************************/
57 bool b_enable_croppadd;
60 int i_src_ffmpeg_chroma;
62 int i_dst_ffmpeg_chroma;
67 /*****************************************************************************
68 * OpenDeinterlace: probe the filter and return score
69 *****************************************************************************/
70 int OpenDeinterlace( vlc_object_t *p_this )
72 filter_t *p_filter = (filter_t*)p_this;
75 /* Check if we can handle that formats */
76 if( TestFfmpegChroma( -1, p_filter->fmt_in.i_codec ) != VLC_SUCCESS )
78 msg_Err( p_filter, "Failed to match chroma type" );
82 /* Allocate the memory needed to store the decoder's structure */
83 if( ( p_filter->p_sys = p_sys =
84 (filter_sys_t *)malloc(sizeof(filter_sys_t)) ) == NULL )
90 p_filter->fmt_in.video.i_chroma = p_filter->fmt_in.i_codec;
91 if( GetFfmpegChroma( &p_sys->i_src_ffmpeg_chroma, p_filter->fmt_in.video ) != VLC_SUCCESS )
93 msg_Err( p_filter, "Failed to match chroma type" );
96 p_filter->pf_video_filter = Deinterlace;
98 msg_Dbg( p_filter, "deinterlacing" );
100 /* libavcodec needs to be initialized for some chroma conversions */
101 InitLibavcodec(p_this);
106 /*****************************************************************************
107 * CloseDeinterlace: clean up the filter
108 *****************************************************************************/
109 void CloseDeinterlace( vlc_object_t *p_this )
111 filter_t *p_filter = (filter_t*)p_this;
112 filter_sys_t *p_sys = p_filter->p_sys;
117 /*****************************************************************************
118 * Do the processing here
119 *****************************************************************************/
120 static picture_t *Deinterlace( filter_t *p_filter, picture_t *p_pic )
122 filter_sys_t *p_sys = p_filter->p_sys;
123 AVPicture src_pic, dest_pic;
124 picture_t *p_pic_dst;
127 /* Request output picture */
128 p_pic_dst = filter_NewPicture( p_filter );
131 picture_Release( p_pic );
135 /* Prepare the AVPictures for the conversion */
136 for( i = 0; i < p_pic->i_planes; i++ )
138 src_pic.data[i] = p_pic->p[i].p_pixels;
139 src_pic.linesize[i] = p_pic->p[i].i_pitch;
141 for( i = 0; i < p_pic_dst->i_planes; i++ )
143 dest_pic.data[i] = p_pic_dst->p[i].p_pixels;
144 dest_pic.linesize[i] = p_pic_dst->p[i].i_pitch;
147 i_res = avpicture_deinterlace( &dest_pic, &src_pic, p_sys->i_src_ffmpeg_chroma,
148 p_filter->fmt_in.video.i_width,
149 p_filter->fmt_in.video.i_height );
152 msg_Err( p_filter, "deinterlacing picture failed" );
153 filter_DeletePicture( p_filter, p_pic_dst );
154 picture_Release( p_pic );
158 picture_CopyProperties( p_pic_dst, p_pic );
159 p_pic_dst->b_progressive = true;
160 picture_Release( p_pic );