<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:#954F72;
text-decoration:underline;}
p.msonormal0, li.msonormal0, div.msonormal0
{mso-style-name:msonormal;
mso-margin-top-alt:auto;
margin-right:0cm;
mso-margin-bottom-alt:auto;
margin-left:0cm;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
span.E-MailFormatvorlage19
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="DE-CH" link="blue" vlink="#954F72">
<div class="WordSection1">
<p class="MsoNormal"><span lang="EN-GB">Awesome dude, thank you very much. Works like a charm, exactly what I needed.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span lang="DE">Von:</span></b><span lang="DE"> Libav-user <libav-user-bounces@ffmpeg.org>
<b>Im Auftrag von </b>Strahinja Radman<br>
<b>Gesendet:</b> 21 February 2019 14:48<br>
<b>An:</b> This list is about using libavcodec, libavformat, libavutil, libavdevice and libavfilter. <libav-user@ffmpeg.org><br>
<b>Betreff:</b> Re: [Libav-user] Getting resulting width and height from scale filter<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span lang="EN-GB">From: </span></b><span lang="EN-GB"><a href="mailto:Michael.Bachmann@picsystems.ch">Michael Bachmann</a><br>
<b>Sent: </b>21 February 2019 13:02<br>
<b>To: </b><a href="mailto:libav-user@ffmpeg.org">libav-user@ffmpeg.org</a><br>
<b>Subject: </b>[Libav-user] Getting resulting width and height from scale filter<o:p></o:p></span></p>
</div>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
<p style="margin-bottom:12.0pt;background:white"><span lang="EN-GB" style="font-size:12.0pt;color:black">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>
<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">The info you are seeking should be available here filter_ctx.buffersink_ctx->inputs[0]->w for width and filter_ctx.buffersink_ctx->inputs[0]->h for height.
<o:p></o:p></span></p>
</div>
</body>
</html>