[Libav-user] Getting the correct display resolution
I’ve been trying to find a reliably way to get the correct display resolution for a given file.
There’s AVVideoCodecContext->width/height, coded_width/coded_height and also sample_aspect_ratio.
There’s also AVStream->sample_aspect_ratio, display_aspect_ratio and AVFrame->sample_aspect_ratio.
Can anybody shed some light on this topic?
What’s the best way to find a video file’s source and display resolution (with source being the size of the actual buffer and display being the cropped, letterboxed etc. version to be presented to the user)?
Is there some kind of order in which they should be checked?
In reply to this post by Info || Non-Lethal Applications
Am Mi., 6. Mai 2020 um 17:53 Uhr schrieb Info || Non-Lethal
Applications <[hidden email]>:
> There’s also AVStream->sample_aspect_ratio, display_aspect_ratio and
To elaborate: It is not difficult to find files where the codec stores another
aspect ratio than the container (ffmpeg allows to create such files because
users want this feature). FFmpeg will prefer the container aspect ratio
over the codec aspect ratio (and this is typically the sane thing to do) but
your application may choose differently.
(Some brand-new containers - no joke - decided to store the display
aspect ratio instead of the sample aspect ratio which was stored for
more than a decade in all formats I remember. To allow calculating
the - needed - sample aspect ratio, the field display_aspect_ratio
had to be created, you should normally ignore it, it will be used to
automatically fill the sample aspect ratio.)