Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int result;
- avfilter_register_all();
- AVFilter* buffer_src = avfilter_get_by_name("buffer"); // Input to the filter chain
- AVFilter* buffer_sink = avfilter_get_by_name("ffbuffersink"); // Output from the filter chain
- AVBufferSinkParams* buffer_sink_params;
- AVFilterInOut* outputs = avfilter_inout_alloc();
- AVFilterInOut* inputs = avfilter_inout_alloc();
- // Supported output pixel format is only YUV420P
- enum PixelFormat pix_fmts[] = { PIX_FMT_YUV420P, PIX_FMT_NONE };
- // Initialize filter graph
- this->filter_graph = avfilter_graph_alloc();
- // Create input pad
- std::string args = (boost::format("video_size=%dx%d:pix_fmt=%d:time_base=%d/%d:pixel_aspect=%d/%d") % this->input_codec_context->width
- % this->input_codec_context->height
- % this->input_codec_context->pix_fmt
- % this->input_time_base.num
- % this->input_time_base.den
- % this->input_codec_context->sample_aspect_ratio.num
- % this->input_codec_context->sample_aspect_ratio.den).str();
- result = avfilter_graph_create_filter(&buffersrc_ctx, buffer_src, "in", args.c_str(), NULL, filter_graph);
- if (result < 0)
- {
- LOG4CXX_FATAL(logger, "Could not create filter chain input sink: " + std::to_string(result));
- throw std::runtime_error("Could not create filter chain input sink: " + std::to_string(result));
- }
- // Create output pad
- buffer_sink_params = av_buffersink_params_alloc();
- buffer_sink_params->pixel_fmts = pix_fmts;
- result = avfilter_graph_create_filter(&buffersink_ctx, buffer_sink, "out", NULL, buffer_sink_params, filter_graph);
- av_free(buffer_sink_params);
- if (result < 0)
- {
- LOG4CXX_FATAL(logger, "Could not create filter chain output sink: " + std::to_string(result));
- throw std::runtime_error("Could not create filter chain output sink: " + std::to_string(result));
- }
- // Register source and sink
- outputs->name = av_strdup("in");
- outputs->filter_ctx = this->buffersrc_ctx;
- outputs->pad_idx = 0;
- outputs->next = NULL;
- inputs->name = av_strdup("out");
- inputs->filter_ctx = this->buffersink_ctx;
- inputs->pad_idx = 0;
- inputs->next = NULL;
- // Now initialize actual filters for scaling and deinterlacing
- std::string filters = (boost::format("yadif,scale=%d:%d:flags=512,setpts=PTS") % this->output_codec_context->width % this->output_codec_context->height).str();
- LOG4CXX_INFO(logger, "Configuring filter chain with " + filters);
- result = avfilter_graph_parse(filter_graph, filters.c_str(), &inputs, &outputs, NULL);
- if (result < 0)
- {
- LOG4CXX_FATAL(logger, "Could not parse filter chain: " + filters + " ERR: " + std::to_string(result));
- throw std::runtime_error("Could not parse filter chain: " + filters + " ERR: " + std::to_string(result));
- }
- result = avfilter_graph_config(filter_graph, NULL);
- if (result < 0)
- {
- LOG4CXX_FATAL(logger, "Could not configure filter chain: " + filters + " ERR: " + std::to_string(result));
- throw std::runtime_error("Could not configure filter chain: " + filters + " ERR: " + std::to_string(result));
- }
- LOG4CXX_INFO(logger, "Filters configured.");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement