Commit 6a55ecf0 authored by Gildas Bazin's avatar Gildas Bazin

* codec/ffmpeg/video_filter.c: deinterlace filter.

* stream_out/transcode.c: deinterlacing works again.
parent ad4a7e63
......@@ -169,6 +169,13 @@ vlc_module_begin();
set_callbacks( E_(OpenFilter), E_(CloseFilter) );
set_description( _("ffmpeg video filter") );
/* video filter submodule */
add_submodule();
set_capability( "video filter2", 0 );
set_callbacks( E_(OpenDeinterlace), E_(CloseDeinterlace) );
set_description( _("ffmpeg deinterlace video filter") );
add_shortcut( "deinterlace" );
var_Create( p_module->p_libvlc, "avcodec", VLC_VAR_MUTEX );
vlc_module_end();
......
......@@ -71,6 +71,8 @@ void E_(CloseDemux)( vlc_object_t * );
/* Video filter module */
int E_(OpenFilter)( vlc_object_t * );
void E_(CloseFilter)( vlc_object_t * );
int E_(OpenDeinterlace)( vlc_object_t * );
void E_(CloseDeinterlace)( vlc_object_t * );
/* Postprocessing module */
void *E_(OpenPostproc)( decoder_t *, vlc_bool_t * );
......
......@@ -40,6 +40,7 @@
void E_(InitLibavcodec) ( vlc_object_t *p_object );
static picture_t *Process( filter_t *p_filter, picture_t *p_pic );
static picture_t *Deinterlace( filter_t *p_filter, picture_t *p_pic );
/*****************************************************************************
* filter_sys_t : filter descriptor
......@@ -232,3 +233,97 @@ static picture_t *Process( filter_t *p_filter, picture_t *p_pic )
p_pic->pf_release( p_pic );
return p_pic_dst;
}
/*****************************************************************************
* OpenDeinterlace: probe the filter and return score
*****************************************************************************/
int E_(OpenDeinterlace)( vlc_object_t *p_this )
{
filter_t *p_filter = (filter_t*)p_this;
filter_sys_t *p_sys;
/* Check if we can handle that formats */
if( E_(GetFfmpegChroma)( p_filter->fmt_in.video.i_chroma ) < 0 )
{
return VLC_EGENERIC;
}
/* Allocate the memory needed to store the decoder's structure */
if( ( p_filter->p_sys = p_sys =
(filter_sys_t *)malloc(sizeof(filter_sys_t)) ) == NULL )
{
msg_Err( p_filter, "out of memory" );
return VLC_EGENERIC;
}
/* Misc init */
p_sys->i_src_ffmpeg_chroma =
E_(GetFfmpegChroma)( p_filter->fmt_in.video.i_chroma );
p_filter->pf_video_filter = Deinterlace;
msg_Dbg( p_filter, "deinterlacing" );
/* libavcodec needs to be initialized for some chroma conversions */
E_(InitLibavcodec)(p_this);
return VLC_SUCCESS;
}
/*****************************************************************************
* CloseDeinterlace: clean up the filter
*****************************************************************************/
void E_(CloseDeinterlace)( vlc_object_t *p_this )
{
filter_t *p_filter = (filter_t*)p_this;
filter_sys_t *p_sys = p_filter->p_sys;
if( p_sys->p_rsc ) img_resample_close( p_sys->p_rsc );
avpicture_free( &p_sys->tmp_pic );
free( p_sys );
}
/*****************************************************************************
* Do the processing here
*****************************************************************************/
static picture_t *Deinterlace( filter_t *p_filter, picture_t *p_pic )
{
filter_sys_t *p_sys = p_filter->p_sys;
AVPicture src_pic, dest_pic;
picture_t *p_pic_dst;
int i;
/* Request output picture */
p_pic_dst = p_filter->pf_vout_buffer_new( p_filter );
if( !p_pic_dst )
{
msg_Warn( p_filter, "can't get output picture" );
return NULL;
}
/* Prepare the AVPictures for the conversion */
for( i = 0; i < p_pic->i_planes; i++ )
{
src_pic.data[i] = p_pic->p[i].p_pixels;
src_pic.linesize[i] = p_pic->p[i].i_pitch;
}
for( i = 0; i < p_pic_dst->i_planes; i++ )
{
dest_pic.data[i] = p_pic_dst->p[i].p_pixels;
dest_pic.linesize[i] = p_pic_dst->p[i].i_pitch;
}
avpicture_deinterlace( &dest_pic, &src_pic, p_sys->i_src_ffmpeg_chroma,
p_filter->fmt_in.video.i_width,
p_filter->fmt_in.video.i_height );
p_pic_dst->date = p_pic->date;
p_pic_dst->b_force = p_pic->b_force;
p_pic_dst->i_nb_fields = p_pic->i_nb_fields;
p_pic_dst->b_progressive = VLC_TRUE;
p_pic_dst->b_top_field_first = p_pic->b_top_field_first;
p_pic->pf_release( p_pic );
return p_pic_dst;
}
......@@ -899,7 +899,7 @@ static int transcode_audio_new( sout_stream_t *p_stream,
id->p_decoder->p_module = 0;
return VLC_EGENERIC;
}
id->p_encoder->fmt_in.audio.i_format = id->p_encoder->fmt_in.audio.i_codec;
id->p_encoder->fmt_in.audio.i_format = id->p_encoder->fmt_in.i_codec;
/* Check if we need a filter for chroma conversion or resizing */
if( id->p_decoder->fmt_out.i_codec !=
......@@ -1390,6 +1390,32 @@ static int transcode_video_process( sout_stream_t *p_stream,
id->b_transcode = VLC_FALSE;
}
/* Deinterlace */
if( p_stream->p_sys->b_deinterlace )
{
id->pp_filter[id->i_filter] =
vlc_object_create( p_stream, VLC_OBJECT_FILTER );
vlc_object_attach( id->pp_filter[id->i_filter], p_stream );
id->pp_filter[id->i_filter]->pf_vout_buffer_new =
video_new_buffer;
id->pp_filter[id->i_filter]->pf_vout_buffer_del =
video_del_buffer;
id->pp_filter[id->i_filter]->fmt_in = id->p_decoder->fmt_out;
id->pp_filter[id->i_filter]->fmt_out = id->p_decoder->fmt_out;
id->pp_filter[id->i_filter]->p_module =
module_Need( id->pp_filter[id->i_filter],
"video filter2", "deinterlace", 0 );
if( id->pp_filter[id->i_filter]->p_module ) id->i_filter++;
else
{
msg_Dbg( p_stream, "no video filter found" );
vlc_object_detach( id->pp_filter[id->i_filter] );
vlc_object_destroy( id->pp_filter[id->i_filter] );
}
}
/* Check if we need a filter for chroma conversion or resizing */
if( id->p_decoder->fmt_out.video.i_chroma !=
id->p_encoder->fmt_in.video.i_chroma ||
......@@ -1400,32 +1426,30 @@ static int transcode_video_process( sout_stream_t *p_stream,
p_sys->i_crop_top > 0 || p_sys->i_crop_bottom > 0 ||
p_sys->i_crop_left > 0 || p_sys->i_crop_right > 0 )
{
id->pp_filter[0] =
id->pp_filter[id->i_filter] =
vlc_object_create( p_stream, VLC_OBJECT_FILTER );
vlc_object_attach( id->pp_filter[0], p_stream );
id->pp_filter[0]->pf_vout_buffer_new = video_new_buffer;
id->pp_filter[0]->pf_vout_buffer_del = video_del_buffer;
id->pp_filter[0]->fmt_in = id->p_decoder->fmt_out;
id->pp_filter[0]->fmt_out = id->p_encoder->fmt_in;
id->pp_filter[0]->p_module =
module_Need( id->pp_filter[0], "video filter2", 0, 0 );
if( id->pp_filter[0]->p_module ) id->i_filter++;
vlc_object_attach( id->pp_filter[id->i_filter], p_stream );
id->pp_filter[id->i_filter]->pf_vout_buffer_new =
video_new_buffer;
id->pp_filter[id->i_filter]->pf_vout_buffer_del =
video_del_buffer;
id->pp_filter[id->i_filter]->fmt_in = id->p_decoder->fmt_out;
id->pp_filter[id->i_filter]->fmt_out = id->p_encoder->fmt_in;
id->pp_filter[id->i_filter]->p_module =
module_Need( id->pp_filter[id->i_filter],
"video filter2", 0, 0 );
if( id->pp_filter[id->i_filter]->p_module ) id->i_filter++;
else
{
msg_Dbg( p_stream, "no video filter found" );
vlc_object_detach( id->pp_filter[0] );
vlc_object_destroy( id->pp_filter[0] );
vlc_object_detach( id->pp_filter[id->i_filter] );
vlc_object_destroy( id->pp_filter[id->i_filter] );
}
}
}
/* Deinterlace */
if( p_stream->p_sys->b_deinterlace )
{
}
/* Run filter chain */
for( i = 0; i < id->i_filter; i++ )
{
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment