Browse Source
- chroma + resizing video filter (using the filter_t architecture). * modules/codec/ffmpeg/*: - cleanup + small updates. * modules/codec/speex.c, theora.c, vorbis.c: - got rid of pf_header() in the encoder. - store the headers in fmt_out.p_extra (this will break the ogg muxer for now). * modules/codec/libmpeg2.c, modules/codec/ffmpeg/video.c: - added a p_dec->b_pace_control field to signal if the decoder is allowed to drop frames. * modules/stream_out/transcode.c: - heavy cleanup. - re-use video decoder modules and got rid of the duplicated ffmpeg video decoder. - use video filters for chroma conversion and resizing. (a few things are broken now like deinterlacing but I'll repair them asap).pull/2/head
18 changed files with 974 additions and 1274 deletions
@ -0,0 +1,234 @@ |
|||
/*****************************************************************************
|
|||
* video filter: video filter doing chroma conversion and resizing |
|||
* using the ffmpeg library |
|||
***************************************************************************** |
|||
* Copyright (C) 1999-2001 VideoLAN |
|||
* $Id: chroma.c 7834 2004-05-30 16:57:55Z sigmunau $ |
|||
* |
|||
* Authors: Gildas Bazin <gbazin@videolan.org> |
|||
* |
|||
* This program is free software; you can redistribute it and/or modify |
|||
* it under the terms of the GNU General Public License as published by |
|||
* the Free Software Foundation; either version 2 of the License, or |
|||
* (at your option) any later version. |
|||
* |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with this program; if not, write to the Free Software |
|||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. |
|||
*****************************************************************************/ |
|||
|
|||
/*****************************************************************************
|
|||
* Preamble |
|||
*****************************************************************************/ |
|||
#include <vlc/vlc.h> |
|||
#include <vlc/decoder.h> |
|||
#include "vlc_filter.h" |
|||
|
|||
/* ffmpeg header */ |
|||
#ifdef HAVE_FFMPEG_AVCODEC_H |
|||
# include <ffmpeg/avcodec.h> |
|||
#else |
|||
# include <avcodec.h> |
|||
#endif |
|||
|
|||
#include "ffmpeg.h" |
|||
|
|||
void E_(InitLibavcodec) ( vlc_object_t *p_object ); |
|||
static picture_t *Process( filter_t *p_filter, picture_t *p_pic ); |
|||
|
|||
/*****************************************************************************
|
|||
* filter_sys_t : filter descriptor |
|||
*****************************************************************************/ |
|||
struct filter_sys_t |
|||
{ |
|||
vlc_bool_t b_resize; |
|||
vlc_bool_t b_convert; |
|||
|
|||
es_format_t fmt_in; |
|||
int i_src_ffmpeg_chroma; |
|||
es_format_t fmt_out; |
|||
int i_dst_ffmpeg_chroma; |
|||
|
|||
AVPicture tmp_pic; |
|||
ImgReSampleContext *p_rsc; |
|||
}; |
|||
|
|||
/*****************************************************************************
|
|||
* OpenFilter: probe the filter and return score |
|||
*****************************************************************************/ |
|||
int E_(OpenFilter)( vlc_object_t *p_this ) |
|||
{ |
|||
filter_t *p_filter = (filter_t*)p_this; |
|||
filter_sys_t *p_sys; |
|||
vlc_bool_t b_convert, b_resize; |
|||
ImgReSampleContext *p_rsc; |
|||
|
|||
/* Check if we can handle that formats */ |
|||
if( E_(GetFfmpegChroma)( p_filter->fmt_in.video.i_chroma ) < 0 || |
|||
E_(GetFfmpegChroma)( p_filter->fmt_out.video.i_chroma ) < 0 ) |
|||
{ |
|||
return VLC_EGENERIC; |
|||
} |
|||
|
|||
b_resize = |
|||
p_filter->fmt_in.video.i_width != p_filter->fmt_out.video.i_width || |
|||
p_filter->fmt_in.video.i_height != p_filter->fmt_out.video.i_height; |
|||
b_convert = |
|||
p_filter->fmt_in.video.i_chroma != p_filter->fmt_out.video.i_chroma; |
|||
|
|||
if( !b_resize && !b_convert ) |
|||
{ |
|||
/* Nothing to do */ |
|||
return VLC_EGENERIC; |
|||
} |
|||
|
|||
p_rsc = img_resample_init( p_filter->fmt_out.video.i_width, |
|||
p_filter->fmt_out.video.i_height, |
|||
p_filter->fmt_in.video.i_width, |
|||
p_filter->fmt_in.video.i_height ); |
|||
if( !p_rsc ) |
|||
{ |
|||
msg_Err( p_filter, "img_resample_init failed" ); |
|||
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->b_resize = b_resize; |
|||
p_sys->b_convert = b_convert; |
|||
p_sys->p_rsc = p_rsc; |
|||
p_sys->i_src_ffmpeg_chroma = |
|||
E_(GetFfmpegChroma)( p_filter->fmt_in.video.i_chroma ); |
|||
p_sys->i_dst_ffmpeg_chroma = |
|||
E_(GetFfmpegChroma)( p_filter->fmt_out.video.i_chroma ); |
|||
p_sys->fmt_in = p_filter->fmt_in; |
|||
p_sys->fmt_out = p_filter->fmt_out; |
|||
p_filter->pf_video_filter = Process; |
|||
|
|||
avpicture_alloc( &p_sys->tmp_pic, p_sys->i_dst_ffmpeg_chroma, |
|||
p_filter->fmt_in.video.i_width, |
|||
p_filter->fmt_in.video.i_height ); |
|||
|
|||
msg_Dbg( p_filter, "input: %ix%i %4.4s -> %ix%i %4.4s", |
|||
p_filter->fmt_in.video.i_width, p_filter->fmt_in.video.i_height, |
|||
(char *)&p_filter->fmt_in.video.i_chroma, |
|||
p_filter->fmt_out.video.i_width, p_filter->fmt_out.video.i_height, |
|||
(char *)&p_filter->fmt_out.video.i_chroma ); |
|||
|
|||
/* libavcodec needs to be initialized for some chroma conversions */ |
|||
E_(InitLibavcodec)(p_this); |
|||
|
|||
return VLC_SUCCESS; |
|||
} |
|||
|
|||
/*****************************************************************************
|
|||
* CloseFilter: clean up the filter |
|||
*****************************************************************************/ |
|||
void E_(CloseFilter)( 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 *Process( filter_t *p_filter, picture_t *p_pic ) |
|||
{ |
|||
filter_sys_t *p_sys = p_filter->p_sys; |
|||
AVPicture src_pic, dest_pic, inter_pic; |
|||
picture_t *p_pic_dst; |
|||
vlc_bool_t b_resize = p_sys->b_resize; |
|||
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; |
|||
} |
|||
|
|||
/* Special cases */ |
|||
if( p_filter->fmt_in.video.i_chroma == VLC_FOURCC('Y','V','1','2') || |
|||
p_filter->fmt_in.video.i_chroma == VLC_FOURCC('Y','V','U','9') ) |
|||
{ |
|||
/* Invert U and V */ |
|||
src_pic.data[1] = p_pic->p[2].p_pixels; |
|||
src_pic.data[2] = p_pic->p[1].p_pixels; |
|||
} |
|||
if( p_filter->fmt_out.video.i_chroma == VLC_FOURCC('Y','V','1','2') || |
|||
p_filter->fmt_out.video.i_chroma == VLC_FOURCC('Y','V','U','9') ) |
|||
{ |
|||
/* Invert U and V */ |
|||
dest_pic.data[1] = p_pic_dst->p[2].p_pixels; |
|||
dest_pic.data[2] = p_pic_dst->p[1].p_pixels; |
|||
} |
|||
|
|||
#if 0 |
|||
if( p_sys->b_resize && |
|||
p_filter->fmt_in.video.i_width * p_filter->fmt_in.video.i_height > |
|||
p_filter->fmt_out.video.i_width * p_filter->fmt_out.video.i_height ) |
|||
{ |
|||
img_resample( p_sys->p_rsc, &dest_pic, &p_sys->tmp_pic ); |
|||
b_resize = 0; |
|||
} |
|||
#endif |
|||
|
|||
if( p_sys->b_convert ) |
|||
{ |
|||
if( p_sys->b_resize ) inter_pic = p_sys->tmp_pic; |
|||
else inter_pic = dest_pic; |
|||
|
|||
img_convert( &inter_pic, p_sys->i_dst_ffmpeg_chroma, |
|||
&src_pic, p_sys->i_src_ffmpeg_chroma, |
|||
p_filter->fmt_in.video.i_width, |
|||
p_filter->fmt_in.video.i_height ); |
|||
|
|||
src_pic = inter_pic; |
|||
} |
|||
|
|||
if( p_sys->b_resize && p_sys->p_rsc ) |
|||
{ |
|||
img_resample( p_sys->p_rsc, &dest_pic, &src_pic ); |
|||
} |
|||
|
|||
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 = p_pic->b_progressive; |
|||
p_pic_dst->b_top_field_first = p_pic->b_top_field_first; |
|||
|
|||
p_pic->pf_release( p_pic ); |
|||
return p_pic_dst; |
|||
} |
|||
File diff suppressed because it is too large
Loading…
Reference in new issue