[Libav-user] Getting the correct display resolution

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[Libav-user] Getting the correct display resolution

Info || Non-Lethal Applications
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?

Thanks a lot in advance!

Best regards,

Flo

_______________________________________________
Libav-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/libav-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Getting the correct display resolution

Nicolas George
Info || Non-Lethal Applications (12020-05-06):
> There’s AVVideoCodecContext->width/height,

That is what you want.

> coded_width/coded_height

Encode a 126x126 video with x264, then use ffprobe to examine it and
compare coded_width and width.

> and also sample_aspect_ratio.

PAL DVDs are 720×576, meant for 16:9. Do the math.

The sample_aspect_ratio for PAL DVDs is 64/45. Do some more math.

> There’s also AVStream->sample_aspect_ratio, display_aspect_ratio and
> AVFrame->sample_aspect_ratio.

These come from the stream, i.e. are obtained from the headers of the
encapsulation format. The data in AVCodecContext comes after decoding
the actual payload.

Regards,

--
  Nicolas George

_______________________________________________
Libav-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/libav-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".

signature.asc (849 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Getting the correct display resolution

Carl Eugen Hoyos-2
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
> AVFrame->sample_aspect_ratio.

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.)

Carl Eugen
_______________________________________________
Libav-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/libav-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".