<div dir="auto"><div><br><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">сб, 20 янв. 2024 г., 19:49 Andrea paz <<a href="mailto:gamberucci.andrea@gmail.com">gamberucci.andrea@gmail.com</a>>:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I tried reading all the ffmpeg.C code inside ../cinelerra-5.1/cinelerra/ffmpeg.C<br>
I found these references to aspect ratio. I don't understand most of the lines.<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">you are welcome anyway! :)</div><div dir="auto"><br></div><div dir="auto"><br></div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
We start by setting the default parameters (line 1105):<br>
<br>
FFVideoStream::FFVideoStream(FFMPEG *ffmpeg, AVStream *strm, int idx, int fidx)<br>
: FFStream(ffmpeg, strm, fidx),<br>
FFVideoConvert(ffmpeg->ff_prefs())<br>
{<br>
this->idx = idx;<br>
width = height = 0;<br>
transpose = 0;<br>
frame_rate = 0;<br>
aspect_ratio = 0;<br>
length = 0;<br>
interlaced = 0;<br>
top_field_first = 0;<br>
color_space = -1;<br>
color_range = -1;<br>
fconvert_ctx = 0;<br>
}<br>
<br>
Then after doing many steps, we arrive at the aspect ratio (lines 1954):<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto"><br></div><div dir="auto">note, functions can be defined and then reused in non-linear fashion, unlike linear interpreted languages. Just a remark.</div><div dir="auto"><br></div><div dir="auto"><br></div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
AVRational FFMPEG::to_sample_aspect_ratio(Asset *asset)<br>
#(==> SAR=AVRational)<br>
{<br>
#if 1<br>
double display_aspect = asset->width / (double)asset->height;<br>
#(==> DAR=Wa/Ha; if SAR=1)<br>
double sample_aspect = display_aspect / asset->aspect_ratio;<br>
#(==> SAR=DAR/(Wa/Ha))<br>
int width = 1000000, height = width * sample_aspect + 0.5;<br>
#(==> W= n°; H=W x SAR + 0.5) ??<br>
float w, h;<br>
MWindow::create_aspect_ratio(w, h, width, height);<br>
return (AVRational){(int)w, (int)h}; #(==> SAR = Int W / Int H) ??<br>
#else<br>
// square pixels<br>
return (AVRational){1, 1}; #(==> SAR = 1:1)<br>
#endif<br>
}<br>
<br>
Then a long block dealing with various parameters including sar (lines 2548):<br>
<br>
<br>
AVRational sar = av_guess_sample_aspect_ratio(fmt_ctx, st, NULL);<br>
AVRational display_aspect_ratio;<br>
if(sar.num) {<br>
<br>
av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den,<br>
st->codecpar->width * (int64_t)sar.num, #(==><br>
DAR.num = W x SAR.num)<br>
st->codecpar->height * (int64_t)sar.den, #(==><br>
DAR.den = W x SAR.den)<br>
1024 * 1024);<br>
/* report(" Guessed SAR: %d:%d, ", sar.num, sar.den ); #(==><br>
SAR is guessed from ffmpeg scan?)<br>
report("DAR: %d:%d \n", display_aspect_ratio.num,<br>
display_aspect_ratio.den); */<br>
}<br>
if (st->sample_aspect_ratio.num)<br>
{<br>
av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den,<br>
st->codecpar->width * (int64_t)st->sample_aspect_ratio.num,<br>
st->codecpar->height * (int64_t)st->sample_aspect_ratio.den,<br>
1024 * 1024);<br>
report(" container Detected SAR: %d:%d , DAR %d:%d \n",<br>
st->sample_aspect_ratio.num, st->sample_aspect_ratio.den,<br>
display_aspect_ratio.num, display_aspect_ratio.den);<br>
}<br>
if (st->codecpar->sample_aspect_ratio.num)<br>
{<br>
av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den,<br>
st->codecpar->width *<br>
(int64_t)st->codecpar->sample_aspect_ratio.num,<br>
st->codecpar->height *<br>
(int64_t)st->codecpar->sample_aspect_ratio.den,<br>
1024 * 1024);<br>
report(" codec Detected SAR: %d:%d , DAR %d:%d \n",<br>
st->codecpar->sample_aspect_ratio.num,<br>
st->codecpar->sample_aspect_ratio.den, display_aspect_ratio.num,<br>
display_aspect_ratio.den);<br>
}<br>
<br>
<br>
I think the whole block refers to "ffprobe", that is what we read in Detail.<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">yeah, I/we added it recently</div><div dir="auto"><br></div><div dir="auto"><br></div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
In a later block is the line (2777):<br>
<br>
vid->aspect_ratio = (double)st->sample_aspect_ratio.num /<br>
st->sample_aspect_ratio.den; #(==> SAR=SAR.num/SAR.den) ??<br>
<br>
I do not know how to interpret, however.<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">those ratios expressed as A/B, not as arithmetical divide but structure with two parts. </div><div dir="auto"><br></div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
At some point (lines 3660, but especially 3710) there are formulas<br>
that also involve PAR (like par = width x sar):<br>
<br>
<br>
int FFMPEG::ff_total_video_layers()<br>
{<br>
return vstrm_index.size();<br>
}<br>
<br>
int FFMPEG::ff_total_vstreams()<br>
{<br>
return ffvideo.size();<br>
}<br>
<br>
int FFMPEG::ff_video_width(int stream)<br>
{<br>
FFVideoStream *vst = ffvideo[stream];<br>
return !vst->transpose ? vst->width : vst->height;<br>
}<br>
<br>
int FFMPEG::ff_video_height(int stream)<br>
{<br>
FFVideoStream *vst = ffvideo[stream];<br>
return !vst->transpose ? vst->height : vst->width;<br>
}<br>
<br>
int FFMPEG::ff_set_video_width(int stream, int width)<br>
{<br>
FFVideoStream *vst = ffvideo[stream];<br>
int *vw = !vst->transpose ? &vst->width : &vst->height, w = *vw;<br>
*vw = width;<br>
return w;<br>
}<br>
<br>
int FFMPEG::ff_set_video_height(int stream, int height)<br>
{<br>
FFVideoStream *vst = ffvideo[stream];<br>
int *vh = !vst->transpose ? &vst->height : &vst->width, h = *vh;<br>
*vh = height;<br>
return h;<br>
}<br>
<br>
int FFMPEG::ff_coded_width(int stream)<br>
{<br>
return ffvideo[stream]->avctx->coded_width;<br>
}<br>
<br>
int FFMPEG::ff_coded_height(int stream)<br>
{<br>
return ffvideo[stream]->avctx->coded_height;<br>
}<br>
<br>
float FFMPEG::ff_aspect_ratio(int stream)<br>
{<br>
//return ffvideo[stream]->aspect_ratio;<br>
AVFormatContext *fmt_ctx = ffvideo[stream]->fmt_ctx;<br>
AVStream *strm = ffvideo[stream]->st;<br>
AVCodecParameters *par = ffvideo[stream]->st->codecpar;<br>
AVRational dar;<br>
AVRational sar = av_guess_sample_aspect_ratio(fmt_ctx, strm, NULL);<br>
if (sar.num && ffvideo[stream]->get_rotation_angle() == 0) {<br>
av_reduce(&dar.num, &dar.den,<br>
par->width * sar.num,<br>
par->height * sar.den,<br>
1024*1024);<br>
return av_q2d(dar);<br>
}<br>
return ffvideo[stream]->aspect_ratio;<br>
}<br>
<br>
<br>
Certainly, although the previous par were intended as "parameter,"<br>
this time it is definitely PAR as aspect ratio; </blockquote></div></div><div dir="auto"><br></div><div dir="auto">Structure named AvCodecParameters - I copied it from ffmpeg if I remember correctly. So, par here really should be parameter.</div><div dir="auto"><br></div><div dir="auto"><br></div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">but I don't know<br>
whether as "Pixel aspect ratio" or "Picture aspect ratio."<br>
So it would seem that ffmpeg uses it (or is it a variation of CinGG?).<br>
<br>
On line 3872 it is found:<br>
<br>
AVCodecParameters *avpar = st->codecpar;<br>
int sa_num = avpar->sample_aspect_ratio.num;<br>
if( !sa_num ) sa_num = 1;<br>
int sa_den = avpar->sample_aspect_ratio.den;<br>
if( !sa_den ) sa_num = 1;<br>
<br>
I don't quite understand if it sets the sar parameters: if we specify<br>
them it takes the value given to it, otherwise it takes 1 by default.<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto"><br></div><div dir="auto">I think your understanding is correct. Just this might be not something user enters but libav* functions fills in during decoding.</div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
I couldn't find any other references to aspect ratio in ffmpeg.C.<br>
</blockquote></div></div></div>