local function cycle_video_rotate(direction)
    local newrotate = mp.get_property_number("video-rotate")

    if direction == "clockwise" then
        newrotate = newrotate + 90
    else
        newrotate = newrotate - 90
    end

    if newrotate >= 360 then
        newrotate = newrotate - 360
    elseif newrotate < 0 then
        newrotate = newrotate + 360
    end

    mp.set_property_number("video-rotate", newrotate)
    mp.osd_message("Rotate: " .. newrotate)
end

mp.register_script_message("Cycle_Video_Rotate", cycle_video_rotate)
