<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;background-color:#FFFFFF;font-family:Calibri,Arial,Helvetica,sans-serif;">
<p><span id="ms-rterangepaste-start"></span>Is there a way to get the resulting width and height from a scale filter, so i can setup the Encoding-AVCodecContext correctly (with width and height)?<br>
<br>
<br>
Here's my init filter method, which gets feeded with the filter description "scale=-1:'min(720,iw)'":<br>
<br>
<br>
int FFMPEGCommands::init_filters(const char *filters_descr, int width, int height, int streamFrameRate) {<br>
char args[512];<br>
int ret = 0;<br>
const AVFilter *buffersrc = avfilter_get_by_name("buffer");<br>
const AVFilter *buffersink = avfilter_get_by_name("buffersink");<br>
AVFilterInOut *outputs = avfilter_inout_alloc();<br>
AVFilterInOut *inputs = avfilter_inout_alloc();<br>
AVRational time_base = { 1, streamFrameRate };<br>
//AVRational time_base = fmt_ctx->streams[video_stream_index]->time_base;<br>
enum AVPixelFormat pix_fmts[] = { AV_PIX_FMT_YUV420P, AV_PIX_FMT_NONE };<br>
filter_graph = avfilter_graph_alloc();<br>
if (!outputs || !inputs || !filter_graph) {<br>
ret = AVERROR(ENOMEM);<br>
goto end;<br>
}<br>
/* buffer video source: the decoded frames from the decoder will be inserted here. */<br>
snprintf(args, sizeof(args),<br>
"video_size=%dx%d:pix_fmt=%d:time_base=%d/%d:pixel_aspect=%d/%d",<br>
width, height, STREAM_PIX_FMT,<br>
time_base.num, time_base.den,<br>
0, 1);<br>
ret = avfilter_graph_create_filter(&buffersrc_ctx, buffersrc, "in",<br>
args, NULL, filter_graph);<br>
if (ret < 0) {<br>
av_log(NULL, AV_LOG_ERROR, "Cannot create buffer source\n");<br>
goto end;<br>
}<br>
/* buffer video sink: to terminate the filter chain. */<br>
ret = avfilter_graph_create_filter(&buffersink_ctx, buffersink, "out",<br>
NULL, NULL, filter_graph);<br>
if (ret < 0) {<br>
av_log(NULL, AV_LOG_ERROR, "Cannot create buffer sink\n");<br>
goto end;<br>
}<br>
ret = av_opt_set_int_list(buffersink_ctx, "pix_fmts", pix_fmts,<br>
AV_PIX_FMT_NONE, AV_OPT_SEARCH_CHILDREN);<br>
if (ret < 0) {<br>
av_log(NULL, AV_LOG_ERROR, "Cannot set output pixel format\n");<br>
goto end;<br>
}<br>
/*<br>
* Set the endpoints for the filter graph. The filter_graph will<br>
* be linked to the graph described by filters_descr.<br>
*/<br>
/*<br>
* The buffer source output must be connected to the input pad of<br>
* the first filter described by filters_descr; since the first<br>
* filter input label is not specified, it is set to "in" by<br>
* default.<br>
*/<br>
outputs->name = av_strdup("in");<br>
outputs->filter_ctx = buffersrc_ctx;<br>
outputs->pad_idx = 0;<br>
outputs->next = NULL;<br>
/*<br>
* The buffer sink input must be connected to the output pad of<br>
* the last filter described by filters_descr; since the last<br>
* filter output label is not specified, it is set to "out" by<br>
* default.<br>
*/<br>
inputs->name = av_strdup("out");<br>
inputs->filter_ctx = buffersink_ctx;<br>
inputs->pad_idx = 0;<br>
inputs->next = NULL;<br>
if ((ret = avfilter_graph_parse_ptr(filter_graph, filters_descr,<br>
&inputs, &outputs, NULL)) < 0)<br>
goto end;<br>
if ((ret = avfilter_graph_config(filter_graph, NULL)) < 0)<br>
goto end;<br>
end:<br>
avfilter_inout_free(&inputs);<br>
avfilter_inout_free(&outputs);<br>
return ret;<br>
}<br>
<br>
<span id="ms-rterangepaste-end"></span><br>
</p>
</div>
</body>
</html>