You are not logged in.

#1 2014-02-19 03:45:23

drcouzelis
Member
From: Connecticut, USA
Registered: 2009-11-09
Posts: 4,092
Website

[SOLVED] Keybinding to rotate video in mpv

Many people take videos with mobile phones these days, and many mobile phones have a vertical orientation, which means many videos are sideways. I know I can fix this at the command line with "mpv --vf=rotate=1 filename.mp4" but...

Is there a keybinding for mpv to rotate a video during playback? Is it possible to create one in my "~/.mpv/input.conf" file?

Last edited by drcouzelis (2014-02-20 00:45:21)

Offline

#2 2014-02-19 04:18:39

lucke
Member
From: Poland
Registered: 2004-11-30
Posts: 4,018

Re: [SOLVED] Keybinding to rotate video in mpv

$ cat ~/.mpv/input.conf
F1 vf toggle rotate=1

Offline

#3 2014-02-20 00:45:03

drcouzelis
Member
From: Connecticut, USA
Registered: 2009-11-09
Posts: 4,092
Website

Re: [SOLVED] Keybinding to rotate video in mpv

Thanks, worked perfectly! I decided to make "~/.mpv/input.conf" like this:

# Rotate by 90 degrees clockwise
Alt+RIGHT no-osd vf add rotate=1
# Rotate by 90 degrees counterclockwise
Alt+LEFT no-osd vf add rotate=2

Last edited by drcouzelis (2014-02-20 00:48:03)

Offline

#4 2015-02-02 21:00:18

sokl
Member
Registered: 2015-02-02
Posts: 11

Re: [SOLVED] Keybinding to rotate video in mpv

key bindings to mirror video and reverse it back.

m vf add mirror
ctrl+m vf del mirror

Offline

#5 2015-12-29 03:05:39

rinopo
Member
Registered: 2015-12-29
Posts: 3

Re: [SOLVED] Keybinding to rotate video in mpv

First of all thank you for the comments on this thread; they helped me a lot.

drcouzelis wrote:
# Rotate by 90 degrees clockwise
Alt+RIGHT no-osd vf add rotate=1
# Rotate by 90 degrees counterclockwise
Alt+LEFT no-osd vf add rotate=2

This unfortunately didn't work for me (mpv 0.14.0-git-e1993d5), with this error:

Invalid value for option angle: 1
Valid values are:
    0
    90
    180
    270
    auto
Error parsing option angle (option could not be parsed)
Option vf-add: Error while parsing rotate parameter angle (1)

---

And for me either of the following did work:

Alt+RIGHT no-osd cycle video-rotate 90
Alt+LEFT no-osd cycle video-rotate -90

or

Alt+RIGHT no-osd vf add rotate=90
Alt+LEFT no-osd vf add rotate=270

The problem with the first method is that it cycles through the following values: 90, 180, 270, 360, no, 0; where '360', 'no', and '0' are effectively the same, hence require you two useless hits of the key to cycle through the rotation.

The itch I get with the second method is the very fact that it just adds up the filters. For example if I rotate a video clockwise, and then counterclockwise to get it back to the upright position, I end up adding two filters for nothing:

Opening video filter: [rotate angle=90]
Opening video filter: [rotate angle=270]

I wonder if this could have any performance implication since the filter stack just keeps getting larger.

For now I'd prefer the second.

Last edited by rinopo (2015-12-29 04:43:09)

Offline

#6 2015-12-29 03:16:30

tom.ty89
Member
Registered: 2012-11-15
Posts: 897

Re: [SOLVED] Keybinding to rotate video in mpv

Apparently the issue of the first working method is a glitch/bug of mpv.

Offline

#7 2015-12-29 04:42:36

rinopo
Member
Registered: 2015-12-29
Posts: 3

Re: [SOLVED] Keybinding to rotate video in mpv

@tom.ty89 Thanks for the reply.

I think I've figured out.

Amendment of "the first working method":

Alt+RIGHT no-osd cycle-values video-rotate  "90" "180" "270" "0"
Alt+LEFT no-osd cycle-values video-rotate  "270" "180" "90" "0"

This was what I was looking for.

Offline

#8 2015-12-29 06:57:44

tom.ty89
Member
Registered: 2012-11-15
Posts: 897

Re: [SOLVED] Keybinding to rotate video in mpv

I've tried cycle-values before I reply but I think it works worse? For example if you ALT+LEFT and then ALT+RIGHT, it will switch to 270 and then 90, instead of switch to 270 and switch back to 0.

Anyway I've filed a bug report, let's see if anyone is gonna fix it: https://github.com/mpv-player/mpv/issues/2647 tongue

Last edited by tom.ty89 (2015-12-29 07:06:14)

Offline

#9 2015-12-29 07:19:43

rinopo
Member
Registered: 2015-12-29
Posts: 3

Re: [SOLVED] Keybinding to rotate video in mpv

@tom.ty89
Thanks again for the reply and filing the issue!
Yes, you are right. (I switched back to the "second method.")

Offline

#10 2016-12-04 11:29:02

windozupdate
Banned
Registered: 2015-03-19
Posts: 25

Re: [SOLVED] Keybinding to rotate video in mpv

Hey I am using a BugMeNot account (windozupdate) to tell you guys about a solution I coded.

https://github.com/mpv-player/mpv/issues/3869

~/.config/mpv/scripts/cycle_video_rotate.lua:

function cycle_video_rotate(direction)
	-- Calculate what the next rotation value should be.
	newrotate = mp.get_property_number("video-rotate")
	if direction == "clockwise" then
		newrotate = newrotate + 90
	else
		newrotate = newrotate - 90
	end
	-- Wrap value to correct range (0 (aka 360) to 359).
	if newrotate >= 360 then
		newrotate = newrotate - 360
	elseif newrotate < 0 then
		newrotate = newrotate + 360
	end
	-- Change rotation and tell the user.
	mp.set_property_number("video-rotate", newrotate)
	mp.osd_message("Rotate: " .. newrotate)
end

mp.add_key_binding(nil, "Cycle_Video_Rotate", cycle_video_rotate)

~/.config/mpv/input.conf:

# Rotate video in 90 degree increments.
Alt+LEFT script-message Cycle_Video_Rotate "counter-clockwise"
Alt+RIGHT script-message Cycle_Video_Rotate "clockwise"

Result: Works instantly in any direction without needing multiple keypresses. Always aware of and basing itself on the current rotation value, thus never "jumping" to an unexpected rotation. Always uses even 90-degree increments as long as the users themselves haven't applied any uneven rotation before calling this function (in that case, it fully preserves their offset and does the 90 degree rotation on top of that).

Offline

Board footer

Powered by FluxBB