MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / init_filter

Function init_filter

doc/examples/transcode.c:260–423  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

258}
259
260static int init_filter(FilteringContext* fctx, AVCodecContext *dec_ctx,
261 AVCodecContext *enc_ctx, const char *filter_spec)
262{
263 char args[512];
264 int ret = 0;
265 const AVFilter *buffersrc = NULL;
266 const AVFilter *buffersink = NULL;
267 AVFilterContext *buffersrc_ctx = NULL;
268 AVFilterContext *buffersink_ctx = NULL;
269 AVFilterInOut *outputs = avfilter_inout_alloc();
270 AVFilterInOut *inputs = avfilter_inout_alloc();
271 AVFilterGraph *filter_graph = avfilter_graph_alloc();
272
273 if (!outputs || !inputs || !filter_graph) {
274 ret = AVERROR(ENOMEM);
275 goto end;
276 }
277
278 if (dec_ctx->codec_type == AVMEDIA_TYPE_VIDEO) {
279 buffersrc = avfilter_get_by_name("buffer");
280 buffersink = avfilter_get_by_name("buffersink");
281 if (!buffersrc || !buffersink) {
282 av_log(NULL, AV_LOG_ERROR, "filtering source or sink element not found\n");
283 ret = AVERROR_UNKNOWN;
284 goto end;
285 }
286
287 snprintf(args, sizeof(args),
288 "video_size=%dx%d:pix_fmt=%d:time_base=%d/%d:pixel_aspect=%d/%d",
289 dec_ctx->width, dec_ctx->height, dec_ctx->pix_fmt,
290 dec_ctx->pkt_timebase.num, dec_ctx->pkt_timebase.den,
291 dec_ctx->sample_aspect_ratio.num,
292 dec_ctx->sample_aspect_ratio.den);
293
294 ret = avfilter_graph_create_filter(&buffersrc_ctx, buffersrc, "in",
295 args, NULL, filter_graph);
296 if (ret < 0) {
297 av_log(NULL, AV_LOG_ERROR, "Cannot create buffer source\n");
298 goto end;
299 }
300
301 buffersink_ctx = avfilter_graph_alloc_filter(filter_graph, buffersink, "out");
302 if (!buffersink_ctx) {
303 av_log(NULL, AV_LOG_ERROR, "Cannot create buffer sink\n");
304 ret = AVERROR(ENOMEM);
305 goto end;
306 }
307
308 ret = av_opt_set_bin(buffersink_ctx, "pix_fmts",
309 (uint8_t*)&enc_ctx->pix_fmt, sizeof(enc_ctx->pix_fmt),
310 AV_OPT_SEARCH_CHILDREN);
311 if (ret < 0) {
312 av_log(NULL, AV_LOG_ERROR, "Cannot set output pixel format\n");
313 goto end;
314 }
315
316 ret = avfilter_init_dict(buffersink_ctx, NULL);
317 if (ret < 0) {

Callers 1

init_filtersFunction · 0.70

Calls 15

avfilter_inout_allocFunction · 0.85
avfilter_graph_allocFunction · 0.85
avfilter_get_by_nameFunction · 0.85
av_logFunction · 0.85
av_opt_set_binFunction · 0.85
avfilter_init_dictFunction · 0.85
av_get_sample_fmt_nameFunction · 0.85
av_opt_setFunction · 0.85

Tested by

no test coverage detected