| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
#ifdef HAVE_CONFIG_H |
|---|
| 29 |
# include "config.h" |
|---|
| 30 |
#endif |
|---|
| 31 |
|
|---|
| 32 |
#include <vlc_common.h> |
|---|
| 33 |
#include <vlc_plugin.h> |
|---|
| 34 |
#include <vlc_vout.h> |
|---|
| 35 |
#include <vlc_filter.h> |
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
#ifdef HAVE_LIBAVCODEC_AVCODEC_H |
|---|
| 39 |
# include <libavcodec/avcodec.h> |
|---|
| 40 |
#elif defined(HAVE_FFMPEG_AVCODEC_H) |
|---|
| 41 |
# include <ffmpeg/avcodec.h> |
|---|
| 42 |
#else |
|---|
| 43 |
# include <avcodec.h> |
|---|
| 44 |
#endif |
|---|
| 45 |
|
|---|
| 46 |
#include "../codec/avcodec/chroma.h" |
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
static int OpenFilter( vlc_object_t * ); |
|---|
| 52 |
static void CloseFilter( vlc_object_t * ); |
|---|
| 53 |
|
|---|
| 54 |
static void Conversion( filter_t *, picture_t *, picture_t * ); |
|---|
| 55 |
static picture_t *Conversion_Filter( filter_t *, picture_t * ); |
|---|
| 56 |
|
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 |
vlc_module_begin(); |
|---|
| 61 |
set_capability( "video filter2", 50 ); |
|---|
| 62 |
set_callbacks( OpenFilter, CloseFilter ); |
|---|
| 63 |
set_description( N_("FFmpeg video filter") ); |
|---|
| 64 |
vlc_module_end(); |
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 |
|
|---|
| 70 |
|
|---|
| 71 |
|
|---|
| 72 |
struct filter_sys_t |
|---|
| 73 |
{ |
|---|
| 74 |
int i_src_vlc_chroma; |
|---|
| 75 |
int i_src_ffmpeg_chroma; |
|---|
| 76 |
int i_dst_vlc_chroma; |
|---|
| 77 |
int i_dst_ffmpeg_chroma; |
|---|
| 78 |
AVPicture tmp_pic; |
|---|
| 79 |
ImgReSampleContext *p_rsc; |
|---|
| 80 |
}; |
|---|
| 81 |
|
|---|
| 82 |
|
|---|
| 83 |
|
|---|
| 84 |
|
|---|
| 85 |
|
|---|
| 86 |
|
|---|
| 87 |
int OpenFilter( vlc_object_t *p_this ) |
|---|
| 88 |
{ |
|---|
| 89 |
filter_t *p_filter = (filter_t *)p_this; |
|---|
| 90 |
int i_ffmpeg_chroma[2]; |
|---|
| 91 |
|
|---|
| 92 |
|
|---|
| 93 |
|
|---|
| 94 |
|
|---|
| 95 |
if( GetFfmpegChroma( &i_ffmpeg_chroma[0], p_filter->fmt_in.video ) == VLC_EGENERIC ) |
|---|
| 96 |
return VLC_EGENERIC; |
|---|
| 97 |
if( GetFfmpegChroma( &i_ffmpeg_chroma[1], p_filter->fmt_out.video ) == VLC_EGENERIC ) |
|---|
| 98 |
return VLC_EGENERIC; |
|---|
| 99 |
|
|---|
| 100 |
p_filter->pf_video_filter = Conversion_Filter; |
|---|
| 101 |
|
|---|
| 102 |
p_filter->p_sys = malloc( sizeof( filter_sys_t ) ); |
|---|
| 103 |
if( p_filter->p_sys == NULL ) |
|---|
| 104 |
{ |
|---|
| 105 |
return VLC_ENOMEM; |
|---|
| 106 |
} |
|---|
| 107 |
|
|---|
| 108 |
p_filter->p_sys->i_src_vlc_chroma = p_filter->fmt_in.video.i_chroma; |
|---|
| 109 |
p_filter->p_sys->i_dst_vlc_chroma = p_filter->fmt_out.video.i_chroma; |
|---|
| 110 |
p_filter->p_sys->i_src_ffmpeg_chroma = i_ffmpeg_chroma[0]; |
|---|
| 111 |
p_filter->p_sys->i_dst_ffmpeg_chroma = i_ffmpeg_chroma[1]; |
|---|
| 112 |
|
|---|
| 113 |
if( ( p_filter->fmt_in.video.i_height != p_filter->fmt_out.video.i_height || |
|---|
| 114 |
p_filter->fmt_in.video.i_width != p_filter->fmt_out.video.i_width ) && |
|---|
| 115 |
( p_filter->p_sys->i_dst_vlc_chroma == VLC_FOURCC('I','4','2','0') || |
|---|
| 116 |
p_filter->p_sys->i_dst_vlc_chroma == VLC_FOURCC('Y','V','1','2') )) |
|---|
| 117 |
{ |
|---|
| 118 |
msg_Dbg( p_filter, "preparing to resample picture" ); |
|---|
| 119 |
p_filter->p_sys->p_rsc = |
|---|
| 120 |
img_resample_init( p_filter->fmt_out.video.i_width, |
|---|
| 121 |
p_filter->fmt_out.video.i_height, |
|---|
| 122 |
p_filter->fmt_in.video.i_width, |
|---|
| 123 |
p_filter->fmt_in.video.i_height ); |
|---|
| 124 |
avpicture_alloc( &p_filter->p_sys->tmp_pic, |
|---|
| 125 |
p_filter->p_sys->i_dst_ffmpeg_chroma, |
|---|
| 126 |
p_filter->fmt_in.video.i_width, |
|---|
| 127 |
p_filter->fmt_in.video.i_height ); |
|---|
| 128 |
} |
|---|
| 129 |
else |
|---|
| 130 |
{ |
|---|
| 131 |
msg_Dbg( p_filter, "no resampling" ); |
|---|
| 132 |
p_filter->p_sys->p_rsc = NULL; |
|---|
| 133 |
} |
|---|
| 134 |
|
|---|
| 135 |
return VLC_SUCCESS; |
|---|
| 136 |
} |
|---|
| 137 |
|
|---|
| 138 |
VIDEO_FILTER_WRAPPER( Conversion ) |
|---|
| 139 |
|
|---|
| 140 |
|
|---|
| 141 |
|
|---|
| 142 |
|
|---|
| 143 |
static void Conversion( filter_t *p_filter, |
|---|
| 144 |
picture_t *p_src, picture_t *p_dest ) |
|---|
| 145 |
{ |
|---|
| 146 |
AVPicture src_pic; |
|---|
| 147 |
AVPicture dest_pic; |
|---|
| 148 |
int i; |
|---|
| 149 |
|
|---|
| 150 |
|
|---|
| 151 |
for( i = 0; i < p_src->i_planes; i++ ) |
|---|
| 152 |
{ |
|---|
| 153 |
src_pic.data[i] = p_src->p[i].p_pixels; |
|---|
| 154 |
src_pic.linesize[i] = p_src->p[i].i_pitch; |
|---|
| 155 |
} |
|---|
| 156 |
for( i = 0; i < p_dest->i_planes; i++ ) |
|---|
| 157 |
{ |
|---|
| 158 |
dest_pic.data[i] = p_dest->p[i].p_pixels; |
|---|
| 159 |
dest_pic.linesize[i] = p_dest->p[i].i_pitch; |
|---|
| 160 |
} |
|---|
| 161 |
|
|---|
| 162 |
|
|---|
| 163 |
if( p_filter->p_sys->i_src_vlc_chroma == VLC_FOURCC('Y','V','1','2') || |
|---|
| 164 |
p_filter->p_sys->i_src_vlc_chroma == VLC_FOURCC('Y','V','U','9') ) |
|---|
| 165 |
{ |
|---|
| 166 |
|
|---|
| 167 |
src_pic.data[1] = p_src->p[2].p_pixels; |
|---|
| 168 |
src_pic.data[2] = p_src->p[1].p_pixels; |
|---|
| 169 |
} |
|---|
| 170 |
if( p_filter->p_sys->i_dst_vlc_chroma == VLC_FOURCC('Y','V','1','2') || |
|---|
| 171 |
p_filter->p_sys->i_dst_vlc_chroma == VLC_FOURCC('Y','V','U','9') ) |
|---|
| 172 |
{ |
|---|
| 173 |
|
|---|
| 174 |
dest_pic.data[1] = p_dest->p[2].p_pixels; |
|---|
| 175 |
dest_pic.data[2] = p_dest->p[1].p_pixels; |
|---|
| 176 |
} |
|---|
| 177 |
if( p_filter->p_sys->i_src_ffmpeg_chroma == PIX_FMT_RGB24 ) |
|---|
| 178 |
if( p_filter->fmt_in.video.i_bmask == 0x00ff0000 ) |
|---|
| 179 |
p_filter->p_sys->i_src_ffmpeg_chroma = PIX_FMT_BGR24; |
|---|
| 180 |
|
|---|
| 181 |
if( p_filter->p_sys->p_rsc ) |
|---|
| 182 |
{ |
|---|
| 183 |
img_convert( &p_filter->p_sys->tmp_pic, |
|---|
| 184 |
p_filter->p_sys->i_dst_ffmpeg_chroma, |
|---|
| 185 |
&src_pic, p_filter->p_sys->i_src_ffmpeg_chroma, |
|---|
| 186 |
p_filter->fmt_in.video.i_width, |
|---|
| 187 |
p_filter->fmt_in.video.i_height ); |
|---|
| 188 |
img_resample( p_filter->p_sys->p_rsc, &dest_pic, |
|---|
| 189 |
&p_filter->p_sys->tmp_pic ); |
|---|
| 190 |
} |
|---|
| 191 |
else |
|---|
| 192 |
{ |
|---|
| 193 |
img_convert( &dest_pic, p_filter->p_sys->i_dst_ffmpeg_chroma, |
|---|
| 194 |
&src_pic, p_filter->p_sys->i_src_ffmpeg_chroma, |
|---|
| 195 |
p_filter->fmt_in.video.i_width, |
|---|
| 196 |
p_filter->fmt_in.video.i_height ); |
|---|
| 197 |
} |
|---|
| 198 |
} |
|---|
| 199 |
|
|---|
| 200 |
|
|---|
| 201 |
|
|---|
| 202 |
|
|---|
| 203 |
|
|---|
| 204 |
|
|---|
| 205 |
void CloseFilter( vlc_object_t *p_this ) |
|---|
| 206 |
{ |
|---|
| 207 |
filter_t *p_filter = (filter_t *)p_this; |
|---|
| 208 |
if( p_filter->p_sys->p_rsc ) |
|---|
| 209 |
{ |
|---|
| 210 |
img_resample_close( p_filter->p_sys->p_rsc ); |
|---|
| 211 |
avpicture_free( &p_filter->p_sys->tmp_pic ); |
|---|
| 212 |
} |
|---|
| 213 |
free( p_filter->p_sys ); |
|---|
| 214 |
} |
|---|