Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

filters: automatically flip video if displaymatrix indicates so #16090

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Traneptora
Copy link
Member

Currently we check AV_FRAME_DATA_DISPLAYMATRIX for its rotation factor but not for its flip factor, which could happen with some input files. This commit adds and autovflip filter, which is applied before the autorotate filter to flip vertically before rotating. It also changes the displaymatrix reading code to output to mp_image->params.vflip so it can be autoinserted as necessary.

@Traneptora
Copy link
Member Author

Note: Orientation files tested with: https://github.com/ianare/exif-samples/tree/master/jpg/orientation but I wasn't able to test on dmabuf_wayland. If someone could test that when reviewing that would be great.

Copy link

github-actions bot commented Mar 22, 2025

Download the artifacts for this pull request:

Windows
macOS

video/mp_image.h Outdated
@@ -57,6 +57,8 @@ struct mp_image_params {

enum mp_csp_light light;
enum pl_chroma_location chroma_location;
// The image should be flipped vertically before rotating
int vflip;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to not just use a bool here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw. what about hflip? Maybe we should make it more complete while at it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no reason not to use a bool, mostly just habit of int as a bool. as for why not hflip, we also have rotate and a vflip and a rotation together can be an hflip. Since this is specifically "flip vertically before rotating" it creates ambiguity whereas hflip before rotation would require us to add 180 degrees to p->rotate.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also implementing a vflip in a driver is much easier for the most part, as we can negate linesize for some things (e.g. vo_gpu) but mirroring horizontally is more complicated.

@@ -709,7 +710,7 @@ static int reconfig(struct vo *vo, struct mp_image *img)
vo->target_params = &p->target_params;
mp_mutex_unlock(&vo->params_mutex);

wl_surface_set_buffer_transform(vo->wl->video_surface, img->params.rotate / 90);
wl_surface_set_buffer_transform(vo->wl->video_surface, img->params.rotate / 90 + 4 * !!img->params.vflip);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This almost works. On the samples in https://github.com/ianare/exif-samples/tree/master/jpg/orientation, 2 and 4 are upside down. It unfortunately looks like the ordering of the wayland transform enums swapped these two cases so a simple +4 won't work.

Copy link
Member Author

@Traneptora Traneptora Mar 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you say they are up-side-down, are they mirrored vertically, or are they rotated 180 degrees?

Also, according to the spec linked (which is where I referenced the +4), this should work, I wonder if the spec is wrong?

landscape_2 results in a displaymatrix:

displaymatrix=
00000000:       -65536           0           0
00000001:            0       65536           0
00000002:            0           0  1073741824

Which has rotate set to 180 and vflip also set to true, which surprises me that this doesn't work. This should set the enum to 6, which is what landscape_2 does.

Copy link
Contributor

@llyyr llyyr Mar 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They're rotated 180 degrees. swapping enum 4 and 6 give the expected result

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that. I tried sway/wlroots and weston and both have the same behavior.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it work now? Added a simple LUT.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep it's correct now

Currently we check AV_FRAME_DATA_DISPLAYMATRIX for its rotation factor
but not for its flip factor, which could happen with some input files.
This commit adds and autovflip filter, which is applied before the
autorotate filter to flip vertically before rotating. It also changes
the displaymatrix reading code to output to mp_image->params.vflip so
it can be autoinserted as necessary.

Signed-off-by: Leo Izen <leo.izen@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants