1313#include "libavutil/avassert.h"
1414#include "libavutil/avstring.h"
1515#include "libavutil/imgutils.h"
16+ #include "libavutil/intreadwrite.h"
1617#include "libavutil/opt.h"
1718#include "libavutil/parseutils.h"
1819#include "video.h"
@@ -21,6 +22,7 @@ typedef struct {
2122 const AVClass * class ;
2223 char * filter_path ;
2324 char * config ;
25+ int clear ;
2426 void * handle ;
2527 void * user_data ;
2628 int (* filter_init )(const char * , void * * );
@@ -109,6 +111,14 @@ static int query_formats(AVFilterContext* ctx) {
109111 return ff_set_common_formats (ctx , fmts_list );
110112}
111113
114+ static void clear_image (AVFrame * out ) {
115+ for (int i = 0 ; i < out -> height ; i ++ ) {
116+ for (int j = 0 ; j < out -> width ; j ++ ) {
117+ AV_WN32 (out -> data [0 ] + i * out -> linesize [0 ] + j * 4 , 0 );
118+ }
119+ }
120+ }
121+
112122static int filter_frame (AVFilterLink * inlink , AVFrame * in ) {
113123 AVFilterContext * ctx = inlink -> dst ;
114124 AVFilterLink * outlink = ctx -> outputs [0 ];
@@ -139,6 +149,10 @@ static int filter_frame(AVFilterLink* inlink, AVFrame* in) {
139149 return data_size ;
140150 }
141151
152+ if (pc -> clear ) {
153+ clear_image (out );
154+ }
155+
142156 double time_ms = in -> pts * av_q2d (inlink -> time_base ) * 1000 ;
143157
144158 int rc = pc -> filter_frame (out -> data [0 ], data_size , in -> width , in -> height ,
@@ -192,6 +206,14 @@ static const AVOption proxy_options[] = {
192206 CHAR_MIN ,
193207 CHAR_MAX ,
194208 FLAGS },
209+ {"clear" ,
210+ "clear frame before filtering" ,
211+ OFFSET (clear ),
212+ AV_OPT_TYPE_BOOL ,
213+ {.i64 = 0 },
214+ 0 ,
215+ 1 ,
216+ FLAGS },
195217 {NULL },
196218};
197219
0 commit comments