You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

643 lines
20KB

  1. /*
  2. * filter layer
  3. * Copyright (c) 2007 Bobby Bingham
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. /* #define DEBUG */
  22. #include "libavutil/pixdesc.h"
  23. #include "libavutil/rational.h"
  24. #include "libavcore/audioconvert.h"
  25. #include "libavcore/imgutils.h"
  26. #include "avfilter.h"
  27. #include "internal.h"
  28. unsigned avfilter_version(void) {
  29. return LIBAVFILTER_VERSION_INT;
  30. }
  31. const char *avfilter_configuration(void)
  32. {
  33. return FFMPEG_CONFIGURATION;
  34. }
  35. const char *avfilter_license(void)
  36. {
  37. #define LICENSE_PREFIX "libavfilter license: "
  38. return LICENSE_PREFIX FFMPEG_LICENSE + sizeof(LICENSE_PREFIX) - 1;
  39. }
  40. AVFilterBufferRef *avfilter_ref_buffer(AVFilterBufferRef *ref, int pmask)
  41. {
  42. AVFilterBufferRef *ret = av_malloc(sizeof(AVFilterBufferRef));
  43. if (!ret)
  44. return NULL;
  45. *ret = *ref;
  46. if (ref->type == AVMEDIA_TYPE_VIDEO) {
  47. ret->video = av_malloc(sizeof(AVFilterBufferRefVideoProps));
  48. if (!ret->video) {
  49. av_free(ret);
  50. return NULL;
  51. }
  52. *ret->video = *ref->video;
  53. } else if (ref->type == AVMEDIA_TYPE_AUDIO) {
  54. ret->audio = av_malloc(sizeof(AVFilterBufferRefAudioProps));
  55. if (!ret->audio) {
  56. av_free(ret);
  57. return NULL;
  58. }
  59. *ret->audio = *ref->audio;
  60. }
  61. ret->perms &= pmask;
  62. ret->buf->refcount ++;
  63. return ret;
  64. }
  65. void avfilter_unref_buffer(AVFilterBufferRef *ref)
  66. {
  67. if (!ref)
  68. return;
  69. if (!(--ref->buf->refcount))
  70. ref->buf->free(ref->buf);
  71. av_free(ref->video);
  72. av_free(ref->audio);
  73. av_free(ref);
  74. }
  75. void avfilter_insert_pad(unsigned idx, unsigned *count, size_t padidx_off,
  76. AVFilterPad **pads, AVFilterLink ***links,
  77. AVFilterPad *newpad)
  78. {
  79. unsigned i;
  80. idx = FFMIN(idx, *count);
  81. *pads = av_realloc(*pads, sizeof(AVFilterPad) * (*count + 1));
  82. *links = av_realloc(*links, sizeof(AVFilterLink*) * (*count + 1));
  83. memmove(*pads +idx+1, *pads +idx, sizeof(AVFilterPad) * (*count-idx));
  84. memmove(*links+idx+1, *links+idx, sizeof(AVFilterLink*) * (*count-idx));
  85. memcpy(*pads+idx, newpad, sizeof(AVFilterPad));
  86. (*links)[idx] = NULL;
  87. (*count)++;
  88. for (i = idx+1; i < *count; i++)
  89. if (*links[i])
  90. (*(unsigned *)((uint8_t *) *links[i] + padidx_off))++;
  91. }
  92. int avfilter_link(AVFilterContext *src, unsigned srcpad,
  93. AVFilterContext *dst, unsigned dstpad)
  94. {
  95. AVFilterLink *link;
  96. if (src->output_count <= srcpad || dst->input_count <= dstpad ||
  97. src->outputs[srcpad] || dst->inputs[dstpad])
  98. return -1;
  99. if (src->output_pads[srcpad].type != dst->input_pads[dstpad].type) {
  100. av_log(src, AV_LOG_ERROR,
  101. "Media type mismatch between the '%s' filter output pad %d and the '%s' filter input pad %d\n",
  102. src->name, srcpad, dst->name, dstpad);
  103. return AVERROR(EINVAL);
  104. }
  105. src->outputs[srcpad] =
  106. dst-> inputs[dstpad] = link = av_mallocz(sizeof(AVFilterLink));
  107. link->src = src;
  108. link->dst = dst;
  109. link->srcpad = &src->output_pads[srcpad];
  110. link->dstpad = &dst->input_pads[dstpad];
  111. link->type = src->output_pads[srcpad].type;
  112. assert(PIX_FMT_NONE == -1 && AV_SAMPLE_FMT_NONE == -1);
  113. link->format = -1;
  114. return 0;
  115. }
  116. int avfilter_insert_filter(AVFilterLink *link, AVFilterContext *filt,
  117. unsigned filt_srcpad_idx, unsigned filt_dstpad_idx)
  118. {
  119. int ret;
  120. unsigned dstpad_idx = link->dstpad - link->dst->input_pads;
  121. av_log(link->dst, AV_LOG_INFO, "auto-inserting filter '%s' "
  122. "between the filter '%s' and the filter '%s'\n",
  123. filt->name, link->src->name, link->dst->name);
  124. link->dst->inputs[dstpad_idx] = NULL;
  125. if ((ret = avfilter_link(filt, filt_dstpad_idx, link->dst, dstpad_idx)) < 0) {
  126. /* failed to link output filter to new filter */
  127. link->dst->inputs[dstpad_idx] = link;
  128. return ret;
  129. }
  130. /* re-hookup the link to the new destination filter we inserted */
  131. link->dst = filt;
  132. link->dstpad = &filt->input_pads[filt_srcpad_idx];
  133. filt->inputs[filt_srcpad_idx] = link;
  134. /* if any information on supported media formats already exists on the
  135. * link, we need to preserve that */
  136. if (link->out_formats)
  137. avfilter_formats_changeref(&link->out_formats,
  138. &filt->outputs[filt_dstpad_idx]->out_formats);
  139. return 0;
  140. }
  141. int avfilter_config_links(AVFilterContext *filter)
  142. {
  143. int (*config_link)(AVFilterLink *);
  144. unsigned i;
  145. int ret;
  146. for (i = 0; i < filter->input_count; i ++) {
  147. AVFilterLink *link = filter->inputs[i];
  148. if (!link) continue;
  149. switch (link->init_state) {
  150. case AVLINK_INIT:
  151. continue;
  152. case AVLINK_STARTINIT:
  153. av_log(filter, AV_LOG_INFO, "circular filter chain detected\n");
  154. return 0;
  155. case AVLINK_UNINIT:
  156. link->init_state = AVLINK_STARTINIT;
  157. if ((ret = avfilter_config_links(link->src)) < 0)
  158. return ret;
  159. if (!(config_link = link->srcpad->config_props))
  160. config_link = avfilter_default_config_output_link;
  161. if ((ret = config_link(link)) < 0)
  162. return ret;
  163. if (link->time_base.num == 0 && link->time_base.den == 0)
  164. link->time_base = link->src && link->src->input_count ?
  165. link->src->inputs[0]->time_base : AV_TIME_BASE_Q;
  166. if ((config_link = link->dstpad->config_props))
  167. if ((ret = config_link(link)) < 0)
  168. return ret;
  169. link->init_state = AVLINK_INIT;
  170. }
  171. }
  172. return 0;
  173. }
  174. static char *ff_get_ref_perms_string(char *buf, size_t buf_size, int perms)
  175. {
  176. snprintf(buf, buf_size, "%s%s%s%s%s%s",
  177. perms & AV_PERM_READ ? "r" : "",
  178. perms & AV_PERM_WRITE ? "w" : "",
  179. perms & AV_PERM_PRESERVE ? "p" : "",
  180. perms & AV_PERM_REUSE ? "u" : "",
  181. perms & AV_PERM_REUSE2 ? "U" : "",
  182. perms & AV_PERM_NEG_LINESIZES ? "n" : "");
  183. return buf;
  184. }
  185. static void ff_dprintf_ref(void *ctx, AVFilterBufferRef *ref, int end)
  186. {
  187. av_unused char buf[16];
  188. dprintf(ctx,
  189. "ref[%p buf:%p refcount:%d perms:%s data:%p linesize[%d, %d, %d, %d] pts:%"PRId64" pos:%"PRId64,
  190. ref, ref->buf, ref->buf->refcount, ff_get_ref_perms_string(buf, sizeof(buf), ref->perms), ref->data[0],
  191. ref->linesize[0], ref->linesize[1], ref->linesize[2], ref->linesize[3],
  192. ref->pts, ref->pos);
  193. if (ref->video) {
  194. dprintf(ctx, " a:%d/%d s:%dx%d i:%c",
  195. ref->video->pixel_aspect.num, ref->video->pixel_aspect.den,
  196. ref->video->w, ref->video->h,
  197. !ref->video->interlaced ? 'P' : /* Progressive */
  198. ref->video->top_field_first ? 'T' : 'B'); /* Top / Bottom */
  199. }
  200. if (ref->audio) {
  201. dprintf(ctx, " cl:%"PRId64"d sn:%d s:%d sr:%d p:%d",
  202. ref->audio->channel_layout,
  203. ref->audio->nb_samples,
  204. ref->audio->size,
  205. ref->audio->sample_rate,
  206. ref->audio->planar);
  207. }
  208. dprintf(ctx, "]%s", end ? "\n" : "");
  209. }
  210. static void ff_dprintf_link(void *ctx, AVFilterLink *link, int end)
  211. {
  212. if (link->type == AVMEDIA_TYPE_VIDEO) {
  213. dprintf(ctx,
  214. "link[%p s:%dx%d fmt:%-16s %-16s->%-16s]%s",
  215. link, link->w, link->h,
  216. av_pix_fmt_descriptors[link->format].name,
  217. link->src ? link->src->filter->name : "",
  218. link->dst ? link->dst->filter->name : "",
  219. end ? "\n" : "");
  220. } else {
  221. char buf[128];
  222. av_get_channel_layout_string(buf, sizeof(buf), -1, link->channel_layout);
  223. dprintf(ctx,
  224. "link[%p r:%"PRId64" cl:%s fmt:%-16s %-16s->%-16s]%s",
  225. link, link->sample_rate, buf,
  226. av_get_sample_fmt_name(link->format),
  227. link->src ? link->src->filter->name : "",
  228. link->dst ? link->dst->filter->name : "",
  229. end ? "\n" : "");
  230. }
  231. }
  232. #define FF_DPRINTF_START(ctx, func) dprintf(NULL, "%-16s: ", #func)
  233. AVFilterBufferRef *avfilter_get_video_buffer(AVFilterLink *link, int perms, int w, int h)
  234. {
  235. AVFilterBufferRef *ret = NULL;
  236. av_unused char buf[16];
  237. FF_DPRINTF_START(NULL, get_video_buffer); ff_dprintf_link(NULL, link, 0);
  238. dprintf(NULL, " perms:%s w:%d h:%d\n", ff_get_ref_perms_string(buf, sizeof(buf), perms), w, h);
  239. if (link->dstpad->get_video_buffer)
  240. ret = link->dstpad->get_video_buffer(link, perms, w, h);
  241. if (!ret)
  242. ret = avfilter_default_get_video_buffer(link, perms, w, h);
  243. if (ret)
  244. ret->type = AVMEDIA_TYPE_VIDEO;
  245. FF_DPRINTF_START(NULL, get_video_buffer); ff_dprintf_link(NULL, link, 0); dprintf(NULL, " returning "); ff_dprintf_ref(NULL, ret, 1);
  246. return ret;
  247. }
  248. AVFilterBufferRef *
  249. avfilter_get_video_buffer_ref_from_arrays(uint8_t *data[4], int linesize[4], int perms,
  250. int w, int h, enum PixelFormat format)
  251. {
  252. AVFilterBuffer *pic = av_mallocz(sizeof(AVFilterBuffer));
  253. AVFilterBufferRef *picref = av_mallocz(sizeof(AVFilterBufferRef));
  254. if (!pic || !picref)
  255. goto fail;
  256. picref->buf = pic;
  257. picref->buf->free = ff_avfilter_default_free_buffer;
  258. if (!(picref->video = av_mallocz(sizeof(AVFilterBufferRefVideoProps))))
  259. goto fail;
  260. pic->w = picref->video->w = w;
  261. pic->h = picref->video->h = h;
  262. /* make sure the buffer gets read permission or it's useless for output */
  263. picref->perms = perms | AV_PERM_READ;
  264. pic->refcount = 1;
  265. picref->type = AVMEDIA_TYPE_VIDEO;
  266. pic->format = picref->format = format;
  267. memcpy(pic->data, data, sizeof(pic->data));
  268. memcpy(pic->linesize, linesize, sizeof(pic->linesize));
  269. memcpy(picref->data, pic->data, sizeof(picref->data));
  270. memcpy(picref->linesize, pic->linesize, sizeof(picref->linesize));
  271. return picref;
  272. fail:
  273. if (picref && picref->video)
  274. av_free(picref->video);
  275. av_free(picref);
  276. av_free(pic);
  277. return NULL;
  278. }
  279. AVFilterBufferRef *avfilter_get_audio_buffer(AVFilterLink *link, int perms,
  280. enum AVSampleFormat sample_fmt, int size,
  281. int64_t channel_layout, int planar)
  282. {
  283. AVFilterBufferRef *ret = NULL;
  284. if (link->dstpad->get_audio_buffer)
  285. ret = link->dstpad->get_audio_buffer(link, perms, sample_fmt, size, channel_layout, planar);
  286. if (!ret)
  287. ret = avfilter_default_get_audio_buffer(link, perms, sample_fmt, size, channel_layout, planar);
  288. if (ret)
  289. ret->type = AVMEDIA_TYPE_AUDIO;
  290. return ret;
  291. }
  292. int avfilter_request_frame(AVFilterLink *link)
  293. {
  294. FF_DPRINTF_START(NULL, request_frame); ff_dprintf_link(NULL, link, 1);
  295. if (link->srcpad->request_frame)
  296. return link->srcpad->request_frame(link);
  297. else if (link->src->inputs[0])
  298. return avfilter_request_frame(link->src->inputs[0]);
  299. else return -1;
  300. }
  301. int avfilter_poll_frame(AVFilterLink *link)
  302. {
  303. int i, min = INT_MAX;
  304. if (link->srcpad->poll_frame)
  305. return link->srcpad->poll_frame(link);
  306. for (i = 0; i < link->src->input_count; i++) {
  307. int val;
  308. if (!link->src->inputs[i])
  309. return -1;
  310. val = avfilter_poll_frame(link->src->inputs[i]);
  311. min = FFMIN(min, val);
  312. }
  313. return min;
  314. }
  315. /* XXX: should we do the duplicating of the picture ref here, instead of
  316. * forcing the source filter to do it? */
  317. void avfilter_start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
  318. {
  319. void (*start_frame)(AVFilterLink *, AVFilterBufferRef *);
  320. AVFilterPad *dst = link->dstpad;
  321. int perms = picref->perms;
  322. FF_DPRINTF_START(NULL, start_frame); ff_dprintf_link(NULL, link, 0); dprintf(NULL, " "); ff_dprintf_ref(NULL, picref, 1);
  323. if (!(start_frame = dst->start_frame))
  324. start_frame = avfilter_default_start_frame;
  325. if (picref->linesize[0] < 0)
  326. perms |= AV_PERM_NEG_LINESIZES;
  327. /* prepare to copy the picture if it has insufficient permissions */
  328. if ((dst->min_perms & perms) != dst->min_perms || dst->rej_perms & perms) {
  329. av_log(link->dst, AV_LOG_DEBUG,
  330. "frame copy needed (have perms %x, need %x, reject %x)\n",
  331. picref->perms,
  332. link->dstpad->min_perms, link->dstpad->rej_perms);
  333. link->cur_buf = avfilter_get_video_buffer(link, dst->min_perms, link->w, link->h);
  334. link->src_buf = picref;
  335. avfilter_copy_buffer_ref_props(link->cur_buf, link->src_buf);
  336. }
  337. else
  338. link->cur_buf = picref;
  339. start_frame(link, link->cur_buf);
  340. }
  341. void avfilter_end_frame(AVFilterLink *link)
  342. {
  343. void (*end_frame)(AVFilterLink *);
  344. if (!(end_frame = link->dstpad->end_frame))
  345. end_frame = avfilter_default_end_frame;
  346. end_frame(link);
  347. /* unreference the source picture if we're feeding the destination filter
  348. * a copied version dues to permission issues */
  349. if (link->src_buf) {
  350. avfilter_unref_buffer(link->src_buf);
  351. link->src_buf = NULL;
  352. }
  353. }
  354. void avfilter_draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
  355. {
  356. uint8_t *src[4], *dst[4];
  357. int i, j, vsub;
  358. void (*draw_slice)(AVFilterLink *, int, int, int);
  359. FF_DPRINTF_START(NULL, draw_slice); ff_dprintf_link(NULL, link, 0); dprintf(NULL, " y:%d h:%d dir:%d\n", y, h, slice_dir);
  360. /* copy the slice if needed for permission reasons */
  361. if (link->src_buf) {
  362. vsub = av_pix_fmt_descriptors[link->format].log2_chroma_h;
  363. for (i = 0; i < 4; i++) {
  364. if (link->src_buf->data[i]) {
  365. src[i] = link->src_buf-> data[i] +
  366. (y >> (i==1 || i==2 ? vsub : 0)) * link->src_buf-> linesize[i];
  367. dst[i] = link->cur_buf->data[i] +
  368. (y >> (i==1 || i==2 ? vsub : 0)) * link->cur_buf->linesize[i];
  369. } else
  370. src[i] = dst[i] = NULL;
  371. }
  372. for (i = 0; i < 4; i++) {
  373. int planew =
  374. av_image_get_linesize(link->format, link->cur_buf->video->w, i);
  375. if (!src[i]) continue;
  376. for (j = 0; j < h >> (i==1 || i==2 ? vsub : 0); j++) {
  377. memcpy(dst[i], src[i], planew);
  378. src[i] += link->src_buf->linesize[i];
  379. dst[i] += link->cur_buf->linesize[i];
  380. }
  381. }
  382. }
  383. if (!(draw_slice = link->dstpad->draw_slice))
  384. draw_slice = avfilter_default_draw_slice;
  385. draw_slice(link, y, h, slice_dir);
  386. }
  387. void avfilter_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref)
  388. {
  389. void (*filter_samples)(AVFilterLink *, AVFilterBufferRef *);
  390. AVFilterPad *dst = link->dstpad;
  391. if (!(filter_samples = dst->filter_samples))
  392. filter_samples = avfilter_default_filter_samples;
  393. /* prepare to copy the samples if the buffer has insufficient permissions */
  394. if ((dst->min_perms & samplesref->perms) != dst->min_perms ||
  395. dst->rej_perms & samplesref->perms) {
  396. av_log(link->dst, AV_LOG_DEBUG,
  397. "Copying audio data in avfilter (have perms %x, need %x, reject %x)\n",
  398. samplesref->perms, link->dstpad->min_perms, link->dstpad->rej_perms);
  399. link->cur_buf = avfilter_default_get_audio_buffer(link, dst->min_perms,
  400. samplesref->format,
  401. samplesref->audio->size,
  402. samplesref->audio->channel_layout,
  403. samplesref->audio->planar);
  404. link->cur_buf->pts = samplesref->pts;
  405. link->cur_buf->audio->sample_rate = samplesref->audio->sample_rate;
  406. /* Copy actual data into new samples buffer */
  407. memcpy(link->cur_buf->data[0], samplesref->data[0], samplesref->audio->size);
  408. avfilter_unref_buffer(samplesref);
  409. } else
  410. link->cur_buf = samplesref;
  411. filter_samples(link, link->cur_buf);
  412. }
  413. #define MAX_REGISTERED_AVFILTERS_NB 64
  414. static AVFilter *registered_avfilters[MAX_REGISTERED_AVFILTERS_NB + 1];
  415. static int next_registered_avfilter_idx = 0;
  416. AVFilter *avfilter_get_by_name(const char *name)
  417. {
  418. int i;
  419. for (i = 0; registered_avfilters[i]; i++)
  420. if (!strcmp(registered_avfilters[i]->name, name))
  421. return registered_avfilters[i];
  422. return NULL;
  423. }
  424. int avfilter_register(AVFilter *filter)
  425. {
  426. if (next_registered_avfilter_idx == MAX_REGISTERED_AVFILTERS_NB)
  427. return -1;
  428. registered_avfilters[next_registered_avfilter_idx++] = filter;
  429. return 0;
  430. }
  431. AVFilter **av_filter_next(AVFilter **filter)
  432. {
  433. return filter ? ++filter : &registered_avfilters[0];
  434. }
  435. void avfilter_uninit(void)
  436. {
  437. memset(registered_avfilters, 0, sizeof(registered_avfilters));
  438. next_registered_avfilter_idx = 0;
  439. }
  440. static int pad_count(const AVFilterPad *pads)
  441. {
  442. int count;
  443. for(count = 0; pads->name; count ++) pads ++;
  444. return count;
  445. }
  446. static const char *filter_name(void *p)
  447. {
  448. AVFilterContext *filter = p;
  449. return filter->filter->name;
  450. }
  451. static const AVClass avfilter_class = {
  452. "AVFilter",
  453. filter_name,
  454. NULL,
  455. LIBAVUTIL_VERSION_INT,
  456. };
  457. int avfilter_open(AVFilterContext **filter_ctx, AVFilter *filter, const char *inst_name)
  458. {
  459. AVFilterContext *ret;
  460. *filter_ctx = NULL;
  461. if (!filter)
  462. return AVERROR(EINVAL);
  463. ret = av_mallocz(sizeof(AVFilterContext));
  464. ret->av_class = &avfilter_class;
  465. ret->filter = filter;
  466. ret->name = inst_name ? av_strdup(inst_name) : NULL;
  467. ret->priv = av_mallocz(filter->priv_size);
  468. ret->input_count = pad_count(filter->inputs);
  469. if (ret->input_count) {
  470. ret->input_pads = av_malloc(sizeof(AVFilterPad) * ret->input_count);
  471. memcpy(ret->input_pads, filter->inputs, sizeof(AVFilterPad) * ret->input_count);
  472. ret->inputs = av_mallocz(sizeof(AVFilterLink*) * ret->input_count);
  473. }
  474. ret->output_count = pad_count(filter->outputs);
  475. if (ret->output_count) {
  476. ret->output_pads = av_malloc(sizeof(AVFilterPad) * ret->output_count);
  477. memcpy(ret->output_pads, filter->outputs, sizeof(AVFilterPad) * ret->output_count);
  478. ret->outputs = av_mallocz(sizeof(AVFilterLink*) * ret->output_count);
  479. }
  480. *filter_ctx = ret;
  481. return 0;
  482. }
  483. void avfilter_free(AVFilterContext *filter)
  484. {
  485. int i;
  486. AVFilterLink *link;
  487. if (filter->filter->uninit)
  488. filter->filter->uninit(filter);
  489. for (i = 0; i < filter->input_count; i++) {
  490. if ((link = filter->inputs[i])) {
  491. if (link->src)
  492. link->src->outputs[link->srcpad - link->src->output_pads] = NULL;
  493. avfilter_formats_unref(&link->in_formats);
  494. avfilter_formats_unref(&link->out_formats);
  495. }
  496. av_freep(&link);
  497. }
  498. for (i = 0; i < filter->output_count; i++) {
  499. if ((link = filter->outputs[i])) {
  500. if (link->dst)
  501. link->dst->inputs[link->dstpad - link->dst->input_pads] = NULL;
  502. avfilter_formats_unref(&link->in_formats);
  503. avfilter_formats_unref(&link->out_formats);
  504. }
  505. av_freep(&link);
  506. }
  507. av_freep(&filter->name);
  508. av_freep(&filter->input_pads);
  509. av_freep(&filter->output_pads);
  510. av_freep(&filter->inputs);
  511. av_freep(&filter->outputs);
  512. av_freep(&filter->priv);
  513. av_free(filter);
  514. }
  515. int avfilter_init_filter(AVFilterContext *filter, const char *args, void *opaque)
  516. {
  517. int ret=0;
  518. if (filter->filter->init)
  519. ret = filter->filter->init(filter, args, opaque);
  520. return ret;
  521. }