<div dir="auto">Apparently, ffmpeg uses SAR (sample aspect ratio) as fundamental metric.<div dir="auto"><br></div><div dir="auto">Cingg's aspect_ratio variable in asset.h is DISPLAY aspect ratio, so we try to work out DAR from sample_aspect_ratio provided by ffmpeg and (coded) dimensions </div><div dir="auto"><br></div><div dir="auto"><a href="https://stackoverflow.com/questions/69560311/confused-about-parpixel-aspect-ratio-in-video" rel="noreferrer noreferrer noreferrer noreferrer noreferrer" target="_blank">https://stackoverflow.com/questions/69560311/confused-about-parpixel-aspect-ratio-in-video</a><br></div><div dir="auto"><br></div><div dir="auto">====</div><div dir="auto"><div dir="auto">
<p>SAR and PAR are the same. <code>sample</code> is the generic term for the elementary "particles" of media. <code>pixel</code> is specific to video, whereas audio has <code>sample</code>.</p>
<p><code>sample aspect ratio</code> is the term used in modern video codec standards.</p>
<p>The only equation to know is <code>SAR * width / height = DAR</code>.</p><p><br></p><p>====</p><p><br></p><p>we do not display sar/dar in our asset info, I guess we better to!</p><p><br></p><p>in ffmpeg.C</p><p><br></p><p>AVRational FFMPEG::to_sample_aspect_ratio(Asset *asset)</p><p>{</p><p>#if 1</p><p> double display_aspect = asset->width / (double)asset->height;</p><p> double sample_aspect = display_aspect / asset->aspect_ratio;</p><p> int width = 1000000, height = width * sample_aspect + 0.5;</p><p> float w, h;</p><p> MWindow::create_aspect_ratio(w, h, width, height);</p><p> return (AVRational){(int)w, (int)h};</p><p>-====-</p><p><br></p><p>and</p><p><br></p><p>-====-</p><p>vid->length = secs * vid->frame_rate;</p><p> vid->aspect_ratio = (double)st->sample_aspect_ratio.num / st->sample_aspect_ratio.den;</p><p> vid->nudge = st->start_time;</p><p><br></p><p>-===--</p><p><br></p><p>May be this line needs correcting ? (on decoding)</p><p><br></p><p>-===--</p><p>float FFMPEG::ff_aspect_ratio(int stream) {</p><p> //return ffvideo[stream]->aspect_ratio;</p><p> AVFormatContext *fmt_ctx = ffvideo[stream]->fmt_ctx;</p><p> AVStream *strm = ffvideo[stream]->st; AVCodecParameters *par = ffvideo[stream]->st->codecpar;</p><p> AVRational dar;</p><p> AVRational sar = av_guess_sample_aspect_ratio(fmt_ctx, strm, NULL);</p><p> if (sar.num && ffvideo[stream]->get_rotation_angle() == 0) { av_reduce(&dar.num, &dar.den,</p><p> par->width * sar.num,</p><p> par->height * sar.den,</p><p> 1024*1024);</p><p> return av_q2d(dar);</p><p> }</p><p> return ffvideo[stream]->aspect_ratio;</p><p>}</p><p><br></p><p>-==-- </p><p><br></p><p>I copied it from ffmpeg.</p><p><br></p><p>there is plenty of more complex explanations, for example at</p><p><br></p><p><a href="https://lurkertech.com/lg/pixelaspect/">https://lurkertech.com/lg/pixelaspect/</a><br></p><p><br></p><p>But I think for now we better to concentrate on what ffmpeg gives and takes.</p><p><br></p><p><br></p></div></div></div>