[Cin] SAR, DAR, PAR - oh, my!

Andrew Randrianasulu randrianasulu at gmail.com
Sun Jan 7 14:46:34 CET 2024

Apparently, ffmpeg uses SAR (sample aspect ratio) as fundamental metric.

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)



SAR and PAR are the same. sample is the generic term for the elementary
"particles" of media. pixel is specific to video, whereas audio has sample.

sample aspect ratio is the term used in modern video codec standards.

The only equation to know is SAR * width / height = DAR.


we do not display sar/dar in our asset info, I guess we better to!

in ffmpeg.C

AVRational FFMPEG::to_sample_aspect_ratio(Asset *asset)


#if 1

        double display_aspect = asset->width / (double)asset->height;

        double sample_aspect = display_aspect / asset->aspect_ratio;

        int width = 1000000, height = width * sample_aspect + 0.5;

        float w, h;

        MWindow::create_aspect_ratio(w, h, width, height);

        return (AVRational){(int)w, (int)h};




vid->length = secs * vid->frame_rate;

                        vid->aspect_ratio =
(double)st->sample_aspect_ratio.num / st->sample_aspect_ratio.den;

                        vid->nudge = st->start_time;


May be this line needs correcting ? (on decoding)


float FFMPEG::ff_aspect_ratio(int stream)

        //return ffvideo[stream]->aspect_ratio;

        AVFormatContext *fmt_ctx = ffvideo[stream]->fmt_ctx;

        AVStream *strm = ffvideo[stream]->st;
                                AVCodecParameters *par =

        AVRational dar;

        AVRational sar = av_guess_sample_aspect_ratio(fmt_ctx, strm, NULL);

        if (sar.num && ffvideo[stream]->get_rotation_angle() == 0) {
                                   av_reduce(&dar.num, &dar.den,

                      par->width  * sar.num,

                      par->height * sar.den,


                      return av_q2d(dar);


        return ffvideo[stream]->aspect_ratio;



I copied it from ffmpeg.

there is plenty of more complex explanations, for example at


But I think for now we better to concentrate on what ffmpeg gives and takes.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.cinelerra-gg.org/pipermail/cin/attachments/20240107/ab0437d3/attachment-0001.htm>

More information about the Cin mailing list